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

fix: cloud monitoring incompatibility with opentelemetry/metrics 0.9.0 #110

Conversation

reggiemcdonald
Copy link
Contributor

This PR upgrades the cloud monitoring exporter's dependency on @opentelemetry/metrics to the latest release (0.9.0).

Changes

The biggest change to @opentelemetry/metrics was the removal of labelKeys from MetricOptions. In response, labels are now added to GCP metrics using the metric instead of the metric descriptor as per the GCP Docs

Functions were adjusted to handle the additional MetricKinds that were added

Testing

Added some additional unit tests; all tests pass.
Tested metric export on a GCE VM running the latest version of node.

Fixes #102

@codecov
Copy link

codecov bot commented Jul 6, 2020

Codecov Report

Merging #110 into master will increase coverage by 1.19%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #110      +/-   ##
==========================================
+ Coverage   92.69%   93.88%   +1.19%     
==========================================
  Files          10       10              
  Lines         260      278      +18     
  Branches       43       52       +9     
==========================================
+ Hits          241      261      +20     
+ Misses         19       17       -2     
Impacted Files Coverage Δ
...emetry-cloud-monitoring-exporter/src/monitoring.ts 87.05% <100.00%> (+1.16%) ⬆️
...lemetry-cloud-monitoring-exporter/src/transform.ts 97.10% <100.00%> (+3.99%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3ecb2e2...36250fb. Read the comment docs.

@@ -117,11 +117,21 @@ export class MetricExporter implements IMetricExporter {
}
}

let sendFailed: Error | undefined;
Copy link

Choose a reason for hiding this comment

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

Could this just be a boolean? I think that might be more readable.

E.g.

let sendFailed = false;
...
catch (err) {
  sendFailed = true;
}

Comment on lines 128 to 130
err.message = `Send TimeSeries failed: ${err.message}`;
sendFailed = err;
this._logger.error(err.message);
Copy link

Choose a reason for hiding this comment

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

I think it might be more readable and less confusing behavior to create a new variable with the modified message to be logged rather than mutating the original error. I think modifying the caught error wouldn't do much unless it is re-thrown. Not a big deal either way, though.

assert(!result.interval.startTime);
});

it('should throw an error when given a distriution value', () => {
Copy link

Choose a reason for hiding this comment

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

typo: distriution -> distribution

Comment on lines +170 to +177
if (isDistributionValue(value)) {
// TODO: Add support for Distribution
throw new Error('Distributions are not yet supported');
}
if (isHistogramValue(value)) {
// TODO: Add support for Histogram
throw new Error('Histograms are not yet supported');
}
Copy link

Choose a reason for hiding this comment

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

This is inconsistent with the existing code, which uses the valueType rather than the value to distinguish the behavior. I think there are pros and cons to each; using the valueType isn't as type safe as using the value, but it is simpler. I would recommend using valueType for now and perhaps revisiting when distributions/histograms are implemented. Does that make sense to you? Having explicit cases for each with TODOs and specific errors still looks good to me.

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 agree that it would be a better solution to just switch on valueType if valueType could be either int, double, histogram, or distribution. From what I understand however, valueType can only ever be int or double (see link to code). I believe that switching solely on valueType would cause unexpected behaviour when value is a Distribution or Histogram. For example when valueType is INT and value is a Distribution, the output of the function would have the following structure:

{
  int64Value: {
    min: <int>,
    max: <int>,
    count: <int>,
    sum: <int>,
  }
}

which I suspect will cause a problem when the payload gets sent to the timeseries.create api.

Its also possible that I'm misunderstanding how valuetypes and values relate to one another.

Copy link

Choose a reason for hiding this comment

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

I see, I misunderstood how that works. I was having trouble locating the ValueType enum, so thanks for sending that.

So I think what you have here is good. What I would suggest is making a user-defined type guard for the functions checking the types. E.g.:

function isDistributionValue(value: number | OTDistribution | OTHistogram): value is OTDistribution {
  return value.hasOwnProperty('min');
}

Then I think you could safely remove the as number type casts in 180 and 182 since it would be narrowed down to number.

That would also help later working with those distribution and histogram types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea! Will do

@reggiemcdonald
Copy link
Contributor Author

@danherr

Copy link
Contributor

@mayurkale22 mayurkale22 left a comment

Choose a reason for hiding this comment

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

LGTM

@mayurkale22 mayurkale22 merged commit 64acf6f into GoogleCloudPlatform:master Jul 9, 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.

cloud monitoring exporter is not compatible with the latest release of @opentelemetry/metrics
3 participants