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(nice-grpc-prometheus): add metrics customization #423

Merged

Conversation

gwer
Copy link
Contributor

@gwer gwer commented Aug 20, 2023

Hi!

I've found that the default buckets for histograms are not always suitable, and it would be useful to be able to customize them.

In looking for a way to change this I came to the conclusion that the most versatile and flexible way is to allow all metrics to be overridden.

Copy link
Contributor

@aikoven aikoven left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution!

Overall it looks good, but please address the issues below 👇

Comment on lines 14 to 20
export const labelNames = [
typeLabel,
serviceLabel,
methodLabel,
pathLabel,
codeLabel,
];
Copy link
Contributor

Choose a reason for hiding this comment

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

The set of labels is not the same for every metric. Particularly the code label is missing in some of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it.

  1. There is indeed an extra label, but it looks like it has absolutely no effect on behavior.
  2. Attempting to separate labels leads to more complexity for the user and more possibility of mistakes.

An alternative way is to create custom wrappers for each metric that encapsulate the necessary parts. But this is too cumbersome.

What are your thoughts on this? Maybe there are some suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed it seems that putting a label to that list does not make it required and does not affect the metrics where we don't use it.

However according to the code of prom-client it would break if we use the metric.label(...) method: it checks that the array lengths are the same.

That said, since we don't use that method, I'm ok with having it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've decided to separate labelNames and labelNamesWithCode for better reliability. Doesn't look as bad as I expected.

import {Histogram} from 'prom-client';

const clientHandlingSecondsMetric = new Histogram({
registers: [registry],
Copy link
Contributor

Choose a reason for hiding this comment

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

The example here reuses the lib's registry, which means that you won't be able to use the same metric names. So to change the buckets you would have to use custom names, which does not sound convenient.

The tests use a separate registry, which I think is the correct way to go. But we need an example to mention this and also show how to merge the registries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. It's updated now.

@aikoven
Copy link
Contributor

aikoven commented Aug 24, 2023

Looks great, thanks! I'm going to merge it and release shortly.

@aikoven aikoven merged commit 4eae37c into deeplay-io:master Aug 24, 2023
8 checks passed
@aikoven
Copy link
Contributor

aikoven commented Aug 24, 2023

Published 📦 nice-grpc-prometheus@0.2.0

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.

2 participants