Repository navigation
feat: bind exposition writers to negotiated escaping #2642
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
zeitlinger
wants to merge
6
commits into
main
Choose a base branch
from
fix/negotiated-exposition
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.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6f96ad9
feat: bind exposition writers to negotiated escaping
zeitlinger 287d883
style: format negotiated exposition writer
zeitlinger 95ff84c
docs: update exposition text formats API diff
zeitlinger 83099af
fix: normalize generated API diff reports
zeitlinger 6ca7c6d
docs: explain negotiated exposition writers
zeitlinger f862a6c
fix: bind escaping to selected exposition media type
zeitlinger 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
12 changes: 11 additions & 1 deletion
12
docs/apidiffs/current_vs_latest/prometheus-metrics-exposition-textformats.txt
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
45 changes: 45 additions & 0 deletions
45
...main/java/io/prometheus/metrics/expositionformats/ExpositionFormatWriterWithEscaping.java
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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package io.prometheus.metrics.expositionformats; | ||
|
|
||
| import io.prometheus.metrics.annotations.StableApi; | ||
| import io.prometheus.metrics.config.EscapingScheme; | ||
| import io.prometheus.metrics.model.snapshots.MetricSnapshots; | ||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
|
|
||
| /** | ||
| * An exposition format writer paired with the escaping scheme selected from an Accept header. | ||
| * | ||
| * <p>Instances are immutable and delegate to the underlying format writer. The content type is the | ||
| * format's standard content type and does not include an escaping parameter. | ||
| */ | ||
| @StableApi | ||
| public final class ExpositionFormatWriterWithEscaping { | ||
|
|
||
| private final ExpositionFormatWriter writer; | ||
| private final EscapingScheme escapingScheme; | ||
|
|
||
| ExpositionFormatWriterWithEscaping(ExpositionFormatWriter writer, EscapingScheme escapingScheme) { | ||
| this.writer = writer; | ||
| this.escapingScheme = escapingScheme; | ||
| } | ||
|
|
||
| /** Writes the given metric snapshots using the negotiated escaping scheme. */ | ||
| public void write(OutputStream out, MetricSnapshots metricSnapshots) throws IOException { | ||
| writer.write(out, metricSnapshots, escapingScheme); | ||
| } | ||
|
|
||
| /** Converts the metric snapshots to a debug string using the negotiated escaping scheme. */ | ||
| public String toDebugString(MetricSnapshots metricSnapshots) { | ||
| return writer.toDebugString(metricSnapshots, escapingScheme); | ||
| } | ||
|
|
||
| /** Returns the standard content type for the selected exposition format. */ | ||
| public String getContentType() { | ||
| return writer.getContentType(); | ||
| } | ||
|
|
||
| /** Returns the escaping scheme selected from the Accept header. */ | ||
| public EscapingScheme getEscapingScheme() { | ||
| return escapingScheme; | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Since this is
@StableApi: was leaving out an accessor for the underlyingExpositionFormatWriterdeliberate? Without one, callers can't check
isAvailable()or which format was picked otherthan by comparing content types. Adding it later is non-breaking, so fine either way.
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.
Thanks for asking. I left out a delegate accessor so the negotiated wrapper remains the write path and keeps output bound to the selected escaping scheme; exposing the raw writer would also expand the StableApi surface. The wrapper exposes its content type and escaping scheme, and callers can inspect availability through
findWriter(acceptHeader). I have not added an accessor; if a concrete caller need remains, I think that deserves a separate API decision.