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

Add support for openmetrics 0.0.1 besides 1.0.0 #1640

Merged
merged 10 commits into from
Aug 20, 2024

Conversation

rg2011
Copy link
Contributor

@rg2011 rg2011 commented Aug 8, 2024

Continuation to #1627 - The current version of prometheus collector in openshift has been found to request openmetrics 0.0.1

@rg2011 rg2011 changed the title Add suppport for both openmetrics 0.0.1 and 1.0.0 Add support for both openmetrics 0.0.1 and 1.0.0 Aug 8, 2024
@rg2011 rg2011 changed the title Add support for both openmetrics 0.0.1 and 1.0.0 [WIPAdd support for both openmetrics 0.0.1 and 1.0.0 Aug 8, 2024
@rg2011 rg2011 changed the title [WIPAdd support for both openmetrics 0.0.1 and 1.0.0 [WIP] Add support for both openmetrics 0.0.1 and 1.0.0 Aug 8, 2024
@rg2011
Copy link
Contributor Author

rg2011 commented Aug 8, 2024

I changed the subject to [WIP] because I intend to add some unit tests of the openmetricsHandler function to make sure Accept headers are processed correctly. But the tests would require a new devDependency to node-mocks-http

@fgalan , @AlvaroVega, would you be ok with adding devDependency node-mocks-http?

@rg2011 rg2011 changed the title [WIP] Add support for both openmetrics 0.0.1 and 1.0.0 [WIP] Add support for openmetrics 0.0.1 besides 1.0.0 Aug 8, 2024
@AlvaroVega
Copy link
Member

@fgalan , @AlvaroVega, would you be ok with adding devDependency node-mocks-http?

Yes, I'm OK with that.

@rg2011 rg2011 changed the title [WIP] Add support for openmetrics 0.0.1 besides 1.0.0 Add support for openmetrics 0.0.1 besides 1.0.0 Aug 8, 2024
@rg2011
Copy link
Contributor Author

rg2011 commented Aug 8, 2024

finally I refactored the code I wanted to test out of the request handler, so I could unit test it without dependencies. The PR i sready for review.

Comment on lines 88 to 94
for (let part of parts.slice(1)) {
if (part.startsWith('version=')) {
version = part.substring(8).trim();
} else if (part.startsWith('charset=')) {
charset = part.substring(8).trim();
} else if (part.startsWith('q=')) {
preference = parseFloat(part.substring(2).trim());
Copy link
Member

@fgalan fgalan Aug 8, 2024

Choose a reason for hiding this comment

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

In order to avoid magic numbers maybe it's better this way:

Suggested change
for (let part of parts.slice(1)) {
if (part.startsWith('version=')) {
version = part.substring(8).trim();
} else if (part.startsWith('charset=')) {
charset = part.substring(8).trim();
} else if (part.startsWith('q=')) {
preference = parseFloat(part.substring(2).trim());
let versionTokenLength = 'version='.length;
let qTokenLength = 'q='.length;
for (let part of parts.slice(1)) {
if (part.startsWith('version=')) {
version = part.substring(versionTokenLength ).trim();
} else if (part.startsWith('charset=')) {
charset = part.substring(versionTokenLength ).trim();
} else if (part.startsWith('q=')) {
preference = parseFloat(part.substring(qTokenLength).trim());

(Code not actually tested, it may not run, but you get the idea :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in 679813e

@rg2011 rg2011 requested a review from fgalan August 12, 2024 08:52
Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

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

LGTM

Passing the ball to @AlvaroVega for extra review and LGTM

Copy link
Member

@AlvaroVega AlvaroVega left a comment

Choose a reason for hiding this comment

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

LGTM

@AlvaroVega AlvaroVega merged commit 9ba35d4 into telefonicaid:master Aug 20, 2024
8 checks passed
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.

3 participants