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

Commit

Permalink
Metrics: Fix DistributionValue buckets properties (#258)
Browse files Browse the repository at this point in the history
* Fix DistributionValue buckets

* Make exemplar optional

As per metrics.proto, we omit exemplar field when the distribution does not have a histogram.
  • Loading branch information
mayurkale22 authored Jan 2, 2019
1 parent 52c304e commit 07e94f7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/opencensus-core/src/metrics/export/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export interface Bucket {
/**
* If the distribution does not have a histogram, then omit this field.
*/
readonly exemplar: Exemplar;
readonly exemplar?: Exemplar;
}

/**
Expand Down
10 changes: 6 additions & 4 deletions packages/opencensus-core/src/stats/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as defaultLogger from '../common/console-logger';
import * as loggerTypes from '../common/types';
import {LabelValue, Metric, MetricDescriptor, MetricDescriptorType, Point, TimeSeries, Timestamp} from '../metrics/export/types';
import {DistributionValue, LabelValue, Metric, MetricDescriptor, MetricDescriptorType, Point, TimeSeries, Timestamp} from '../metrics/export/types';

import {BucketBoundaries} from './bucket-boundaries';
import {MetricUtils} from './metric-utils';
Expand Down Expand Up @@ -254,10 +254,12 @@ export class BaseView implements View {
sum,
sumOfSquaredDeviation,
bucketOptions: {explicit: {bounds: data.buckets}},
buckets: data.bucketCounts
};
// Bucket without an Exemplar.
buckets:
data.bucketCounts.map(bucketCount => ({count: bucketCount}))
} as DistributionValue;
} else {
value = data.value;
value = data.value as number;
}
return {timestamp, value};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/opencensus-core/test/test-metric-producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('Metric producer for stats', () => {
points: [{
value: {
'bucketOptions': {'explicit': {'bounds': [2, 4, 6]}},
'buckets': [1, 2, 2, 0],
'buckets': [{count: 1}, {count: 2}, {count: 2}, {count: 0}],
'count': 5,
'sum': 16.099999999999998,
'sumOfSquaredDeviation': 10.427999999999997
Expand Down
6 changes: 3 additions & 3 deletions packages/opencensus-core/test/test-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('BaseView', () => {
assert.notEqual(typeof value, 'number');
assert.deepStrictEqual((value as DistributionValue), {
bucketOptions: {explicit: {bounds: buckets}},
buckets: [1, 2, 2, 0],
buckets: [{count: 1}, {count: 2}, {count: 2}, {count: 0}],
count: 5,
sum: total,
sumOfSquaredDeviation: 10.427999999999997
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('BaseView', () => {
assert.notEqual(typeof value, 'number');
assert.deepStrictEqual((value as DistributionValue), {
bucketOptions: {explicit: {bounds: buckets}},
buckets: [1, 2, 2, 0],
buckets: [{count: 1}, {count: 2}, {count: 2}, {count: 0}],
count: 5,
sum: total,
sumOfSquaredDeviation: 10.427999999999997
Expand All @@ -353,7 +353,7 @@ describe('BaseView', () => {
assert.notEqual(typeof value, 'number');
assert.deepStrictEqual((value as DistributionValue), {
bucketOptions: {explicit: {bounds: buckets}},
buckets: [1, 2, 2, 0],
buckets: [{count: 1}, {count: 2}, {count: 2}, {count: 0}],
count: 5,
sum: total,
sumOfSquaredDeviation: 10.427999999999997
Expand Down

0 comments on commit 07e94f7

Please sign in to comment.