-
Notifications
You must be signed in to change notification settings - Fork 921
Limit prometheus exemplar labels #6791
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
2bd6126
965a8fa
5a536f2
280c548
55a1bac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| import io.prometheus.metrics.model.snapshots.HistogramSnapshot.HistogramDataPointSnapshot; | ||
| import io.prometheus.metrics.model.snapshots.InfoSnapshot; | ||
| import io.prometheus.metrics.model.snapshots.InfoSnapshot.InfoDataPointSnapshot; | ||
| import io.prometheus.metrics.model.snapshots.Label; | ||
| import io.prometheus.metrics.model.snapshots.Labels; | ||
| import io.prometheus.metrics.model.snapshots.MetricMetadata; | ||
| import io.prometheus.metrics.model.snapshots.MetricSnapshot; | ||
|
|
@@ -77,6 +78,7 @@ final class Otel2PrometheusConverter { | |
| private static final String OTEL_SCOPE_VERSION = "otel_scope_version"; | ||
| private static final long NANOS_PER_MILLISECOND = TimeUnit.MILLISECONDS.toNanos(1); | ||
| static final int MAX_CACHE_SIZE = 10; | ||
| static final int EXEMPLAR_MAX_CODE_POINTS = 128; | ||
|
|
||
| private final boolean otelScopeEnabled; | ||
| @Nullable private final Predicate<String> allowedResourceAttributesFilter; | ||
|
|
@@ -400,29 +402,44 @@ private Exemplars convertDoubleExemplars(List<DoubleExemplarData> exemplars) { | |
| return Exemplars.of(result); | ||
| } | ||
|
|
||
| @Nullable | ||
| private Exemplar convertExemplar(double value, ExemplarData exemplar) { | ||
| SpanContext spanContext = exemplar.getSpanContext(); | ||
| Labels labels = Labels.EMPTY; | ||
| if (spanContext.isValid()) { | ||
| return new Exemplar( | ||
| value, | ||
| labels = | ||
| convertAttributes( | ||
| null, // resource attributes are only copied for point's attributes | ||
| null, // scope attributes are only needed for point's attributes | ||
| exemplar.getFilteredAttributes(), | ||
| "trace_id", | ||
| spanContext.getTraceId(), | ||
| "span_id", | ||
| spanContext.getSpanId()), | ||
| exemplar.getEpochNanos() / NANOS_PER_MILLISECOND); | ||
| spanContext.getSpanId()); | ||
| } else { | ||
| return new Exemplar( | ||
| value, | ||
| convertAttributes( | ||
| null, // resource attributes are only copied for point's attributes | ||
| null, // scope attributes are only needed for point's attributes | ||
| exemplar.getFilteredAttributes()), | ||
| exemplar.getEpochNanos() / NANOS_PER_MILLISECOND); | ||
| labels = convertAttributes(null, null, exemplar.getFilteredAttributes()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test that covers this (codecov claims it's not tested, and it seems like it would be good to have it covered) |
||
| } | ||
| int codePoints = getCodePoints(labels); | ||
| if (codePoints > EXEMPLAR_MAX_CODE_POINTS) { | ||
| THROTTLING_LOGGER.log( | ||
| Level.WARNING, | ||
| "exemplar labels have " | ||
| + codePoints | ||
| + " codePoints, exceeding the limit of " | ||
|
||
| + EXEMPLAR_MAX_CODE_POINTS); | ||
| return null; | ||
| } | ||
| return new Exemplar(value, labels, exemplar.getEpochNanos() / NANOS_PER_MILLISECOND); | ||
| } | ||
|
|
||
| private static int getCodePoints(Labels labels) { | ||
| int codePoints = 0; | ||
| for (Label l : labels) { | ||
jkwatson marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| codePoints += | ||
| l.getName().codePointCount(0, l.getName().length()) | ||
| + l.getValue().codePointCount(0, l.getValue().length()); | ||
| } | ||
| return codePoints; | ||
| } | ||
|
|
||
| private InfoSnapshot makeTargetInfo(Resource resource) { | ||
|
|
||
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.
Is this based on the specification somewhere?