diff --git a/cmd/main.go b/cmd/main.go index 67263a9..b2b21c4 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -16,6 +16,7 @@ import ( ginSwagger "github.com/swaggo/gin-swagger" _ "go.uber.org/automaxprocs" + "github.com/gin-contrib/pprof" "github.com/mysteriumnetwork/discovery/config" _ "github.com/mysteriumnetwork/discovery/docs" "github.com/mysteriumnetwork/discovery/health" @@ -55,6 +56,12 @@ func main() { }) r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) r.GET("/metrics", gin.WrapH(promhttp.Handler())) + if cfg.DevPass != "" { + devGroup := r.Group("/dev", gin.BasicAuth(gin.Accounts{ + "dev": cfg.DevPass, + })) + pprof.RouteRegister(devGroup, "pprof") + } tagEnhancer := tags.NewEnhancer(tags.NewApi(cfg.BadgerAddress.String())) proposalRepo := proposal.NewRepository([]proposal.Enhancer{tagEnhancer}) diff --git a/config/options.go b/config/options.go index 9e7ccf4..08a3820 100644 --- a/config/options.go +++ b/config/options.go @@ -32,6 +32,8 @@ type Options struct { UniverseJWTSecret string SentinelURL string + DevPass string + MaxRequestsLimit int } @@ -60,6 +62,8 @@ func ReadDiscovery() (*Options, error) { return nil, err } + devPass := OptionalEnv("DEV_PASS", "") + maxRequestsLimit := OptionalEnv("MAX_REQUESTS_LIMIT", "1000") limit, err := strconv.Atoi(maxRequestsLimit) if err != nil { @@ -75,6 +79,7 @@ func ReadDiscovery() (*Options, error) { LocationUser: locationUser, LocationPass: locationPass, MaxRequestsLimit: limit, + DevPass: devPass, }, nil } diff --git a/docs/docs.go b/docs/docs.go index 57efff9..04a13bc 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,14 +1,13 @@ -// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT +// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag - package docs import ( "bytes" "encoding/json" "strings" + "text/template" - "github.com/alecthomas/template" "github.com/swaggo/swag" ) @@ -16,7 +15,7 @@ var doc = `{ "schemes": {{ marshal .Schemes }}, "swagger": "2.0", "info": { - "description": "{{.Description}}", + "description": "{{escape .Description}}", "title": "{{.Title}}", "contact": {}, "version": "{{.Version}}" @@ -24,6 +23,81 @@ var doc = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/countries": { + "get": { + "description": "List number of providers in each country", + "consumes": [ + "application/json" + ], + "tags": [ + "countries" + ], + "summary": "List number of providers in each country", + "parameters": [ + { + "type": "string", + "description": "Consumer country", + "name": "from", + "in": "query" + }, + { + "type": "string", + "description": "Provider ID", + "name": "provider_id", + "in": "query" + }, + { + "type": "string", + "description": "Service type", + "name": "service_type", + "in": "query" + }, + { + "type": "string", + "description": "Provider country", + "name": "location_country", + "in": "query" + }, + { + "type": "string", + "description": "IP type (residential, datacenter, etc.)", + "name": "ip_type", + "in": "query" + }, + { + "type": "string", + "description": "Access policy. When empty, returns only public proposals (default). Use 'all' to return all.", + "name": "access_policy", + "in": "query" + }, + { + "type": "string", + "description": "Access policy source", + "name": "access_policy_source", + "in": "query" + }, + { + "type": "number", + "description": "Minimum compatibility. When empty, will not filter by it.", + "name": "compatibility_min", + "in": "query" + }, + { + "type": "number", + "description": "Maximum compatibility. When empty, will not filter by it.", + "name": "compatibility_max", + "in": "query" + }, + { + "type": "number", + "description": "Minimal quality threshold. When empty will be defaulted to 0. Quality ranges from [0.0; 3.0]", + "name": "quality_min", + "in": "query" + } + ], + "responses": {} + } + }, "/ping": { "get": { "description": "Ping", @@ -47,69 +121,6 @@ var doc = `{ } } }, - "/prices": { - "get": { - "description": "Latest Prices", - "tags": [ - "prices" - ], - "summary": "Latest Prices", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pricing.LatestPrices" - } - } - } - } - } - }, - "/prices/config": { - "get": { - "description": "price config", - "tags": [ - "prices" - ], - "summary": "Price config", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pricing.Config" - } - } - } - } - }, - "post": { - "description": "update price config", - "tags": [ - "prices" - ], - "summary": "update price config", - "parameters": [ - { - "description": "config object", - "name": "config", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/pricing.Config" - } - } - ], - "responses": { - "202": { - "description": "" - } - } - } - }, "/proposals": { "get": { "description": "List proposals", @@ -261,115 +272,6 @@ var doc = `{ "properties": { "cache_ok": { "type": "boolean" - }, - "db_ok": { - "type": "boolean" - } - } - }, - "pricing.Config": { - "type": "object", - "properties": { - "base_prices": { - "$ref": "#/definitions/pricing.PriceByTypeUSD" - }, - "country_modifiers": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/pricing.Modifier" - } - } - } - }, - "pricing.LatestPrices": { - "type": "object", - "properties": { - "current_valid_until": { - "type": "string" - }, - "defaults": { - "$ref": "#/definitions/pricing.PriceHistory" - }, - "per_country": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/pricing.PriceHistory" - } - }, - "previous_valid_until": { - "type": "string" - } - } - }, - "pricing.Modifier": { - "type": "object", - "properties": { - "other": { - "type": "number" - }, - "residential": { - "type": "number" - } - } - }, - "pricing.Price": { - "type": "object", - "properties": { - "price_per_gib": { - "type": "integer" - }, - "price_per_gib_human_readable": { - "type": "number" - }, - "price_per_hour": { - "type": "integer" - }, - "price_per_hour_human_readable": { - "type": "number" - } - } - }, - "pricing.PriceByType": { - "type": "object", - "properties": { - "other": { - "$ref": "#/definitions/pricing.Price" - }, - "residential": { - "$ref": "#/definitions/pricing.Price" - } - } - }, - "pricing.PriceByTypeUSD": { - "type": "object", - "properties": { - "other": { - "$ref": "#/definitions/pricing.PriceUSD" - }, - "residential": { - "$ref": "#/definitions/pricing.PriceUSD" - } - } - }, - "pricing.PriceHistory": { - "type": "object", - "properties": { - "current": { - "$ref": "#/definitions/pricing.PriceByType" - }, - "previous": { - "$ref": "#/definitions/pricing.PriceByType" - } - } - }, - "pricing.PriceUSD": { - "type": "object", - "properties": { - "price_per_gib_usd": { - "type": "number" - }, - "price_per_hour_usd": { - "type": "number" } } }, @@ -415,6 +317,9 @@ var doc = `{ }, "isp": { "type": "string" + }, + "region": { + "type": "string" } } }, @@ -430,6 +335,9 @@ var doc = `{ "isp": { "type": "string" }, + "monitoring_failed": { + "type": "boolean" + }, "provider_id": { "type": "string" }, @@ -499,9 +407,17 @@ var doc = `{ "description": "Latency in ms.", "type": "number" }, + "monitoring_failed": { + "description": "MonitoringFailed did monitoring agent succeed to connect to the node.", + "type": "boolean" + }, "quality": { "description": "Quality valuation from the oracle.", "type": "number" + }, + "uptime": { + "description": "Uptime in hours per day", + "type": "number" } } } @@ -538,6 +454,13 @@ func (s *s) ReadDoc() string { a, _ := json.Marshal(v) return string(a) }, + "escape": func(v interface{}) string { + // escape tabs + str := strings.Replace(v.(string), "\t", "\\t", -1) + // replace " with \", and if that results in \\", replace that with \\\" + str = strings.Replace(str, "\"", "\\\"", -1) + return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1) + }, }).Parse(doc) if err != nil { return doc @@ -552,5 +475,5 @@ func (s *s) ReadDoc() string { } func init() { - swag.Register(swag.Name, &s{}) + swag.Register("swagger", &s{}) } diff --git a/docs/swagger.json b/docs/swagger.json index 543cbc8..68b48c1 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -106,69 +106,6 @@ } } }, - "/prices": { - "get": { - "description": "Latest Prices", - "tags": [ - "prices" - ], - "summary": "Latest Prices", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pricing.LatestPrices" - } - } - } - } - } - }, - "/prices/config": { - "get": { - "description": "price config", - "tags": [ - "prices" - ], - "summary": "Price config", - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "array", - "items": { - "$ref": "#/definitions/pricing.Config" - } - } - } - } - }, - "post": { - "description": "update price config", - "tags": [ - "prices" - ], - "summary": "update price config", - "parameters": [ - { - "description": "config object", - "name": "config", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/pricing.Config" - } - } - ], - "responses": { - "202": { - "description": "" - } - } - } - }, "/proposals": { "get": { "description": "List proposals", @@ -323,115 +260,6 @@ } } }, - "pricing.Config": { - "type": "object", - "properties": { - "base_prices": { - "$ref": "#/definitions/pricing.PriceByTypeUSD" - }, - "country_modifiers": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/pricing.Modifier" - } - } - } - }, - "pricing.LatestPrices": { - "type": "object", - "properties": { - "current_server_time": { - "type": "string" - }, - "current_valid_until": { - "type": "string" - }, - "defaults": { - "$ref": "#/definitions/pricing.PriceHistory" - }, - "per_country": { - "type": "object", - "additionalProperties": { - "$ref": "#/definitions/pricing.PriceHistory" - } - }, - "previous_valid_until": { - "type": "string" - } - } - }, - "pricing.Modifier": { - "type": "object", - "properties": { - "other": { - "type": "number" - }, - "residential": { - "type": "number" - } - } - }, - "pricing.Price": { - "type": "object", - "properties": { - "price_per_gib": { - "type": "integer" - }, - "price_per_gib_human_readable": { - "type": "number" - }, - "price_per_hour": { - "type": "integer" - }, - "price_per_hour_human_readable": { - "type": "number" - } - } - }, - "pricing.PriceByType": { - "type": "object", - "properties": { - "other": { - "$ref": "#/definitions/pricing.Price" - }, - "residential": { - "$ref": "#/definitions/pricing.Price" - } - } - }, - "pricing.PriceByTypeUSD": { - "type": "object", - "properties": { - "other": { - "$ref": "#/definitions/pricing.PriceUSD" - }, - "residential": { - "$ref": "#/definitions/pricing.PriceUSD" - } - } - }, - "pricing.PriceHistory": { - "type": "object", - "properties": { - "current": { - "$ref": "#/definitions/pricing.PriceByType" - }, - "previous": { - "$ref": "#/definitions/pricing.PriceByType" - } - } - }, - "pricing.PriceUSD": { - "type": "object", - "properties": { - "price_per_gib_usd": { - "type": "number" - }, - "price_per_hour_usd": { - "type": "number" - } - } - }, "v3.AccessPolicy": { "type": "object", "properties": { @@ -474,6 +302,9 @@ }, "isp": { "type": "string" + }, + "region": { + "type": "string" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 8ce7e53..a17666d 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -10,76 +10,6 @@ definitions: cache_ok: type: boolean type: object - pricing.Config: - properties: - base_prices: - $ref: '#/definitions/pricing.PriceByTypeUSD' - country_modifiers: - additionalProperties: - $ref: '#/definitions/pricing.Modifier' - type: object - type: object - pricing.LatestPrices: - properties: - current_server_time: - type: string - current_valid_until: - type: string - defaults: - $ref: '#/definitions/pricing.PriceHistory' - per_country: - additionalProperties: - $ref: '#/definitions/pricing.PriceHistory' - type: object - previous_valid_until: - type: string - type: object - pricing.Modifier: - properties: - other: - type: number - residential: - type: number - type: object - pricing.Price: - properties: - price_per_gib: - type: integer - price_per_gib_human_readable: - type: number - price_per_hour: - type: integer - price_per_hour_human_readable: - type: number - type: object - pricing.PriceByType: - properties: - other: - $ref: '#/definitions/pricing.Price' - residential: - $ref: '#/definitions/pricing.Price' - type: object - pricing.PriceByTypeUSD: - properties: - other: - $ref: '#/definitions/pricing.PriceUSD' - residential: - $ref: '#/definitions/pricing.PriceUSD' - type: object - pricing.PriceHistory: - properties: - current: - $ref: '#/definitions/pricing.PriceByType' - previous: - $ref: '#/definitions/pricing.PriceByType' - type: object - pricing.PriceUSD: - properties: - price_per_gib_usd: - type: number - price_per_hour_usd: - type: number - type: object v3.AccessPolicy: properties: id: @@ -108,6 +38,8 @@ definitions: type: string isp: type: string + region: + type: string type: object v3.Metadata: properties: @@ -249,47 +181,6 @@ paths: summary: Ping tags: - system - /prices: - get: - description: Latest Prices - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/pricing.LatestPrices' - type: array - summary: Latest Prices - tags: - - prices - /prices/config: - get: - description: price config - responses: - "200": - description: OK - schema: - items: - $ref: '#/definitions/pricing.Config' - type: array - summary: Price config - tags: - - prices - post: - description: update price config - parameters: - - description: config object - in: body - name: config - required: true - schema: - $ref: '#/definitions/pricing.Config' - responses: - "202": - description: "" - summary: update price config - tags: - - prices /proposals: get: consumes: diff --git a/go.mod b/go.mod index c1f8d2e..f99f60c 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( github.com/deckarep/golang-set v1.7.1 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/ethereum/go-ethereum v1.10.2 // indirect + github.com/gin-contrib/pprof v1.4.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect diff --git a/go.sum b/go.sum index c41e1fb..9850d61 100644 --- a/go.sum +++ b/go.sum @@ -171,6 +171,8 @@ github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/gzip v0.0.1 h1:ezvKOL6jH+jlzdHNE4h9h8q8uMpDQjyl0NN0Jd7jozc= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= +github.com/gin-contrib/pprof v1.4.0 h1:XxiBSf5jWZ5i16lNOPbMTVdgHBdhfGRD5PZ1LWazzvg= +github.com/gin-contrib/pprof v1.4.0/go.mod h1:RrehPJasUVBPK6yTUwOl8/NP6i0vbUgmxtis+Z5KE90= github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=