Skip to content

feat: added support for adding labels to default metrics #374

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

Merged
merged 9 commits into from
Sep 26, 2020

Conversation

rkoval
Copy link
Contributor

@rkoval rkoval commented Jun 11, 2020

I believe this resolves #224. I was also needing a mechanism like this for applying labels to worker processes when running in a clustered environment.

I did it a bit more generically than just the suggested collectDefaultMetrics({includeWorkerId: true}) because our project setup prevents us from using lib/cluster.js. We're using a pm2 wrapper around our nodejs parent process which has some nuances when using the nodejs cluster module directly from lib/cluster.js. As such, this should appease a wider audience of users who just want to generically apply labels to default metrics (including myself)

@@ -71,6 +71,21 @@ describe('collectDefaultMetrics', () => {
});
});

it('should apply labels to metrics when configured', () => {
const labels = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a expect.assertions(5) (or whatever the number is)?

Copy link
Contributor Author

@rkoval rkoval Jun 26, 2020

Choose a reason for hiding this comment

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

Can you please elaborate on what this type of assertion is supposed to do? I'm not actually familiar with it, and it appears to produce different results when running locally vs. CI (this commit's tests do not fail for me locally on my mac using node v12.16.1, though they appear to be failing in CI). I'm guessing I'm just using it wrong, but I don't see any other examples of it in this repo for help

Copy link
Collaborator

Choose a reason for hiding this comment

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

https://jestjs.io/docs/en/expect#expectassertionsnumber - it ensures that that many assertions are made, which makes sure tests don't falsely pass if some bug causes the async callback not to run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do you know why this function produces inconsistent results / doesn't always have the same number of assertions? i can actually reproduce the inconsistencies locally:
image
the first run has 47 assertions, but the second only has 45 (i didn't change any code between each run)

Copy link
Collaborator

Choose a reason for hiding this comment

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

probably something async we're not properly waiting for

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, what would you like to do here? again, this type of assertion isn't used anywhere else in the codebase, so i might just have to close this PR and just use our own fork if it'll be blocked without it. i unfortunately don't have time to debug the issue

Copy link
Collaborator

Choose a reason for hiding this comment

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

went with a slightly different approach

@SimenB SimenB requested review from zbjornson and siimon June 19, 2020 09:16
@rkoval rkoval force-pushed the master branch 3 times, most recently from 8bb8aa9 to 863ae67 Compare June 26, 2020 07:16
@@ -84,6 +84,7 @@ describe('collectDefaultMetrics', () => {
expect(metricValue.labels).toMatchObject(labels);
});
});
expect.assertions(45);
Copy link
Collaborator

Choose a reason for hiding this comment

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

(I'm not sure if it matters, but usually this is the first line of the it function.)

@zbjornson
Copy link
Collaborator

I like this approach!

Sorry for the hassle but can you rebase on master please?

@rkoval
Copy link
Contributor Author

rkoval commented Jul 5, 2020

@zbjornson this has been rebased on the current master

@SimenB
Copy link
Collaborator

SimenB commented Aug 24, 2020

@zbjornson @siimon PTAL

@siimon
Copy link
Owner

siimon commented Aug 25, 2020

👍

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.

Request: an option for aggregating cluster metrics that preserves worker id
4 participants