Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For Prometheus Default metrics, can we host value across all standard metrics #88

Closed
3 tasks done
ankittiwari-harness opened this issue Mar 1, 2023 · 3 comments
Closed
3 tasks done

Comments

@ankittiwari-harness
Copy link
Contributor

ankittiwari-harness commented Mar 1, 2023

Issue Description

For all the standard Metrics, there are 3 labels present, However, the 4th Label host is available on one of the metrics

echo_request_size_bytes_count{code="200",method="POST",url="/v1/api"} 1200

echo_requests_total{code="200",host="localhost:9090",method="POST",url="/v1/api"} 104

Ideally we should add Host label as having host helps in differentiating the same API call across multiple service while scraping these metrics

Checklist

  • Dependencies installed
  • No typos
  • Searched existing issues and docs

Expected behaviour

Actual behaviour

Steps to reproduce

Working code to debug

package main

func main() {
}

Version/commit

@aldas
Copy link
Contributor

aldas commented Mar 1, 2023

Probably these lines:

"host" needs to be added as arg

Args: []string{"code", "method", "url"},

and provided here

p.reqDur.WithLabelValues(statusStr, c.Request().Method, url).Observe(elapsed)
p.reqCnt.WithLabelValues(statusStr, c.Request().Method, p.RequestCounterHostLabelMappingFunc(c), url).Inc()
p.reqSz.WithLabelValues(statusStr, c.Request().Method, url).Observe(float64(reqSz))
resSz := float64(c.Response().Size)
p.resSz.WithLabelValues(statusStr, c.Request().Method, url).Observe(resSz)

@ankittiwari-harness
Copy link
Contributor Author

Yeah, the changes would be exactly here.

Here is the PR for this from my fork

#89

aldas pushed a commit that referenced this issue Mar 1, 2023
Issue #88 Adding Host Label to all metrics
@aldas aldas closed this as completed Mar 1, 2023
@aldas
Copy link
Contributor

aldas commented Mar 3, 2023

NB: path is added to metrics this way:

RequestCounterURLLabelMappingFunc: func(c echo.Context) string {
p := c.Path() // contains route path ala `/users/:id`
if p != "" {
return p
}
// as of Echo v4.10.1 path is empty for 404 cases (when router did not find any matching routes)
// in this case we use actual path from request to have some distinction in Prometheus
return c.Request().URL.Path
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants