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

Stats/Stackdriver: export data using metrics API #1501

Merged
merged 3 commits into from
Oct 25, 2018
Merged

Stats/Stackdriver: export data using metrics API #1501

merged 3 commits into from
Oct 25, 2018

Conversation

mayurkale22
Copy link
Member

@mayurkale22 mayurkale22 commented Oct 17, 2018

Dependency on #1499

This PR is part of #1483

@codecov-io
Copy link

codecov-io commented Oct 17, 2018

Codecov Report

Merging #1501 into master will decrease coverage by 0.3%.
The diff coverage is 94.73%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...er/stats/stackdriver/StackdriverStatsExporter.java 65.27% <100%> (ø) 11 <0> (ø) ⬇️
...r/stats/stackdriver/StackdriverExporterWorker.java 72.26% <94.11%> (+0.23%) 19 <9> (ø) ⬇️
...rter/stats/stackdriver/StackdriverExportUtils.java 78.23% <94.8%> (-4.78%) 37 <20> (+6)
...pencensus/implcore/metrics/MetricRegistryImpl.java 92.1% <0%> (-6.26%) 3% <0%> (-3%)
.../io/opencensus/implcore/metrics/LongGaugeImpl.java 93.33% <0%> (-0.22%) 15% <0%> (ø)
...o/opencensus/implcore/metrics/DoubleGaugeImpl.java 93.33% <0%> (-0.22%) 15% <0%> (ø)
.../java/io/opencensus/metrics/export/TimeSeries.java 100% <0%> (ø) 4% <0%> (ø) ⬇️
...io/opencensus/metrics/export/MetricDescriptor.java 100% <0%> (ø) 2% <0%> (ø) ⬇️
...ain/java/io/opencensus/metrics/MetricRegistry.java 100% <0%> (ø) 2% <0%> (ø) ⬇️
...src/main/java/io/opencensus/metrics/LongGauge.java 72.22% <0%> (ø) 2% <0%> (ø) ⬇️
... and 6 more

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 9c9c152...998d053. Read the comment docs.

@@ -148,6 +148,7 @@ General guidelines on imports:
<subpackage name="stats">
<allow pkg="io.opencensus.stats"/>
Copy link
Contributor

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?

Copy link
Member Author

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,
Copy link
Contributor

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>() {
Copy link
Contributor

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.

if (existing != null) {
if (existing.equals(view)) {
// Ignore views that are already registered.
boolean registerMetric(Metric metric) {
Copy link
Contributor

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.

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.

if (registerView(view)) {
// Only upload stats for valid views.
viewDataList.add(viewManager.getView(view.getName()));
List</*@Nullable*/ Metric> metricsList = Lists.newArrayList();
Copy link
Contributor

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.

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

}
}

List<TimeSeries> timeSeriesList = Lists.newArrayList();
for (/*@Nullable*/ ViewData viewData : viewDataList) {
for (/*@Nullable*/ Metric metric : metricsList) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

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

@@ -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())
Copy link
Contributor

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.");
Copy link
Member Author

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

Copy link
Contributor

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."

@mayurkale22
Copy link
Member Author

Comparison after and before change on same data set. Left side OC16 (SD using Stats API), Right side OC17(SD using Metrics API).

screen shot 2018-10-19 at 11 37 44 am

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();
Copy link
Contributor

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() {
  ...
}

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


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));
Copy link
Contributor

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.

TagValue value = tagValues.get(i);
List<LabelKey> labelKeys = metricDescriptor.getLabelKeys();

checkArgument(labelKeys.size() == labelValues.size(), "Keys and Values don't have same size.");
Copy link
Contributor

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.

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.

5 participants