-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix Prometheus metric types parser #39743
Fix Prometheus metric types parser #39743
Conversation
This pull request does not have a backport label.
To fixup this pull request, you need to add the backport labels for the needed
|
/test |
/test |
Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane) |
/test |
|
||
result, err := ParseMetricFamilies([]byte(input), ContentTypeTextFormat, time.Now(), nil) | ||
if err != nil { | ||
t.Fatalf("ParseMetricFamilies for content type %s returned an error.", ContentTypeTextFormat) |
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.
[Blocker]
Please log the error as well. Otherwise if this test fail it'll be difficult to understand why it failed.
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.
@gpop63 could you please apply the requested change here?
nginx_sts_server_connects_total{listen="TCP:8091:127.0.0.1",port="8091",protocol="TCP",code="5xx"} 171 | ||
nginx_sts_server_connects_total{listen="TCP:8091:127.0.0.1",port="8091",protocol="TCP",code="total"} 171 | ||
nginx_sts_server_session_seconds_total{listen="TCP:8091:127.0.0.1",port="8091",protocol="TCP"} 0.016 | ||
nginx_sts_server_session_seconds{listen="TCP:8091:127.0.0.1",port="8091",protocol="TCP"} 0.000 |
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.
[Suggestion]
2 things:
- from this the metric name of
nginx_sts_server_session_seconds_total
would benginx_sts_server_session_seconds
and the metric name ofnginx_sts_server_session_seconds
would benginx_sts_server_session
. Just checking, is my understand correct and is it the expected behaviour? - wouldn't be good to add 2 metrics with the same base name, like in your example
summary_metric_count
andsummary_metric_sum
?
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.
My example was for the metric family below (we have a test for this). The metric family is called summary_metric
and it includes various metrics such as summary_metric_sum
, summary_metric_count
, etc. We only want to store the metric type for the metric family summary_metric
since all its metrics share the same type, which is summary
.
# TYPE summary_metric summary
summary_metric{quantile="0.5"} 29735
summary_metric{quantile="0.9"} 47103
summary_metric{quantile="0.99"} 50681
summary_metric{noquantile="0.2"} 50681
summary_metric_sum 234892394
summary_metric_count 44000
summary_metric_impossible 123
# EOF
beats/metricbeat/helper/prometheus/textparse.go
Lines 525 to 535 in 28ed783
buf, t := parser.Type() | |
s := string(buf) | |
fam, ok = metricFamiliesByName[s] | |
if !ok { | |
fam = &MetricFamily{Name: &s, Type: t} | |
metricFamiliesByName[s] = fam | |
} else { | |
fam.Type = t | |
} | |
// Store the metric type for each base metric name. | |
metricTypes[s] = t |
s
represents the metric family name (e.g., summary_metric
). Only the metric family name is stored in the map, without its individual metrics.
For the examples you mentioned, nginx_sts_server_session_seconds_total
and nginx_sts_server_session_seconds
, these metrics are already the metric family names (they don't have any child metrics) and thus would not trigger the !ok
condition. The !ok
condition was added as an edge case for families that have multiple child metrics with different suffixes.
@fearful-symmetry / @VihasMakwana could you please review this PR? |
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.
Don't have much context for Prometheus specifically, but the code seems fine.
@gpop63 are we expecting to backport this in 8.14? |
@gpop63 could you have a look here please? |
@pierrehilbert Sorry for the late reply, we could backport it to |
* store metric types in a map * add test case * include error in fatal log * add changelog entry (cherry picked from commit 35158d8)
* store metric types in a map * add test case * include error in fatal log * add changelog entry (cherry picked from commit 35158d8) Co-authored-by: Gabriel Pop <[email protected]>
Overview
When processing a group of metrics of this format, the metric type variable is set to the latest metric type in the group, even if their types might differ. This happens because the parser thinks this is only 1 metric. This change stores the metric types for each base metric name to avoid this issue.
Checklist
CHANGELOG.next.asciidoc
orCHANGELOG-developer.next.asciidoc
.Disruptive User Impact
Author's Checklist
How to test this PR locally
Related issues
Use cases
Screenshots
Logs