Skip to content

Commit

Permalink
go.d fix url path overwrite (netdata#18132)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Jul 12, 2024
1 parent fa8c704 commit 28de8a8
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 92 deletions.
3 changes: 1 addition & 2 deletions src/go/plugin/go.d/modules/consul/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ func (c *Consul) isServer() bool {
}

func (c *Consul) doOKDecode(urlPath string, in interface{}, statusCodes ...int) error {
req, err := web.NewHTTPRequest(c.Request.Copy())
req, err := web.NewHTTPRequestWithPath(c.Request, urlPath)
if err != nil {
return fmt.Errorf("error on creating request: %v", err)
}

req.URL.Path = urlPath
if c.ACLToken != "" {
req.Header.Set("X-Consul-Token", c.ACLToken)
}
Expand Down
8 changes: 5 additions & 3 deletions src/go/plugin/go.d/modules/couchbase/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ func (cb *Couchbase) addDimToChart(chartID string, dim *module.Dim) {
}

func (cb *Couchbase) scrapeCouchbase() (*cbMetrics, error) {
ms := &cbMetrics{}
req, _ := web.NewHTTPRequest(cb.Request)
req.URL.Path = urlPathBucketsStats
req, err := web.NewHTTPRequestWithPath(cb.Request, urlPathBucketsStats)
if err != nil {
return nil, err
}
req.URL.RawQuery = url.Values{"skipMap": []string{"true"}}.Encode()

ms := &cbMetrics{}
if err := cb.doOKDecode(req, &ms.BucketsBasicStats); err != nil {
return nil, err
}
Expand Down
20 changes: 8 additions & 12 deletions src/go/plugin/go.d/modules/couchdb/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ func (cdb *CouchDB) scrapeCouchDB() *cdbMetrics {
}

func (cdb *CouchDB) scrapeNodeStats(ms *cdbMetrics) {
req, _ := web.NewHTTPRequest(cdb.Request)
req.URL.Path = fmt.Sprintf(urlPathOverviewStats, cdb.Config.Node)
req, _ := web.NewHTTPRequestWithPath(cdb.Request, fmt.Sprintf(urlPathOverviewStats, cdb.Config.Node))

var stats cdbNodeStats
if err := cdb.doOKDecode(req, &stats); err != nil {
Expand All @@ -132,8 +131,7 @@ func (cdb *CouchDB) scrapeNodeStats(ms *cdbMetrics) {
}

func (cdb *CouchDB) scrapeSystemStats(ms *cdbMetrics) {
req, _ := web.NewHTTPRequest(cdb.Request)
req.URL.Path = fmt.Sprintf(urlPathSystemStats, cdb.Config.Node)
req, _ := web.NewHTTPRequestWithPath(cdb.Request, fmt.Sprintf(urlPathSystemStats, cdb.Config.Node))

var stats cdbNodeSystem
if err := cdb.doOKDecode(req, &stats); err != nil {
Expand All @@ -144,8 +142,7 @@ func (cdb *CouchDB) scrapeSystemStats(ms *cdbMetrics) {
}

func (cdb *CouchDB) scrapeActiveTasks(ms *cdbMetrics) {
req, _ := web.NewHTTPRequest(cdb.Request)
req.URL.Path = urlPathActiveTasks
req, _ := web.NewHTTPRequestWithPath(cdb.Request, urlPathActiveTasks)

var stats []cdbActiveTask
if err := cdb.doOKDecode(req, &stats); err != nil {
Expand All @@ -156,8 +153,7 @@ func (cdb *CouchDB) scrapeActiveTasks(ms *cdbMetrics) {
}

func (cdb *CouchDB) scrapeDBStats(ms *cdbMetrics) {
req, _ := web.NewHTTPRequest(cdb.Request)
req.URL.Path = urlPathDatabases
req, _ := web.NewHTTPRequestWithPath(cdb.Request, urlPathDatabases)
req.Method = http.MethodPost
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
Expand All @@ -182,18 +178,18 @@ func (cdb *CouchDB) scrapeDBStats(ms *cdbMetrics) {
}

func findMaxMQSize(MessageQueues map[string]interface{}) int64 {
var max float64
var maxSize float64
for _, mq := range MessageQueues {
switch mqSize := mq.(type) {
case float64:
max = math.Max(max, mqSize)
maxSize = math.Max(maxSize, mqSize)
case map[string]interface{}:
if v, ok := mqSize["count"].(float64); ok {
max = math.Max(max, v)
maxSize = math.Max(maxSize, v)
}
}
}
return int64(max)
return int64(maxSize)
}

func (cdb *CouchDB) pingCouchDB() error {
Expand Down
6 changes: 4 additions & 2 deletions src/go/plugin/go.d/modules/dnsdist/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ func (d *DNSdist) collectStatistic(collected map[string]int64, statistics *stati
}

func (d *DNSdist) scrapeStatistics() (*statisticMetrics, error) {
req, _ := web.NewHTTPRequest(d.Request)
req.URL.Path = urlPathJSONStat
req, err := web.NewHTTPRequestWithPath(d.Request, urlPathJSONStat)
if err != nil {
return nil, err
}
req.URL.RawQuery = url.Values{"command": []string{"stats"}}.Encode()

var statistics statisticMetrics
Expand Down
17 changes: 8 additions & 9 deletions src/go/plugin/go.d/modules/elasticsearch/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ func (es *Elasticsearch) scrapeElasticsearch() *esMetrics {
}

func (es *Elasticsearch) scrapeNodesStats(ms *esMetrics) {
req, _ := web.NewHTTPRequest(es.Request)
var p string
if es.ClusterMode {
req.URL.Path = urlPathNodesStats
p = urlPathNodesStats
} else {
req.URL.Path = urlPathLocalNodeStats
p = urlPathLocalNodeStats
}

req, _ := web.NewHTTPRequestWithPath(es.Request, p)

var stats esNodesStats
if err := es.doOKDecode(req, &stats); err != nil {
es.Warning(err)
Expand All @@ -175,8 +177,7 @@ func (es *Elasticsearch) scrapeNodesStats(ms *esMetrics) {
}

func (es *Elasticsearch) scrapeClusterHealth(ms *esMetrics) {
req, _ := web.NewHTTPRequest(es.Request)
req.URL.Path = urlPathClusterHealth
req, _ := web.NewHTTPRequestWithPath(es.Request, urlPathClusterHealth)

var health esClusterHealth
if err := es.doOKDecode(req, &health); err != nil {
Expand All @@ -188,8 +189,7 @@ func (es *Elasticsearch) scrapeClusterHealth(ms *esMetrics) {
}

func (es *Elasticsearch) scrapeClusterStats(ms *esMetrics) {
req, _ := web.NewHTTPRequest(es.Request)
req.URL.Path = urlPathClusterStats
req, _ := web.NewHTTPRequestWithPath(es.Request, urlPathClusterStats)

var stats esClusterStats
if err := es.doOKDecode(req, &stats); err != nil {
Expand All @@ -201,8 +201,7 @@ func (es *Elasticsearch) scrapeClusterStats(ms *esMetrics) {
}

func (es *Elasticsearch) scrapeLocalIndicesStats(ms *esMetrics) {
req, _ := web.NewHTTPRequest(es.Request)
req.URL.Path = urlPathIndicesStats
req, _ := web.NewHTTPRequestWithPath(es.Request, urlPathIndicesStats)
req.URL.RawQuery = "local=true&format=json"

var stats []esIndexStats
Expand Down
16 changes: 4 additions & 12 deletions src/go/plugin/go.d/modules/ipfs/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,11 @@ func (ip *IPFS) collectPinLs(mx map[string]int64) error {
}

func (ip *IPFS) queryStatsBandwidth() (*ipfsStatsBw, error) {
req, err := web.NewHTTPRequest(ip.Request)
req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathStatsBandwidth)
if err != nil {
return nil, err
}

req.URL.Path = urlPathStatsBandwidth

var stats ipfsStatsBw
if err := ip.doOKDecode(req, &stats); err != nil {
return nil, err
Expand All @@ -145,13 +143,11 @@ func (ip *IPFS) queryStatsBandwidth() (*ipfsStatsBw, error) {
}

func (ip *IPFS) querySwarmPeers() (*ipfsSwarmPeers, error) {
req, err := web.NewHTTPRequest(ip.Request)
req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathSwarmPeers)
if err != nil {
return nil, err
}

req.URL.Path = urlPathSwarmPeers

var stats ipfsSwarmPeers
if err := ip.doOKDecode(req, &stats); err != nil {
return nil, err
Expand All @@ -161,13 +157,11 @@ func (ip *IPFS) querySwarmPeers() (*ipfsSwarmPeers, error) {
}

func (ip *IPFS) queryStatsRepo() (*ipfsStatsRepo, error) {
req, err := web.NewHTTPRequest(ip.Request)
req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathStatsRepo)
if err != nil {
return nil, err
}

req.URL.Path = urlPathStatsRepo

var stats ipfsStatsRepo
if err := ip.doOKDecode(req, &stats); err != nil {
return nil, err
Expand All @@ -177,13 +171,11 @@ func (ip *IPFS) queryStatsRepo() (*ipfsStatsRepo, error) {
}

func (ip *IPFS) queryPinLs() (*ipfsPinsLs, error) {
req, err := web.NewHTTPRequest(ip.Request)
req, err := web.NewHTTPRequestWithPath(ip.Request, urlPathPinLs)
if err != nil {
return nil, err
}

req.URL.Path = urlPathPinLs

var stats ipfsPinsLs
if err := ip.doOKDecode(req, &stats); err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions src/go/plugin/go.d/modules/logstash/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func (l *Logstash) updateCharts(pipelines map[string]pipelineStats) {
}

func (l *Logstash) queryNodeStats() (*nodeStats, error) {
req, _ := web.NewHTTPRequest(l.Request.Copy())
req.URL.Path = urlPathNodeStatsAPI
req, err := web.NewHTTPRequestWithPath(l.Request, urlPathNodeStatsAPI)
if err != nil {
return nil, err
}

var stats nodeStats

Expand Down
45 changes: 15 additions & 30 deletions src/go/plugin/go.d/modules/nginxplus/nginx_http_api_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ type nginxMetrics struct {
}

func (n *NginxPlus) queryAPIVersion() (int64, error) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = urlPathAPIVersions
req, _ := web.NewHTTPRequestWithPath(n.Request, urlPathAPIVersions)

var versions nginxAPIVersions
if err := n.doWithDecode(&versions, req); err != nil {
Expand All @@ -62,8 +61,7 @@ func (n *NginxPlus) queryAPIVersion() (int64, error) {
}

func (n *NginxPlus) queryAvailableEndpoints() error {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIEndpointsRoot, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIEndpointsRoot, n.apiVersion))

var endpoints []string
if err := n.doWithDecode(&endpoints, req); err != nil {
Expand Down Expand Up @@ -91,8 +89,7 @@ func (n *NginxPlus) queryAvailableEndpoints() error {

if hasHTTP {
endpoints = endpoints[:0]
req, _ = web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIEndpointsHTTP, n.apiVersion)
req, _ = web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIEndpointsHTTP, n.apiVersion))

if err := n.doWithDecode(&endpoints, req); err != nil {
return err
Expand All @@ -117,8 +114,7 @@ func (n *NginxPlus) queryAvailableEndpoints() error {

if hasStream {
endpoints = endpoints[:0]
req, _ = web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIEndpointsStream, n.apiVersion)
req, _ = web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIEndpointsStream, n.apiVersion))

if err := n.doWithDecode(&endpoints, req); err != nil {
return err
Expand Down Expand Up @@ -171,8 +167,7 @@ func (n *NginxPlus) queryMetrics() *nginxMetrics {
}

func (n *NginxPlus) queryNginxInfo(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPINginx, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPINginx, n.apiVersion))

var v nginxInfo

Expand All @@ -186,8 +181,7 @@ func (n *NginxPlus) queryNginxInfo(ms *nginxMetrics) {
}

func (n *NginxPlus) queryConnections(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIConnections, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIConnections, n.apiVersion))

var v nginxConnections

Expand All @@ -201,8 +195,7 @@ func (n *NginxPlus) queryConnections(ms *nginxMetrics) {
}

func (n *NginxPlus) querySSL(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPISSL, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPISSL, n.apiVersion))

var v nginxSSL

Expand All @@ -216,8 +209,7 @@ func (n *NginxPlus) querySSL(ms *nginxMetrics) {
}

func (n *NginxPlus) queryHTTPRequests(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIHTTPRequests, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPRequests, n.apiVersion))

var v nginxHTTPRequests

Expand All @@ -231,8 +223,7 @@ func (n *NginxPlus) queryHTTPRequests(ms *nginxMetrics) {
}

func (n *NginxPlus) queryHTTPServerZones(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIHTTPServerZones, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPServerZones, n.apiVersion))

var v nginxHTTPServerZones

Expand All @@ -246,8 +237,7 @@ func (n *NginxPlus) queryHTTPServerZones(ms *nginxMetrics) {
}

func (n *NginxPlus) queryHTTPLocationZones(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIHTTPLocationZones, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPLocationZones, n.apiVersion))

var v nginxHTTPLocationZones

Expand All @@ -261,8 +251,7 @@ func (n *NginxPlus) queryHTTPLocationZones(ms *nginxMetrics) {
}

func (n *NginxPlus) queryHTTPUpstreams(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIHTTPUpstreams, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPUpstreams, n.apiVersion))

var v nginxHTTPUpstreams

Expand All @@ -276,8 +265,7 @@ func (n *NginxPlus) queryHTTPUpstreams(ms *nginxMetrics) {
}

func (n *NginxPlus) queryHTTPCaches(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIHTTPCaches, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIHTTPCaches, n.apiVersion))

var v nginxHTTPCaches

Expand All @@ -291,8 +279,7 @@ func (n *NginxPlus) queryHTTPCaches(ms *nginxMetrics) {
}

func (n *NginxPlus) queryStreamServerZones(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIStreamServerZones, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIStreamServerZones, n.apiVersion))

var v nginxStreamServerZones

Expand All @@ -306,8 +293,7 @@ func (n *NginxPlus) queryStreamServerZones(ms *nginxMetrics) {
}

func (n *NginxPlus) queryStreamUpstreams(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIStreamUpstreams, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIStreamUpstreams, n.apiVersion))

var v nginxStreamUpstreams

Expand All @@ -321,8 +307,7 @@ func (n *NginxPlus) queryStreamUpstreams(ms *nginxMetrics) {
}

func (n *NginxPlus) queryResolvers(ms *nginxMetrics) {
req, _ := web.NewHTTPRequest(n.Request.Copy())
req.URL.Path = fmt.Sprintf(urlPathAPIResolvers, n.apiVersion)
req, _ := web.NewHTTPRequestWithPath(n.Request, fmt.Sprintf(urlPathAPIResolvers, n.apiVersion))

var v nginxResolvers

Expand Down
Loading

0 comments on commit 28de8a8

Please sign in to comment.