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

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
Fix typos (THe -> The).
Use const and a ternary expression instead of let.
Remove unwanted template backticks.
Add separate function to create/get metric Bucket (getMetricBucket).
  • Loading branch information
mayurkale22 committed Mar 8, 2019
1 parent 945fb03 commit e018a4c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/opencensus-core/src/stats/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export interface Stats {
* tags could either be explicitly passed to the method, or implicitly
* read from current execution context.
* @param attachments optional The contextual information associated with an
* example value. THe contextual information is represented as key - value
* example value. The contextual information is represented as key - value
* string pairs.
*/
record(
Expand Down
45 changes: 22 additions & 23 deletions packages/opencensus-core/src/stats/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {isValidTagKey} from '../tags/validation';
import {BucketBoundaries} from './bucket-boundaries';
import {MetricUtils} from './metric-utils';
import {Recorder} from './recorder';
import {AggregationData, AggregationType, Measure, Measurement, View} from './types';
import {AggregationData, AggregationType, Measure, Measurement, StatsExemplar, View} from './types';

const RECORD_SEPARATOR = String.fromCharCode(30);

Expand Down Expand Up @@ -116,7 +116,7 @@ export class BaseView implements View {
* @param measurement The measurement to record
* @param tags The tags to which the value is applied
* @param attachments optional The contextual information associated with an
* example value. THe contextual information is represented as key - value
* example value. The contextual information is represented as key - value
* string pairs.
*/
recordMeasurement(
Expand Down Expand Up @@ -235,27 +235,8 @@ export class BaseView implements View {
const buckets = [];
for (let bucket = 0; bucket < data.bucketCounts.length; bucket++) {
const bucketCount = data.bucketCounts[bucket];
let statsExemplar;
if (exemplars) {
statsExemplar = exemplars[bucket];
}

let metricBucket;
if (statsExemplar) {
// Bucket with an Exemplar.
metricBucket = {
count: bucketCount,
exemplar: {
value: statsExemplar.value,
timestamp: timestampFromMillis(statsExemplar.timestamp),
attachments: statsExemplar.attachments
}
} as metricBucket;
} else {
// Bucket with no Exemplar.
metricBucket = {count: bucketCount};
}
buckets.push(metricBucket);
const statsExemplar = exemplars ? exemplars[bucket] : undefined;
buckets.push(this.getMetricBucket(statsExemplar, bucketCount));
}

value = {
Expand All @@ -280,6 +261,24 @@ export class BaseView implements View {
return this.tagValueAggregationMap[this.encodeTagValues(tagValues)];
}

/** Returns a Bucket with count and examplar (if present) */
private getMetricBucket(statsExemplar: StatsExemplar, bucketCount: number):
metricBucket {
if (statsExemplar) {
// Bucket with an Exemplar.
return {
count: bucketCount,
exemplar: {
value: statsExemplar.value,
timestamp: timestampFromMillis(statsExemplar.timestamp),
attachments: statsExemplar.attachments
}
};
}
// Bucket with no Exemplar.
return {count: bucketCount};
}

/** Determines whether the given TagKeys are valid. */
private validateTagKeys(tagKeys: TagKey[]): TagKey[] {
const tagKeysCopy = Object.assign([], tagKeys);
Expand Down
4 changes: 2 additions & 2 deletions packages/opencensus-core/test/test-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ describe('Recorder', () => {
}
});

describe(`for distribution aggregation data with attachments`, () => {
describe('for distribution aggregation data with attachments', () => {
const attachments = {'k1': 'v1', 'k2': 'v2', 'k3': 'v3'};
it(`should record measurements and attachments correctly`, () => {
it('should record measurements and attachments correctly', () => {
const distributionData: DistributionData = {
type: AggregationType.DISTRIBUTION,
tagValues,
Expand Down

0 comments on commit e018a4c

Please sign in to comment.