-
Notifications
You must be signed in to change notification settings - Fork 842
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
Limit prometheus exemplar labels #6791
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 @@ | |
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 @@ | |
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()); | ||
Check warning on line 420 in exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverter.java Codecov / codecov/patchexporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverter.java#L420
|
||
} | ||
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) { | ||
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. strongly suggest you rename l -> label. Otherwise it looks like the number '1' 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. @jkwatson i don't think it's a big deal as the loop is too small, but i suppose it does help in quicker reading. I addressed it in latest commit. |
||
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.
i'd replace
codePoints
withunicode code points
to make it easier to understand what this warning meansThere 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.
@laurit addressed.