-
Notifications
You must be signed in to change notification settings - Fork 925
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
Open
harshitrjpt
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
harshitrjpt:bug/6770-limit-prometheus-exemplar-labels
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+161
−11
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2bd6126
Limit prometheus exemplar labels (open-telemetry#6770)
harshitrjpt 965a8fa
Use codePointCount instead of length (open-telemetry#6770)
harshitrjpt 5a536f2
Merge branch 'open-telemetry:main' into bug/6770-limit-prometheus-exe…
harshitrjpt 280c548
Better warn log phrasing (open-telemetry#6770)
harshitrjpt 55a1bac
Better var name label
harshitrjpt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| + " unicode code points, 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 label : labels) { | ||
| codePoints += | ||
| label.getName().codePointCount(0, label.getName().length()) | ||
| + label.getValue().codePointCount(0, label.getValue().length()); | ||
| } | ||
| return codePoints; | ||
| } | ||
|
|
||
| private InfoSnapshot makeTargetInfo(Resource resource) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?