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

Commit ba04ff7

Browse files
authored
Adds interfaces for [Metrics api] (#188)
1 parent 272efd1 commit ba04ff7

1 file changed

Lines changed: 332 additions & 0 deletions

File tree

  • packages/opencensus-core/src/metrics/export
Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
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+
18+
/** Properties of a Metric which has one or more timeseries */
19+
export interface Metric {
20+
/**
21+
* The descriptor of the Metric. This is an optimization for network wire
22+
* size, from data-model perspective a Metric contains always
23+
* a MetricDescriptor.
24+
* In case of a streaming RPC can be sent only
25+
* the first time a metric is reported to save network traffic.
26+
*/
27+
readonly descriptor: MetricDescriptor;
28+
/**
29+
* One or more timeseries for a single metric, where each timeseries has
30+
* one or more points.
31+
*/
32+
readonly timeseries: TimeSeries[];
33+
}
34+
35+
/** Properties of a Metric type and its schema */
36+
export interface MetricDescriptor {
37+
/** The metric type, including its DNS name prefix. It must be unique. */
38+
readonly name: string;
39+
/**
40+
* A detailed description of the metric, which can be used in documentation.
41+
*/
42+
readonly description: string;
43+
/**
44+
* The unit in which the metric value is reported. Follows the format
45+
* described by http://unitsofmeasure.org/ucum.html.
46+
*/
47+
readonly unit: string;
48+
/** MetricDescriptor type */
49+
readonly type: MetricDescriptorType;
50+
/** The label keys associated with the metric descriptor. */
51+
readonly labelKeys: LabelKey[];
52+
}
53+
54+
/**
55+
* The kind of metric. It describes how the data is reported.
56+
*
57+
* A gauge is an instantaneous measurement of a value.
58+
*
59+
* A cumulative measurement is a value accumulated over a time interval. In
60+
* a time series, cumulative measurements should have the same start time,
61+
* increasing values and increasing end times, until an event resets the
62+
* cumulative value to zero and sets a new start time for the following
63+
* points.
64+
*/
65+
export enum MetricDescriptorType {
66+
/** Do not use this default value. */
67+
UNSPECIFIED,
68+
/** Integer gauge. The value can go both up and down. */
69+
GAUGE_INT64,
70+
/** Floating point gauge. The value can go both up and down. */
71+
GAUGE_DOUBLE,
72+
/**
73+
* Distribution gauge measurement. The count and sum can go both up and
74+
* down. Recorded values are always >= 0.
75+
* Used in scenarios like a snapshot of time the current items in a queue
76+
* have spent there.
77+
*/
78+
GAUGE_DISTRIBUTION,
79+
/**
80+
* Integer cumulative measurement. The value cannot decrease, if resets
81+
* then the start_time should also be reset.
82+
*/
83+
CUMULATIVE_INT64,
84+
/**
85+
* Floating point cumulative measurement. The value cannot decrease, if
86+
* resets then the start_time should also be reset. Recorded values are
87+
* always >= 0.
88+
*/
89+
CUMULATIVE_DOUBLE,
90+
/**
91+
* Distribution cumulative measurement. The count and sum cannot decrease,
92+
* if resets then the start_time should also be reset.
93+
*/
94+
CUMULATIVE_DISTRIBUTION,
95+
/**
96+
* Some frameworks implemented Histograms as a summary of observations
97+
* (usually things like request durations and response sizes). While it
98+
* also provides a total count of observations and a sum of all observed
99+
* values, it calculates configurable percentiles over a sliding time
100+
* window. This is not recommended, since it cannot be aggregated.
101+
*/
102+
SUMMARY
103+
}
104+
105+
/** Properties of a LabelKey associated with a MetricDescriptor. */
106+
export interface LabelKey {
107+
/** The key for the label. */
108+
readonly key: string;
109+
/** A human-readable description of what this label key represents. */
110+
readonly description: string;
111+
}
112+
113+
/**
114+
* A collection of data points that describes the time-varying values
115+
* of a metric.
116+
*/
117+
export interface TimeSeries {
118+
/**
119+
* Must be present for cumulative metrics. The time when the cumulative value
120+
* was reset to zero. Exclusive. The cumulative value is over the time
121+
* interval (start_timestamp, timestamp]. If not specified, the backend can
122+
* use the previous recorded value.
123+
*/
124+
readonly startTimestamp: Timestamp;
125+
/**
126+
* The set of label values that uniquely identify this timeseries. Applies to
127+
* all points. The order of label values must match that of label keys in the
128+
* metric descriptor.
129+
*/
130+
readonly labelValues: LabelValue[];
131+
/**
132+
* The data points of this timeseries. Point.value type MUST match the
133+
* MetricDescriptor.type.
134+
*/
135+
readonly points: Point[];
136+
}
137+
138+
/** Properties of a LabelValue. */
139+
export interface LabelValue {
140+
/** The value for the label */
141+
readonly value: string;
142+
/**
143+
* If false the value field is ignored and considered not set.
144+
* This is used to differentiate a missing label from an empty string.
145+
*/
146+
readonly hasValue: boolean;
147+
}
148+
149+
/** A timestamped measurement. */
150+
export interface Point {
151+
/**
152+
* The moment when this point was recorded. Inclusive.
153+
* If not specified, the timestamp will be decided by the backend.
154+
*/
155+
readonly timestamp: Timestamp;
156+
/**
157+
* The actual point value.
158+
* 64-bit integer or 64-bit double-precision floating-point number
159+
* or distribution value
160+
* or summary value. This is not recommended, since it cannot be aggregated.
161+
*/
162+
readonly value: number|DistributionValue|SummaryValue;
163+
}
164+
165+
/**
166+
* Distribution contains summary statistics for a population of values. It
167+
* optionally contains a histogram representing the distribution of those
168+
* values across a set of buckets.
169+
*/
170+
export interface DistributionValue {
171+
/**
172+
* The number of values in the population. Must be non-negative. This value
173+
* must equal the sum of the values in bucket_counts if a histogram is
174+
* provided.
175+
*/
176+
readonly count: number;
177+
/**
178+
* The sum of the values in the population. If count is zero then this field
179+
* must be zero.
180+
*/
181+
readonly sum: number;
182+
/**
183+
* The sum of squared deviations from the mean of the values in the
184+
* population. For values x_i this is:
185+
*
186+
* Sum[i=1..n]((x_i - mean)^2)
187+
*
188+
* Knuth, "The Art of Computer Programming", Vol. 2, page 323, 3rd edition
189+
* describes Welford's method for accumulating this sum in one pass.
190+
*
191+
* If count is zero then this field must be zero.
192+
*/
193+
readonly sumOfSquaredDeviation: number;
194+
/**
195+
* Don't change bucket boundaries within a TimeSeries if your backend doesn't
196+
* support this. To save network bandwidth this field can be sent only the
197+
* first time a metric is sent when using a streaming RPC.
198+
*/
199+
readonly bucketOptions: BucketOptions;
200+
/** DistributionValue buckets */
201+
readonly buckets: Bucket[];
202+
}
203+
204+
/**
205+
* Properties of a BucketOptions.
206+
* A Distribution may optionally contain a histogram of the values in the
207+
* population. The bucket boundaries for that histogram are described by
208+
* BucketOptions.
209+
*
210+
* If bucket_options has no type, then there is no histogram associated with
211+
* the Distribution.
212+
*/
213+
export interface BucketOptions {
214+
/** Bucket with explicit bounds. */
215+
readonly explicit: Explicit;
216+
}
217+
218+
/**
219+
* Properties of an Explicit.
220+
* Specifies a set of buckets with arbitrary upper-bounds.
221+
* This defines size(bounds) + 1 (= N) buckets. The boundaries for bucket
222+
* index i are:
223+
*
224+
* [0, bucket_bounds[i]) for i == 0
225+
* [bucket_bounds[i-1], bucket_bounds[i]) for 0 < i < N-1
226+
* [bucket_bounds[i-1], +infinity) for i == N-1
227+
*/
228+
export interface Explicit {
229+
/** The values must be strictly increasing and > 0. */
230+
readonly bounds: number[];
231+
// TODO: If OpenMetrics decides to support (a, b] intervals we should add
232+
// support for these by defining a boolean value here which decides what
233+
// type of intervals to use.
234+
}
235+
236+
/** Properties of a Bucket. */
237+
export interface Bucket {
238+
/**
239+
* The number of values in each bucket of the histogram, as described in
240+
* bucket_bounds.
241+
*/
242+
readonly count: number;
243+
/**
244+
* If the distribution does not have a histogram, then omit this field.
245+
*/
246+
readonly exemplar: Exemplar;
247+
}
248+
249+
/**
250+
* Exemplars are example points that may be used to annotate aggregated
251+
* Distribution values. They are metadata that gives information about a
252+
* particular value added to a Distribution bucket.
253+
*/
254+
export interface Exemplar {
255+
/**
256+
* Value of the exemplar point. It determines which bucket the exemplar
257+
* belongs to.
258+
*/
259+
readonly value: number;
260+
/** The observation (sampling) time of the above value. */
261+
readonly timestamp: Timestamp;
262+
/** Contextual information about the example value. */
263+
readonly attachments: ({[k: string]: string}|null);
264+
}
265+
266+
/**
267+
* The start_timestamp only applies to the count and sum in the SummaryValue.
268+
*/
269+
export interface SummaryValue {
270+
/**
271+
* The total number of recorded values since start_time. Optional since
272+
* some systems don't expose this.
273+
*/
274+
readonly count: number;
275+
/**
276+
* The total sum of recorded values since start_time. Optional since some
277+
* systems don't expose this. If count is zero then this field must be zero.
278+
* This field must be unset if the sum is not available.
279+
*/
280+
readonly sum: number;
281+
/** Values calculated over an arbitrary time window. */
282+
readonly snapshot: Snapshot;
283+
}
284+
285+
/**
286+
* The values in this message can be reset at arbitrary unknown times, with
287+
* the requirement that all of them are reset at the same time.
288+
*/
289+
export interface Snapshot {
290+
/**
291+
* The number of values in the snapshot. Optional since some systems don't
292+
* expose this.
293+
*/
294+
readonly count: number;
295+
/**
296+
* The sum of values in the snapshot. Optional since some systems don't
297+
* expose this. If count is zero then this field must be zero or not set
298+
* (if not supported).
299+
*/
300+
readonly sum: number;
301+
/**
302+
* A list of values at different percentiles of the distribution calculated
303+
* from the current snapshot. The percentiles must be strictly increasing.
304+
*/
305+
readonly percentileValues: ValueAtPercentile[];
306+
}
307+
308+
/**
309+
* Represents the value at a given percentile of a distribution.
310+
*/
311+
export interface ValueAtPercentile {
312+
/** The percentile of a distribution. Must be in the interval (0.0, 100.0]. */
313+
readonly percentile: number;
314+
/** The value at the given percentile of a distribution. */
315+
readonly value: number;
316+
}
317+
318+
export interface Timestamp {
319+
/**
320+
* Represents seconds of UTC time since Unix epoch
321+
* 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
322+
* 9999-12-31T23:59:59Z inclusive.
323+
*/
324+
seconds: number|null;
325+
/**
326+
* Non-negative fractions of a second at nanosecond resolution. Negative
327+
* second values with fractions must still have non-negative nanos values
328+
* that count forward in time. Must be from 0 to 999,999,999
329+
* inclusive.
330+
*/
331+
nanos: number|null;
332+
}

0 commit comments

Comments
 (0)