Skip to content
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

Output EOF following the OpenMetrics exposition recommendation #3654

Merged
merged 5 commits into from
Sep 14, 2022

Conversation

reyang
Copy link
Member

@reyang reyang commented Sep 13, 2022

Changes

  • Added support for EOF.

Reference: https://github.com/OpenObservability/OpenMetrics/blob/main/specification/OpenMetrics.md#overall-structure

image

For significant contributions please make sure you have completed the following items:

  • Appropriate CHANGELOG.md updated for non-trivial changes

@reyang reyang requested a review from a team as a code owner September 13, 2022 19:06
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int WriteEof(byte[] buffer, int cursor)
{
cursor = WriteAsciiStringNoEscape(buffer, cursor, "# EOF");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about prometheus, but I assume this won't cause an older prometheus scrapper to blow up?

Also, is simply adding # EOF enough to warrant a change to the content-type to application/openmetrics-text?

response.ContentType = "text/plain; charset=utf-8; version=0.0.4";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about prometheus, but I assume this won't cause an older prometheus scrapper to blow up?

I've tested this with older version of scrappers.

image

Also, is simply adding # EOF enough to warrant a change to the content-type to application/openmetrics-text?

response.ContentType = "text/plain; charset=utf-8; version=0.0.4";

I guess the answer is no, I keep learning new things while reading the OpenMetrics spec, e.g. #3651. I think we need to do a full scan of the spec, maybe it's okay to flip the content-type earlier?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's okay to flip the content-type earlier?

Probably fine to wait since content-type might be a thing that would affect older scrapers. But may become necessary with exemplar support?

@codecov
Copy link

codecov bot commented Sep 14, 2022

Codecov Report

Merging #3654 (82187e5) into main (3a8f139) will decrease coverage by 0.31%.
The diff coverage is 33.33%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3654      +/-   ##
==========================================
- Coverage   87.88%   87.57%   -0.32%     
==========================================
  Files         283      283              
  Lines       10264    10276      +12     
==========================================
- Hits         9021     8999      -22     
- Misses       1243     1277      +34     
Impacted Files Coverage Δ
...tpListener/Internal/PrometheusCollectionManager.cs 74.72% <20.00%> (-5.77%) ⬇️
...heus.HttpListener/Internal/PrometheusSerializer.cs 80.83% <100.00%> (+0.49%) ⬆️
...entation/ExportClient/OtlpGrpcTraceExportClient.cs 35.71% <0.00%> (-42.86%) ⬇️
...xporter.OpenTelemetryProtocol/OtlpTraceExporter.cs 36.36% <0.00%> (-40.91%) ⬇️
...Listener/Internal/PrometheusExporterEventSource.cs 16.66% <0.00%> (-11.12%) ⬇️
...metheus.AspNetCore/PrometheusExporterMiddleware.cs 60.71% <0.00%> (-7.15%) ⬇️
...metryProtocol/Implementation/ActivityExtensions.cs 91.75% <0.00%> (-3.30%) ⬇️
....Prometheus.HttpListener/PrometheusHttpListener.cs 80.00% <0.00%> (-2.67%) ⬇️
src/OpenTelemetry/Logs/OpenTelemetryLogger.cs 86.66% <0.00%> (-2.23%) ⬇️
... and 1 more

@Kielek
Copy link
Contributor

Kielek commented Sep 14, 2022

I do not check the specification, but it is worth to double check how it should behave when there is no metrics to export.
Should it be 200 with empty response or 200 with # EOF\n?

Ref: #3643

@reyang
Copy link
Member Author

reyang commented Sep 14, 2022

I do not check the specification, but it is worth to double check how it should behave when there is no metrics to export. Should it be 200 with empty response or 200 with # EOF\n?

Ref: #3643

Good point, the current approach is returning HTTP 200 without content/content-type, so technically it is not a Prometheus nor OpenMetrics exposition format (which means OpenMetrics spec won't apply).

@CodeBlanch CodeBlanch merged commit e68abc8 into open-telemetry:main Sep 14, 2022
@reyang reyang deleted the reyang/prometheus-eof branch March 2, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants