-
Notifications
You must be signed in to change notification settings - Fork 0
Add fake metric entry to populate prometheus #35
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
Conversation
Signed-off-by: Matteo Collina <[email protected]>
Signed-off-by: Matteo Collina <[email protected]>
index.js
Outdated
@@ -27,19 +27,45 @@ module.exports = fp(async function (fastify, opts) { | |||
return false | |||
} | |||
|
|||
let needEntrySummary = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this optional (disabled by default.)
index.js
Outdated
const summary = new Summary({ | ||
name: 'http_request_summary_seconds', | ||
help: 'request duration in seconds summary', | ||
labelNames, | ||
registers, | ||
collect: function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will save an "empty" metric every time the prom fetches metrics (every 1s in most cases). Are you sure you need to push a new metric every second and not just save it once after summary/histogram initialisation?
something like summary.observe(0)
index.js
Outdated
const histogram = new Histogram({ | ||
name: 'http_request_duration_seconds', | ||
help: 'request duration in seconds', | ||
labelNames, | ||
registers, | ||
collect: function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe histogram.zero
can be useful:
https://github.com/siimon/prom-client?tab=readme-ov-file#zeroing-metrics-with-labels
index.js
Outdated
if (needEntrySummary) { | ||
const summaryTimer = this.startTimer() | ||
summaryTimer({ | ||
method: 'GET', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny problem with that solution is that it will work only if you aggregate values when you query the prom metrics. For example if I want to get metrics for all POST requests or all requests with status code 200 they will not have this default values as they stored with labels "GET/__empty_metrics/404".
Obviously we don't know all route labels, but maybe it will make sense to store such metrics for some method + status_code combinations.
Signed-off-by: Matteo Collina <[email protected]>
@ivan-tymoshenko PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Alternative implementation of platformatic/platformatic#3883.