-
Notifications
You must be signed in to change notification settings - Fork 1
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
Calling GET /metrics results in clearing all cached metrics #3
Comments
After reading the rest of the code, I found out that older values for metrics are kept in In that since, I believe |
I think we need to change the following code with the code suggested afterwards. Current code: node-prom-pushgateway/lib/gateway.js Lines 213 to 218 in f8e56cd
Suggested code: // never omit any known metrics, report the previous value if no change
// This allows /metrics to be called more frequently than the /push interval.
var allValues = {};
const now = this.getTimestamp();
const oldestKeepTs = this.maxMetricAgeMs >= 0 ? (now - this.maxMetricAgeMs) : 0;
const filterOldMetrics = this.maxMetricAgeMs >= 0;
for (id in this.previousValues) {
if (!filterOldMetrics || this.previousValues[id].ts >= oldestKeepTs) {
allValues[id] = this.previousValues[id];
}
}
const discardedMetrics = Object.keys(this.previousValues).length - Object.keys(allValues).length;
if (discardedMetrics > 0) {
Gateway.trace("discarding %d metrics older than %d ms", discardedMetrics, this.maxMetricAgeMs);
}
for (id in map) allValues[id] = map[id];
this.previousValues = allValues; |
This snippet is taken from
reportMetrics()
which is called upon receiving a request toGET /metrics
.node-prom-pushgateway/lib/gateway.js
Lines 181 to 196 in f8e56cd
In this part,
samples.splice(0)
results in removing all stored samples inthis.samples
. I don't get why this is needed. There is already a mechanism to get rid of old samples usingmaxMetricAgeMs
.Here is more context on why it doesn't make sense to remove cached metrics:
prom-pushgateway
should serve as a caching layer.prom-pushgateway
. pushing a new value formetric_1{<label_set>}
should overwrite any previous value for that metric and label set. However, pushing a new metricmetric_2
should not result in removingmetric_1
.GET /metrics
should not affect the cached metrics.samples.splice(0)
results in clearing all cached metrics whenGET /metrics
is called!I appreciate your inputs on this and I'm happy to open a PR with a solution.
The text was updated successfully, but these errors were encountered: