-
Notifications
You must be signed in to change notification settings - Fork 365
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
consolidating collect functions for multiple metrics #538
Comments
I think we'd need to add some registry-level hook/event for this that tells you "collect is about to be called," but that has some risk too if there are concurrent collections for some reason. Could you do something like this as a workaround? let employees;
let nCollected = 0;
// in each metric
collect() {
if (!employees)
employees = await getAllEmployees();
this.set({}, /* value */);
nCollected++;
if (nCollected === 2) {
employees = null;
nCollected = 0;
}
} |
thats indeed a workaround - thanks. (Id be happier if a better solution exists - maybe something where a collection can hook onto another collection) however I will just cache |
Would be nice to be able to create multiple metrics at the same time using a common collect function. Something like:
Then when collect runs, the set function could update all metrics at once. |
Just realized I should be using labels for this instead, not multiple metrics. |
I have the following example:
Now
getAllEmployees
is a very expensive query, which takes some time to retrieve. And that's rather bad if we have to call this method for each metric.I could however add to the second
collect
-function the following snippet:and leave out the
collect
-function of the first metric. But now we have a running condition - which collect function is called first, and is it fast enough? should I rather add asetTimeout(Promise.resolve(),500)
into the firstcollect
-function so it doesnt resolve before the value is set in the secondcollect
-function?now I have more metrics I want to collect for the hypothetical employees
what is the best way to solve this?
The text was updated successfully, but these errors were encountered: