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

Stats/Stackdriver: export data using metrics API #275

Conversation

mayurkale22
Copy link
Member

This PR is part of #257

The majority of work has been handled/covered in StackdriverStatsExporterUtils #266, this PR is based on that work to export data to backend.

@codecov-io
Copy link

codecov-io commented Jan 11, 2019

Codecov Report

Merging #275 into master will decrease coverage by 0.23%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #275      +/-   ##
==========================================
- Coverage   94.81%   94.58%   -0.24%     
==========================================
  Files         110      110              
  Lines        7771     7421     -350     
  Branches      713      679      -34     
==========================================
- Hits         7368     7019     -349     
+ Misses        403      402       -1
Impacted Files Coverage Δ
src/stackdriver-monitoring.ts 80.21% <0%> (-12.64%) ⬇️
test/test-stackdriver-monitoring.ts 95.23% <0%> (-2.13%) ⬇️
src/stats/stats.ts 97.95% <0%> (+0.04%) ⬆️
test/test-stats.ts 100% <0%> (+0.97%) ⬆️
src/prometheus-stats.ts 94.25% <0%> (+1.14%) ⬆️
src/zpages.ts 92.85% <0%> (+1.42%) ⬆️

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 ef3486a...2ed8acc. Read the comment docs.

const resourceLabels = {project_id: this.projectId};
const monitoredResource = {type: 'global', labels: resourceLabels};

metricsList.map(metric => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the value is not being used here, could you do a for (const .. of ..) loop instead of a .map call?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

metricsList.map(metric => {
const timeSeriesList =
createTimeSeriesList(metric, monitoredResource, this.metricPrefix);
timeSeriesList.forEach(ts => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than using forEach and push, could you use map here? And would that allow you to make the initial assignment of timeSeries above be the result of the map?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

{[key: string]: {view: View; tags: {[key: string]: Tags;}}};
private displayNamePrefix: string;
// tslint:disable:no-any
private onMetricUploadError: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like a possible value of this is a function. Could you make the type something like (err: Error) => void|{}, which would allow it to either a function that takes an error, or just any arbitrary object? That way there is some amount of documentation about what role it plays.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, done.

for (const metricProducer of metricProducerManager.getAllMetricProducer()) {
for (const metric of metricProducer.getMetrics()) {
const isRegistered =
await this.registerMetricDescriptor(metric.descriptor);
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 worth running these registerMetricDescriptor calls in parallel? Not sure how useful it would be but they don't seem dependent on each other in this loop.

It seems like if you ran them all in parallel with something like Promise.all then you could aggregate their results together into the metricsList list once they all complete.

Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is to register each metricDescriptor once (and ignore metricDescriptor that are already registered). If we run registerMetricDescriptor in parallel, there are chances will make more external calls than usual. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. I suppose registering metric descriptors may not happen that often, so it's probably OK to leave as is. Maybe just something we can think of if anybody has a performance issue with it that we could try to compress it to a Set and run in parallel, but I like leaving it alone for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is certainly a good point, I have added TODO comment for now to track this in future.

@mayurkale22
Copy link
Member Author

I will merge this PR later today, if no other comments.

@mayurkale22 mayurkale22 merged commit 3b76356 into census-instrumentation:master Jan 15, 2019
@mayurkale22 mayurkale22 deleted the rewrite_stackdriver_exporter branch January 15, 2019 01:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants