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

Initialise metrics at startup #180

Open
roidelapluie opened this issue Sep 24, 2018 · 16 comments
Open

Initialise metrics at startup #180

roidelapluie opened this issue Sep 24, 2018 · 16 comments
Assignees
Labels
enhancement This is considered a feature request, not currently guaranteed by the code or design today mtail-Language/VM Issues related to the mtail language, compiler, or VM
Milestone

Comments

@roidelapluie
Copy link
Contributor

roidelapluie commented Sep 24, 2018

Just like in awk BEGIN,

I would like to be able to initiate metrics.

counter http_requests_duration_seconds_sum by code

BEGIN {
  http_requests_duration_seconds_sum["200"] = 0
}
@roidelapluie
Copy link
Contributor Author

roidelapluie commented Sep 24, 2018

A workaround:

hidden counter init

init == 0 {
    http_requests_duration_seconds_sum["200"] += 0
    init++
}

But then we need to check init each time, which is not performant.

@jnovack
Copy link
Contributor

jnovack commented Sep 24, 2018

I think this runs DANGEROUSLY close to confusing zero (0) with null. If you are initiating it with zero (0), then you are effectively skewing results when averaged over time. If a metric cannot be collected, it SHOULD be considered missing, not none.

I would not want this metric reading to be 0 if I just restarted the program before the first poll.
image

However, doing some digging. Is this related to why you need it set? prometheus/prometheus#1853

Per the Prometheus Best Practices:

Avoid missing metrics
Time series that are not present until something happens are difficult to deal with, as the usual simple operations are no longer sufficient to correctly handle them. To avoid this, export 0 (or NaN, if 0 would be misleading) for any time series you know may exist in advance.

Most Prometheus client libraries (including Go, Java, and Python) will automatically export a 0 for you for metrics with no labels.

@roidelapluie
Copy link
Contributor Author

Yes, I want to initiate counters with labels to 0. It is different from setting gauges, which makes less sense.

@jaqx0r
Copy link
Contributor

jaqx0r commented Sep 26, 2018 via email

@jnovack
Copy link
Contributor

jnovack commented Sep 26, 2018

Stlil a bit uneasy about the syntax; we only want to allow counters to be initialized?

I can come up with a contrived example of why gauges should be initialized, but I do not have an actual example. I would want to set the gauge to zero when a gauge is measured as an offset of another number without a log file line stating as such (If we're using mtail, the application is probably not logging or metricing (verb) the way we want to, and we have to give intelligence to it, anyway). On application start, if I'm measuring drift of something that only complains when drift is NOT zero, I would like to initialize it as zero on my metrics so I can watch it drift from zero, rather than all of a sudden SEEING it at ±1 after a "missing" period.

I worry though that this feature (like all features) creates an explosion of possibility and thus grants mtail programs the power to become very slow at processing log lines.

Acknowledging feature creep, initializing is just for startup (runonce), it is just to initialize variables (no logic), and it is recommended practice by Prometheus.

@jaqx0r
Copy link
Contributor

jaqx0r commented Oct 31, 2018 via email

@jaqx0r
Copy link
Contributor

jaqx0r commented Nov 5, 2018

I think this is easier to implement without a BEGIN block but by allowing an initialisation expression after the metric declaration, e.g.:

counter foo = 0

just like in C++.

@jaqx0r jaqx0r added the enhancement This is considered a feature request, not currently guaranteed by the code or design today label Nov 5, 2018
@jaqx0r jaqx0r self-assigned this Nov 5, 2018
@jaqx0r jaqx0r changed the title Initiate mecrics Initialise metrics at startup Nov 5, 2018
@jaqx0r
Copy link
Contributor

jaqx0r commented Nov 5, 2018

Huh, that doesn't work for the case in your first comment, with a dimensioned metric. :/

@roidelapluie
Copy link
Contributor Author

yeah because the counters are already 0 when they are not dimensional in mtail (IIRC)

@jaqx0r
Copy link
Contributor

jaqx0r commented Nov 8, 2018

Facepalm. Thanks for the reminder :-)

@jaqx0r jaqx0r added this to the 3.0.0 milestone Nov 8, 2018
@darkl0rd
Copy link

darkl0rd commented Feb 12, 2019

I've just started using mtail, but this one of the first things that confused me.
I noticed all my counters in prometheus went missing when there are no matches (thus value = 0) and they will show up again when the value > 0. I can understand what the technical reasons are for this, but from a practical point of view, it is rather inconvenient that certain metrics simply disappear when their values are 0 (or in reality, probably null?).

I feel that when there are no matches, the value should always be set to '0' rather than omitting it.

@SuperQ
Copy link
Contributor

SuperQ commented Jul 25, 2019

One reason for initializing any gauge/counter/histogram is where you have by labels. The standard example is when you have counter http_requests_total by status. You want to be able to init status="500" to make sure you don't have a zero count for 500 errors. This is especially important when you do matching things in Prometheus.

sum without (status) (rate(http_requests_total{status="500"}[1m])) /
sum without (status) (rate(http_requests_total[1m]))

This will return no value if "500" is missing as there are no results on the left side of the expression.

@praetp
Copy link

praetp commented Nov 6, 2019

Any progress on this ? We are using mtail based metrics to detect anomalies. However, we currently hitting prometheus/prometheus#1673. We would not hit this problem if the metric would be initialized to zero.

@roidelapluie
Copy link
Contributor Author

@praetp did you try #180 (comment)?

@praetp
Copy link

praetp commented Nov 10, 2019

@praetp did you try #180 (comment)?

Our counters are in fact dimensionless, so I just needed to upstep to a newer version of mtail :)

@roidelapluie
Copy link
Contributor Author

There is even no syntax I know of that can initialize histograms (regardless of BEGIN or not).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is considered a feature request, not currently guaranteed by the code or design today mtail-Language/VM Issues related to the mtail language, compiler, or VM
Projects
None yet
Development

No branches or pull requests

6 participants