Skip to content

Commit

Permalink
Merge pull request #82 from mysteriumnetwork/pprof-path
Browse files Browse the repository at this point in the history
Add pprof endpoint
  • Loading branch information
Andrey M authored Feb 6, 2023
2 parents b3970eb + 67f3c82 commit 7d5b114
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 460 deletions.
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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})
Expand Down
5 changes: 5 additions & 0 deletions config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type Options struct {
UniverseJWTSecret string
SentinelURL string

DevPass string

MaxRequestsLimit int
}

Expand Down Expand Up @@ -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 {
Expand All @@ -75,6 +79,7 @@ func ReadDiscovery() (*Options, error) {
LocationUser: locationUser,
LocationPass: locationPass,
MaxRequestsLimit: limit,
DevPass: devPass,
}, nil
}

Expand Down
277 changes: 100 additions & 177 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,103 @@
// 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"
)

var doc = `{
"schemes": {{ marshal .Schemes }},
"swagger": "2.0",
"info": {
"description": "{{.Description}}",
"description": "{{escape .Description}}",
"title": "{{.Title}}",
"contact": {},
"version": "{{.Version}}"
},
"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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
}
}
},
Expand Down Expand Up @@ -415,6 +317,9 @@ var doc = `{
},
"isp": {
"type": "string"
},
"region": {
"type": "string"
}
}
},
Expand All @@ -430,6 +335,9 @@ var doc = `{
"isp": {
"type": "string"
},
"monitoring_failed": {
"type": "boolean"
},
"provider_id": {
"type": "string"
},
Expand Down Expand Up @@ -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"
}
}
}
Expand Down Expand Up @@ -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
Expand All @@ -552,5 +475,5 @@ func (s *s) ReadDoc() string {
}

func init() {
swag.Register(swag.Name, &s{})
swag.Register("swagger", &s{})
}
Loading

0 comments on commit 7d5b114

Please sign in to comment.