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 | import * as defaultLogger from '../common/console-logger';
|
17 | import * as loggerTypes from '../common/types';
|
18 | import { Metric } from '../metrics/export/types';
|
19 | import { TagMap } from '../tags/tag-map';
|
20 | import { TagKey, TagValue } from '../tags/types';
|
21 | import { AggregationData, AggregationType, Measure, Measurement, View } from './types';
|
22 | /**
|
23 | * A View specifies an aggregation and a set of tag keys. The aggregation will
|
24 | * be broken down by the unique set of matching tag values for each measure.
|
25 | */
|
26 | export declare class BaseView implements View {
|
27 | /**
|
28 | * A string by which the View will be referred to, e.g. "rpc_latency". Names
|
29 | * MUST be unique within the library.
|
30 | */
|
31 | readonly name: string;
|
32 | /** Describes the view, e.g. "RPC latency distribution" */
|
33 | readonly description: string;
|
34 | /** The Measure to which this view is applied. */
|
35 | readonly measure: Measure;
|
36 | /**
|
37 | * A map of stringified tags representing columns labels or tag keys, concept
|
38 | * similar to dimensions on multidimensional modeling, to AggregationData.
|
39 | * If no Tags are provided, then, all data is recorded in a single
|
40 | * aggregation.
|
41 | */
|
42 | private tagValueAggregationMap;
|
43 | /**
|
44 | * A list of tag keys that represents the possible column labels
|
45 | */
|
46 | private columns;
|
47 | /**
|
48 | * An Aggregation describes how data collected is aggregated.
|
49 | * There are four aggregation types: count, sum, lastValue and distirbution.
|
50 | */
|
51 | readonly aggregation: AggregationType;
|
52 | /** The start time for this view */
|
53 | readonly startTime: number;
|
54 | /** The bucket boundaries in a Distribution Aggregation */
|
55 | private bucketBoundaries?;
|
56 | /**
|
57 | * Cache a MetricDescriptor to avoid converting View to MetricDescriptor
|
58 | * in the future.
|
59 | */
|
60 | private metricDescriptor;
|
61 | /**
|
62 | * The end time for this view - represents the last time a value was recorded
|
63 | */
|
64 | endTime?: number;
|
65 | /** true if the view was registered */
|
66 | registered: boolean;
|
67 | /** An object to log information to */
|
68 | logger: loggerTypes.Logger;
|
69 | /**
|
70 | * Creates a new View instance. This constructor is used by Stats. User should
|
71 | * prefer using Stats.createView() instead.
|
72 | * @param name The view name
|
73 | * @param measure The view measure
|
74 | * @param aggregation The view aggregation type
|
75 | * @param tagsKeys The Tags' keys that view will have
|
76 | * @param description The view description
|
77 | * @param bucketBoundaries The view bucket boundaries for a distribution
|
78 | * aggregation type
|
79 | * @param logger
|
80 | */
|
81 | constructor(name: string, measure: Measure, aggregation: AggregationType, tagsKeys: TagKey[], description: string, bucketBoundaries?: number[], logger?: typeof defaultLogger);
|
82 | /** Gets the view's tag keys */
|
83 | getColumns(): TagKey[];
|
84 | /**
|
85 | * Records a measurement in the proper view's row. This method is used by
|
86 | * Stats. User should prefer using Stats.record() instead.
|
87 | *
|
88 | * Measurements with measurement type INT64 will have its value truncated.
|
89 | * @param measurement The measurement to record
|
90 | * @param tags The tags to which the value is applied
|
91 | * @param attachments optional The contextual information associated with an
|
92 | * example value. The contextual information is represented as key - value
|
93 | * string pairs.
|
94 | */
|
95 | recordMeasurement(measurement: Measurement, tags: TagMap, attachments?: {
|
96 | [key: string]: string;
|
97 | }): void;
|
98 | /**
|
99 | * Encodes a TagValue object into a value sorted string.
|
100 | * @param tagValues The tagValues to encode
|
101 | */
|
102 | private encodeTagValues;
|
103 | /**
|
104 | * Creates an empty aggregation data for a given tags.
|
105 | * @param tagValues The tags for that aggregation data
|
106 | */
|
107 | private createAggregationData;
|
108 | /**
|
109 | * Gets view`s metric
|
110 | * @param start The start timestamp in epoch milliseconds
|
111 | * @returns The Metric.
|
112 | */
|
113 | getMetric(start: number): Metric;
|
114 | /**
|
115 | * Converts snapshot to point
|
116 | * @param timestamp The timestamp
|
117 | * @param data The aggregated data
|
118 | * @returns The Point.
|
119 | */
|
120 | private toPoint;
|
121 | /**
|
122 | * Returns a snapshot of an AggregationData for that tags/labels values.
|
123 | * @param tags The desired data's tags
|
124 | * @returns The AggregationData.
|
125 | */
|
126 | getSnapshot(tagValues: Array<TagValue | null>): AggregationData;
|
127 | /** Returns a Bucket with count and examplar (if present) */
|
128 | private getMetricBucket;
|
129 | /** Determines whether the given TagKeys are valid. */
|
130 | private validateTagKeys;
|
131 | }
|