-
Notifications
You must be signed in to change notification settings - Fork 202
Stats/Stackdriver: export data using metrics API #1501
Stats/Stackdriver: export data using metrics API #1501
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1501 +/- ##
============================================
- Coverage 82.6% 82.29% -0.31%
+ Complexity 1648 1628 -20
============================================
Files 251 247 -4
Lines 7782 7576 -206
Branches 743 728 -15
============================================
- Hits 6428 6235 -193
+ Misses 1129 1117 -12
+ Partials 225 224 -1
Continue to review full report at Codecov.
|
buildscripts/import-control.xml
Outdated
@@ -148,6 +148,7 @@ General guidelines on imports: | |||
<subpackage name="stats"> | |||
<allow pkg="io.opencensus.stats"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are stats
and tags
still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are still needed for other two exporters (prometheus and signalFx), I will remove that once we update these exporters to use Metrics API.
static List<TimeSeries> createTimeSeriesList( | ||
@javax.annotation.Nullable ViewData viewData, | ||
@javax.annotation.Nullable io.opencensus.metrics.export.Metric metric, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @Nullable
annotation is no longer needed.
return value.match( | ||
typedValueDoubleFunction, | ||
typedValueLongFunction, | ||
new Function<io.opencensus.metrics.export.Distribution, TypedValue>() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can make this function static too.
...ackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java
Show resolved
Hide resolved
...ackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java
Show resolved
Hide resolved
...driver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java
Outdated
Show resolved
Hide resolved
if (existing != null) { | ||
if (existing.equals(view)) { | ||
// Ignore views that are already registered. | ||
boolean registerMetric(Metric metric) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, this should be called registerMetricDescriptor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
if (registerView(view)) { | ||
// Only upload stats for valid views. | ||
viewDataList.add(viewManager.getView(view.getName())); | ||
List</*@Nullable*/ Metric> metricsList = Lists.newArrayList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nullable
annotation is no longer needed here, since I don't think metricProducer.getMetrics()
would return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
} | ||
|
||
List<TimeSeries> timeSeriesList = Lists.newArrayList(); | ||
for (/*@Nullable*/ ViewData viewData : viewDataList) { | ||
for (/*@Nullable*/ Metric metric : metricsList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
...river/src/test/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtilsTest.java
Outdated
Show resolved
Hide resolved
@@ -315,6 +314,7 @@ static Distribution createDistribution(io.opencensus.metrics.export.Distribution | |||
.setBucketOptions(createBucketOptions(distribution.getBucketOptions())) | |||
.addAllBucketCounts(createBucketCounts(distribution.getBuckets())) | |||
.setCount(distribution.getCount()) | |||
.setMean(distribution.getSum() / distribution.getCount()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check for divided-by-0 here.
for (int i = 0; i < tagValues.size(); i++) { | ||
TagKey key = columns.get(i); | ||
TagValue value = tagValues.get(i); | ||
labelKeys.size() == labelValues.size(), "LabelKeys and LabelValues don't have same size."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see ambiguity here, if someone using the stats API will get confused by seeing this message. Can we say "TagKeys/LabelKeys and TagValues/LabelValues don't have same size." @bogdandrutu @songy23
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's less confusing to just call them "key" and "value"? i.e "Keys and Values don't have same size."
...driver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java
Show resolved
Hide resolved
View.create(VIEW_NAME, VIEW_DESCRIPTION, MEASURE, SUM, Arrays.asList(KEY), CUMULATIVE); | ||
doReturn(ImmutableSet.of(view)).when(mockViewManager).getAllExportedViews(); | ||
public void doNotExportIfFailedToRegisterMetric() { | ||
doReturn(ImmutableSet.of(metricProducer)).when(metricProducerManager).getAllMetricProducer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This line can be extracted to
@Before
public void setUp() {
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
...driver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java
Show resolved
Hide resolved
...driver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExporterWorker.java
Show resolved
Hide resolved
|
||
MetricDescriptor.Builder builder = MetricDescriptor.newBuilder(); | ||
String viewName = view.getName().asString(); | ||
String type = generateType(viewName, domain); | ||
String type = generateType(metricDescriptor.getName(), domain); | ||
// Name format refers to | ||
// cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create | ||
builder.setName(String.format("projects/%s/metricDescriptors/%s", projectId, type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that you did not write this but is probably faster to do string concatenation.
...ackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java
Show resolved
Hide resolved
...ackdriver/src/main/java/io/opencensus/exporter/stats/stackdriver/StackdriverExportUtils.java
Show resolved
Hide resolved
TagValue value = tagValues.get(i); | ||
List<LabelKey> labelKeys = metricDescriptor.getLabelKeys(); | ||
|
||
checkArgument(labelKeys.size() == labelValues.size(), "Keys and Values don't have same size."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already check for this when we create the Metric so I think this is useless.
Dependency on #1499
This PR is part of #1483