Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

feat: add prometheus stats exporter to opencensus nodejs #96

Merged
merged 3 commits into from
Aug 29, 2018

Conversation

djonathascardoso
Copy link
Member

This PR adds prometheus stats exporter to opencensus nodejs. Unit tests are included.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@googlebot
Copy link

CLAs look good, thanks!

@djonathascardoso djonathascardoso force-pushed the exporter_prometheus branch 2 times, most recently from 859cf6e to c15055c Compare August 20, 2018 14:07
private registerMetric(view: View, tags?: Tags): Metric {
const metricName = this.getPrometheusMetricName(view);
/** Get metric if already registered */
const metric = register.getSingleMetric(metricName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to set up a registry belonging to this Exporter instance, instead of registering to a global registry?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it's possible. I'll change.

const metric = register.getSingleMetric(metricName);

// Create a new metric if there is no one
if (!metric) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest swapping this and write if (metric) { return metric; }, and everything else afterwards.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I'll change.

// Creating the metric based on aggregation type
switch (view.aggregation) {
case AggregationType.COUNT:
return new Counter(metricObj);
Copy link
Contributor

Choose a reason for hiding this comment

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

Will whatever gets returned here be returned the next time register.getSingleMetric is called with the same metric name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, because this new instance run the registerMetric in background. Anyway, I'm going to change this to fit with the proposed changes in your first comment.

* Get a string unit type based on measure unit
* @param view View used to get the unit
*/
private getUnit(view: View): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: getUnits

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case I believe the correct is getUnit because it returns only one unit

Copy link
Contributor

Choose a reason for hiding this comment

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

In colloquial English we typically say "units", even for one unit. But I'm not sure if this is grammatically correct, so we can keep it this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok

}

/**
* Not used in this context
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you elaborate here that metrics can't happen because it depends on information that is only present in Measurement objects?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I'll put this.


/** Format and sends Stats to Prometheus */
export class PrometheusStatsExporter implements StatsEventListener {
static readonly defaultOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest making this in ALL_CAPS

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, looks better.

}

/**
* Not used because to register metrics it's necessary some information only
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: to register metrics it's necessary some information -> registering metrics requires information that is

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok

Copy link
Contributor

@kjin kjin left a comment

Choose a reason for hiding this comment

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

LGTM w/ nit.

@kjin kjin merged commit 097d1de into census-instrumentation:master Aug 29, 2018
@kjin kjin mentioned this pull request Sep 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants