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

feat(prometheus): add getMetricsRequestHandler-method to Prometheus… #1881

Conversation

tapico-weyert
Copy link
Contributor

… exporter

This commit introduces a new method on the PrometheusExporter-class that
allows users of server frameworks with an existing service instance to
call the getMetricsRequestHandler-method as part of a route to return
the collected metrics in Prometheus format.

Fixes #1872

Which problem is this PR solving?

  • Allows using an existing server instance to expose the Prometheus endpoint / metrics

Short description of the changes

  • Added a new getMetricsRequestHandler-method to the PrometheusExporter-class which calls the internal _exportMetrics-method

… exporter

This commit introduces a new method on the `PrometheusExporter`-class that
allows users of server frameworks with an existing service instance to
call the `getMetricsRequestHandler`-method as part of a route to return
the collected metrics in Prometheus format.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 28, 2021

CLA Signed

The committers are authorized under a signed CLA.

@codecov
Copy link

codecov bot commented Jan 28, 2021

Codecov Report

Merging #1881 (d0fefc9) into main (d54c5c8) will increase coverage by 0.23%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1881      +/-   ##
==========================================
+ Coverage   92.35%   92.58%   +0.23%     
==========================================
  Files         157      174      +17     
  Lines        5104     6032     +928     
  Branches     1085     1278     +193     
==========================================
+ Hits         4714     5585     +871     
- Misses        390      447      +57     
Impacted Files Coverage Δ
...etry-exporter-prometheus/src/PrometheusExporter.ts 91.04% <100.00%> (-1.27%) ⬇️
...kages/opentelemetry-node/src/NodeTracerProvider.ts 96.55% <0.00%> (-3.45%) ⬇️
...ges/opentelemetry-instrumentation-http/src/http.ts 94.73% <0.00%> (-0.81%) ⬇️
.../opentelemetry-exporter-collector/src/transform.ts 87.85% <0.00%> (ø)
packages/opentelemetry-web/src/types.ts 100.00% <0.00%> (ø)
...s/opentelemetry-instrumentation-fetch/src/fetch.ts 96.00% <0.00%> (ø)
...lemetry-exporter-collector/src/transformMetrics.ts 95.00% <0.00%> (ø)
...kages/opentelemetry-exporter-collector/src/util.ts 100.00% <0.00%> (ø)
...es/opentelemetry-context-zone-peer-dep/src/util.ts 100.00% <0.00%> (ø)
... and 11 more

* @param request Incoming HTTP request of server instance
* @param response HTTP response objet used to response to request
*/
public getMetricsRequestHandler(
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: I'm not a Prometheus user and have no knowledge of it's inner workings, but I think the name and description of this function is misleading based on what the issue is talking about and looking at the implementation.

Based on m limited understanding it looks like you are really trying to "reuse" the internal pipeline, rather than "return" (i.e. get) the MetricsRequestHandler.

As such I would think (I'll let the Prometheus experts and approvers / maintainers correct me and tell me I'm wrong) the name of the method would better be named as "handleRequest" or "publishMetrics" or something like that based on the way the internal _exportMetrics() function is used from the _requestHandler. There may also be some considerations around the batcher usage if the request is a different URL's...

@tapico-weyert
Copy link
Contributor Author

Closing this pull request in favour of #1879

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.

Expose request handler of Prometheus exporter
2 participants