-
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 <hello@matteocollina.com>
index.js
Outdated
| 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
| 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
| 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 <hello@matteocollina.com>
|
@ivan-tymoshenko PTAL |
MzUgM
left a comment
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
ivan-tymoshenko
left a comment
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.