-
Notifications
You must be signed in to change notification settings - Fork 835
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(opentelemetry-exporter-prometheus): export PrometheusSerializer #3034
feat(opentelemetry-exporter-prometheus): export PrometheusSerializer #3034
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3034 +/- ##
=======================================
Coverage 92.64% 92.64%
=======================================
Files 187 187
Lines 6169 6169
Branches 1303 1303
=======================================
Hits 5715 5715
Misses 454 454
|
@matschaffer I don't think thats an issue to re-use it however you'll need to add a entry in |
Thanks @vmarchaud ! Should be all set on those points. |
Can’t you use the request handler that’s available on I am using |
@weyert I tried that but didn't see a good way to map from the KibanaResponseFactory API (https://github.com/elastic/kibana/blob/fa89c459ac71a9c911a5a2cc486dd3eff120d484/src/core/server/http/router/response.ts#L117) to ServerResponse. Similarly I wasn't sure how to cleanly pass in the unused Can you share the code you ended up using? |
Oh sorry, I am not well versed in Kibana but I had a quick look and at first sight it looked I am using it with Express so having less of a problem but I am doing something like: this_app.use((req, res) => {
If (this._exporter) {
this.exporter.getMetricsRequestHandler(req, res)
} else {
res.status(404).json({ message: ‘Not OK })
}
}) |
Thanks! I'll give another crack at it today. It feels like a bit of extra overhead to have a server-off PrometheusExporter as compared to a reusable PrometheusSerializer. But maybe the smaller public API surface area is worth that trade off. |
Yeah, that’s why I am using the handler and the prevent the server form starting to avoid a second server instance just for th metrics endpoint. That was my main reason for introducing the method in the past |
@vmarchaud @weyert so while To use that API I'd have to feed it an instantiated As such I'd like to propose we merge this API. That will enable me to use the PrometheusSerializer directly from my own kibana-compatible version of the PrometheusExporter. As shown on elastic/kibana#128755 (comment), the approach is functional but it'd be great not to have to fork Thanks in advance! |
No worries, I just tried to unblock you . Happy with the PR myself. I have approved it as an outsider ;) |
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'm good with exposing the PrometheusSerializer
. But I still would like to minimize the surfaced interfaces, i.e. hide all methods as private
and leave the basic PrometheusSerializer.serialize
as public
.
Would you mind taking that part of the work? Or I can help to do the chore.
@legendecas easy enough. I'll put it on my list for tomorrow. Thanks for the feedback 🧡 |
@legendecas does the project have any typical strategy for testing private methods? I was thinking I'll try updating the tests to work via the Some other ideas are:
|
Initial attempts at testing via |
@matschaffer generally options 1 and 3 are both fine. We already have practices on 3, i.e. testing with the bracket accessing, as it still preserves type information and TypeScript can properly check the type conformance. |
Thanks for the quick reply! Testing via |
4b3ac64
to
050ac63
Compare
experimental/packages/opentelemetry-exporter-prometheus/src/PrometheusSerializer.ts
Outdated
Show resolved
Hide resolved
experimental/packages/opentelemetry-exporter-prometheus/test/PrometheusSerializer.test.ts
Outdated
Show resolved
Hide resolved
1c45233
to
fb7b15d
Compare
Using underscore prefix to communicate intention for JS consumers. Also leverage bracket accessing to directly test private methods.
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.
LGTM. Thank you for your work on this!
Thanks @dyladan ! |
Which problem is this PR solving?
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Fixes #3033
Short description of the changes
Exports PrometheusSerializer from opentelemetry-exporter-prometheus
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
The existing test has been switched to include PrometheusSerializer from the package-level export.
Checklist: