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

Commit 88aa832

Browse files
eduardoemerykjin
authored andcommitted
refactor: change design to better fit opencensus' sepecs
1 parent a912905 commit 88aa832

24 files changed

+518
-2360
lines changed

packages/opencensus-core/src/exporters/console-exporter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import * as loggerTypes from '../common/types';
18-
import {Measure, Measurement, View} from '../stats/model/types';
18+
import {Measure, Measurement, View} from '../stats/types';
1919
import * as modelTypes from '../trace/model/types';
2020

2121
import {ExporterBuffer} from './exporter-buffer';
@@ -77,7 +77,7 @@ export class ConsoleExporter implements types.Exporter {
7777
}
7878

7979
/** Exporter that receives stats data and shows in the log console. */
80-
export class ConsoleStatsExporter implements types.StatsExporter {
80+
export class ConsoleStatsExporter implements types.StatsEventListener {
8181
/**
8282
* Event called when a view is registered
8383
* @param view registered view
@@ -92,7 +92,7 @@ export class ConsoleStatsExporter implements types.StatsExporter {
9292
* @param view recorded view from measurement
9393
* @param measurement recorded measurement
9494
*/
95-
onRecord(view: View) {
95+
onRecord(view: View, measurement: Measurement) {
9696
console.log(`Measurement recorded: ${view.measure.name}`);
9797
}
9898
}

packages/opencensus-core/src/exporters/types.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
18-
import {Measure, Measurement, View, ViewEventListener} from '../stats/model/types';
17+
import {Measurement, View} from '../stats/types';
1918
import * as configTypes from '../trace/config/types';
2019
import * as modelTypes from '../trace/model/types';
2120

@@ -28,7 +27,10 @@ export interface Exporter extends modelTypes.SpanEventListener {
2827
publish(rootSpans: modelTypes.RootSpan[]): Promise<number|string|void>;
2928
}
3029

31-
/** Define a StatsExporter interface */
32-
export interface StatsExporter extends ViewEventListener {}
30+
/** Defines a StatsEventListener interface */
31+
export interface StatsEventListener {
32+
onRegisterView(view: View): void;
33+
onRecord(view: View, measurement: Measurement): void;
34+
}
3335

3436
export type ExporterConfig = configTypes.BufferConfig;

packages/opencensus-core/src/index.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@ export * from './exporters/console-exporter';
4242

4343
// STATS CLASSES
4444

45-
// domain models impls
46-
export * from './stats/model/metrics/counter';
47-
export * from './stats/model/metrics/gauge';
48-
export * from './stats/model/metrics/histogram';
49-
export * from './stats/model/metrics/metric';
50-
export * from './stats/model/measure';
51-
export * from './stats/model/view';
45+
// classes
5246
export * from './stats/stats';
47+
export * from './stats/view';
48+
export * from './stats/aggregation/count-aggregation';
49+
export * from './stats/aggregation/sum-aggregation';
50+
export * from './stats/aggregation/last-value-aggregation';
51+
export * from './stats/aggregation/distribution-aggregation';
5352

5453
// interfaces
55-
export * from './stats/model/metrics/types';
56-
export * from './stats/model/types';
54+
export * from './stats/aggregation/types';
55+
export * from './stats/types';
5756

5857
// logger
5958
import * as logger from './common/console-logger';
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {Measurement, Tags} from '../types';
18+
19+
import {AggregationType, CountData} from './types';
20+
21+
export class CountAggregation implements CountData {
22+
/** The aggregation type of the aggregation data */
23+
readonly type: AggregationType;
24+
/** The tags/labels that this AggregationData collects and aggregates */
25+
readonly tags: Tags;
26+
/** The latest timestamp a new data point was recorded */
27+
readonly timestamp: number;
28+
/** The current counted value */
29+
readonly value: number;
30+
31+
constructor() {}
32+
33+
addMeasurement(measurement: Measurement): void {
34+
// TODO: To be implemented
35+
}
36+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {Measurement, Tags} from '../types';
18+
19+
import {AggregationType, Bucket, DistributionData} from './types';
20+
21+
export class DistributionAggregation implements DistributionData {
22+
/** The aggregation type of the aggregation data */
23+
readonly type: AggregationType;
24+
/** The tags/labels that this AggregationData collects and aggregates */
25+
readonly tags: Tags;
26+
/** The latest timestamp a new data point was recorded */
27+
timestamp: number;
28+
/** The first timestamp a datapoint was added */
29+
readonly startTime: number;
30+
/** Get the total count of all recorded values in the histogram */
31+
count: number;
32+
/** Sum of all recorded values in the histogram */
33+
sum: number;
34+
/** Max value recorded in the histogram */
35+
max: number;
36+
/** Min value recorded in the histogram */
37+
min: number;
38+
/** Get the computed mean value of all recorded values in the histogram */
39+
mean: number;
40+
/**
41+
* Get the computed standard deviation of all recorded values in the
42+
* histogram
43+
*/
44+
stdDeviation: number;
45+
/**
46+
* Get the computed sum of squared deviations of all recorded values in the
47+
* histogram.
48+
*/
49+
sumSquaredDeviations: number;
50+
/** Bucket distribution of the histogram */
51+
buckets: Bucket[];
52+
/** The bucket boundaries for a histogram */
53+
readonly bucketsBoundaries: number[];
54+
55+
constructor() {}
56+
57+
addMeasurement(measurement: Measurement): void {
58+
// TODO: To be implemented
59+
}
60+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {Measurement, Tags} from '../types';
18+
19+
import {AggregationType, LastValueData} from './types';
20+
21+
export class LastValueAggregation implements LastValueData {
22+
/** The aggregation type of the aggregation data */
23+
readonly type: AggregationType;
24+
/** The tags/labels that this AggregationData collects and aggregates */
25+
readonly tags: Tags;
26+
/** The latest timestamp a new data point was recorded */
27+
timestamp: number;
28+
/** The last recorded value */
29+
value: number;
30+
31+
constructor() {}
32+
33+
addMeasurement(measurement: Measurement): void {
34+
// TODO: To be implemented
35+
}
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {Measurement, Tags} from '../types';
18+
19+
import {AggregationType, SumData} from './types';
20+
21+
export class SumAggregation implements SumData {
22+
/** The aggregation type of the aggregation data */
23+
readonly type: AggregationType;
24+
/** The tags/labels that this AggregationData collects and aggregates */
25+
readonly tags: Tags;
26+
/** The latest timestamp a new data point was recorded */
27+
timestamp: number;
28+
/** The current accumulated value */
29+
value: number;
30+
31+
constructor() {}
32+
33+
addMeasurement(measurement: Measurement): void {
34+
// TODO: To be implemented
35+
}
36+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Copyright 2018, OpenCensus Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import {Measurement, Tags} from '../types';
18+
19+
/**
20+
* Informs the type of the aggregation. It can be: count, sum, lastValue or
21+
* distribution.
22+
*/
23+
export const enum AggregationType {
24+
count = 0,
25+
sum = 1,
26+
lastValue = 2,
27+
distribution = 3
28+
}
29+
30+
/** Defines how data is collected and aggregated */
31+
export interface AggregationData {
32+
/** The aggregation type of the aggregation data */
33+
readonly type: AggregationType;
34+
/** The tags/labels that this AggregationData collects and aggregates */
35+
readonly tags: Tags;
36+
/** The latest timestamp a new data point was recorded */
37+
timestamp: number;
38+
/**
39+
* Adds a new data point to the aggregation.
40+
* @param measurement The new data point to aggregate
41+
*/
42+
addMeasurement(measurement: Measurement): void;
43+
}
44+
45+
/**
46+
* Data collected and aggregated with this AggregationData will be summed up.
47+
*/
48+
export interface SumData extends AggregationData {
49+
/** The current accumulated value */
50+
value: number;
51+
}
52+
53+
/**
54+
* This AggregationData counts the number of measurements recorded.
55+
*/
56+
export interface CountData extends AggregationData {
57+
/** The current counted value */
58+
value: number;
59+
}
60+
61+
/**
62+
* This AggregationData represents the last recorded value. This is useful when
63+
* giving support to Gauges.
64+
*/
65+
export interface LastValueData extends AggregationData {
66+
/** The last recorded value */
67+
value: number;
68+
}
69+
70+
/** This AggregationData contains a histogram of the collected values. */
71+
export interface DistributionData extends AggregationData {
72+
/** The first timestamp a datapoint was added */
73+
readonly startTime: number;
74+
/** Get the total count of all recorded values in the histogram */
75+
count: number;
76+
/** Sum of all recorded values in the histogram */
77+
sum: number;
78+
/** Max value recorded in the histogram */
79+
max: number;
80+
/** Min value recorded in the histogram */
81+
min: number;
82+
/** Get the computed mean value of all recorded values in the histogram */
83+
mean: number;
84+
/**
85+
* Get the computed standard deviation of all recorded values in the
86+
* histogram
87+
*/
88+
stdDeviation: number;
89+
/**
90+
* Get the computed sum of squared deviations of all recorded values in the
91+
* histogram.
92+
*/
93+
sumSquaredDeviations: number;
94+
/** Bucket distribution of the histogram */
95+
buckets: Bucket[];
96+
/** The bucket boundaries for a histogram */
97+
readonly bucketsBoundaries: number[];
98+
}
99+
100+
/** A simple histogram bucket interface. */
101+
export interface Bucket {
102+
/** Number of occurrences in the domain */
103+
count: number;
104+
/** The maximum bucket limit in domain */
105+
readonly max: number;
106+
/** The minimum bucket limit in domain */
107+
readonly min: number;
108+
}

0 commit comments

Comments
 (0)