xref: /aosp_15_r20/external/googleapis/google/api/metric.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15syntax = "proto3";
16
17package google.api;
18
19import "google/api/label.proto";
20import "google/api/launch_stage.proto";
21import "google/protobuf/duration.proto";
22
23option go_package = "google.golang.org/genproto/googleapis/api/metric;metric";
24option java_multiple_files = true;
25option java_outer_classname = "MetricProto";
26option java_package = "com.google.api";
27option objc_class_prefix = "GAPI";
28
29// Defines a metric type and its schema. Once a metric descriptor is created,
30// deleting or altering it stops data collection and makes the metric type's
31// existing data unusable.
32//
33message MetricDescriptor {
34  // The kind of measurement. It describes how the data is reported.
35  // For information on setting the start time and end time based on
36  // the MetricKind, see [TimeInterval][google.monitoring.v3.TimeInterval].
37  enum MetricKind {
38    // Do not use this default value.
39    METRIC_KIND_UNSPECIFIED = 0;
40
41    // An instantaneous measurement of a value.
42    GAUGE = 1;
43
44    // The change in a value during a time interval.
45    DELTA = 2;
46
47    // A value accumulated over a time interval.  Cumulative
48    // measurements in a time series should have the same start time
49    // and increasing end times, until an event resets the cumulative
50    // value to zero and sets a new start time for the following
51    // points.
52    CUMULATIVE = 3;
53  }
54
55  // The value type of a metric.
56  enum ValueType {
57    // Do not use this default value.
58    VALUE_TYPE_UNSPECIFIED = 0;
59
60    // The value is a boolean.
61    // This value type can be used only if the metric kind is `GAUGE`.
62    BOOL = 1;
63
64    // The value is a signed 64-bit integer.
65    INT64 = 2;
66
67    // The value is a double precision floating point number.
68    DOUBLE = 3;
69
70    // The value is a text string.
71    // This value type can be used only if the metric kind is `GAUGE`.
72    STRING = 4;
73
74    // The value is a [`Distribution`][google.api.Distribution].
75    DISTRIBUTION = 5;
76
77    // The value is money.
78    MONEY = 6;
79  }
80
81  // Additional annotations that can be used to guide the usage of a metric.
82  message MetricDescriptorMetadata {
83    // Deprecated. Must use the
84    // [MetricDescriptor.launch_stage][google.api.MetricDescriptor.launch_stage]
85    // instead.
86    LaunchStage launch_stage = 1 [deprecated = true];
87
88    // The sampling period of metric data points. For metrics which are written
89    // periodically, consecutive data points are stored at this time interval,
90    // excluding data loss due to errors. Metrics with a higher granularity have
91    // a smaller sampling period.
92    google.protobuf.Duration sample_period = 2;
93
94    // The delay of data points caused by ingestion. Data points older than this
95    // age are guaranteed to be ingested and available to be read, excluding
96    // data loss due to errors.
97    google.protobuf.Duration ingest_delay = 3;
98  }
99
100  // The resource name of the metric descriptor.
101  string name = 1;
102
103  // The metric type, including its DNS name prefix. The type is not
104  // URL-encoded. All user-defined metric types have the DNS name
105  // `custom.googleapis.com` or `external.googleapis.com`. Metric types should
106  // use a natural hierarchical grouping. For example:
107  //
108  //     "custom.googleapis.com/invoice/paid/amount"
109  //     "external.googleapis.com/prometheus/up"
110  //     "appengine.googleapis.com/http/server/response_latencies"
111  string type = 8;
112
113  // The set of labels that can be used to describe a specific
114  // instance of this metric type. For example, the
115  // `appengine.googleapis.com/http/server/response_latencies` metric
116  // type has a label for the HTTP response code, `response_code`, so
117  // you can look at latencies for successful responses or just
118  // for responses that failed.
119  repeated LabelDescriptor labels = 2;
120
121  // Whether the metric records instantaneous values, changes to a value, etc.
122  // Some combinations of `metric_kind` and `value_type` might not be supported.
123  MetricKind metric_kind = 3;
124
125  // Whether the measurement is an integer, a floating-point number, etc.
126  // Some combinations of `metric_kind` and `value_type` might not be supported.
127  ValueType value_type = 4;
128
129  // The units in which the metric value is reported. It is only applicable
130  // if the `value_type` is `INT64`, `DOUBLE`, or `DISTRIBUTION`. The `unit`
131  // defines the representation of the stored metric values.
132  //
133  // Different systems might scale the values to be more easily displayed (so a
134  // value of `0.02kBy` _might_ be displayed as `20By`, and a value of
135  // `3523kBy` _might_ be displayed as `3.5MBy`). However, if the `unit` is
136  // `kBy`, then the value of the metric is always in thousands of bytes, no
137  // matter how it might be displayed.
138  //
139  // If you want a custom metric to record the exact number of CPU-seconds used
140  // by a job, you can create an `INT64 CUMULATIVE` metric whose `unit` is
141  // `s{CPU}` (or equivalently `1s{CPU}` or just `s`). If the job uses 12,005
142  // CPU-seconds, then the value is written as `12005`.
143  //
144  // Alternatively, if you want a custom metric to record data in a more
145  // granular way, you can create a `DOUBLE CUMULATIVE` metric whose `unit` is
146  // `ks{CPU}`, and then write the value `12.005` (which is `12005/1000`),
147  // or use `Kis{CPU}` and write `11.723` (which is `12005/1024`).
148  //
149  // The supported units are a subset of [The Unified Code for Units of
150  // Measure](https://unitsofmeasure.org/ucum.html) standard:
151  //
152  // **Basic units (UNIT)**
153  //
154  // * `bit`   bit
155  // * `By`    byte
156  // * `s`     second
157  // * `min`   minute
158  // * `h`     hour
159  // * `d`     day
160  // * `1`     dimensionless
161  //
162  // **Prefixes (PREFIX)**
163  //
164  // * `k`     kilo    (10^3)
165  // * `M`     mega    (10^6)
166  // * `G`     giga    (10^9)
167  // * `T`     tera    (10^12)
168  // * `P`     peta    (10^15)
169  // * `E`     exa     (10^18)
170  // * `Z`     zetta   (10^21)
171  // * `Y`     yotta   (10^24)
172  //
173  // * `m`     milli   (10^-3)
174  // * `u`     micro   (10^-6)
175  // * `n`     nano    (10^-9)
176  // * `p`     pico    (10^-12)
177  // * `f`     femto   (10^-15)
178  // * `a`     atto    (10^-18)
179  // * `z`     zepto   (10^-21)
180  // * `y`     yocto   (10^-24)
181  //
182  // * `Ki`    kibi    (2^10)
183  // * `Mi`    mebi    (2^20)
184  // * `Gi`    gibi    (2^30)
185  // * `Ti`    tebi    (2^40)
186  // * `Pi`    pebi    (2^50)
187  //
188  // **Grammar**
189  //
190  // The grammar also includes these connectors:
191  //
192  // * `/`    division or ratio (as an infix operator). For examples,
193  //          `kBy/{email}` or `MiBy/10ms` (although you should almost never
194  //          have `/s` in a metric `unit`; rates should always be computed at
195  //          query time from the underlying cumulative or delta value).
196  // * `.`    multiplication or composition (as an infix operator). For
197  //          examples, `GBy.d` or `k{watt}.h`.
198  //
199  // The grammar for a unit is as follows:
200  //
201  //     Expression = Component { "." Component } { "/" Component } ;
202  //
203  //     Component = ( [ PREFIX ] UNIT | "%" ) [ Annotation ]
204  //               | Annotation
205  //               | "1"
206  //               ;
207  //
208  //     Annotation = "{" NAME "}" ;
209  //
210  // Notes:
211  //
212  // * `Annotation` is just a comment if it follows a `UNIT`. If the annotation
213  //    is used alone, then the unit is equivalent to `1`. For examples,
214  //    `{request}/s == 1/s`, `By{transmitted}/s == By/s`.
215  // * `NAME` is a sequence of non-blank printable ASCII characters not
216  //    containing `{` or `}`.
217  // * `1` represents a unitary [dimensionless
218  //    unit](https://en.wikipedia.org/wiki/Dimensionless_quantity) of 1, such
219  //    as in `1/s`. It is typically used when none of the basic units are
220  //    appropriate. For example, "new users per day" can be represented as
221  //    `1/d` or `{new-users}/d` (and a metric value `5` would mean "5 new
222  //    users). Alternatively, "thousands of page views per day" would be
223  //    represented as `1000/d` or `k1/d` or `k{page_views}/d` (and a metric
224  //    value of `5.3` would mean "5300 page views per day").
225  // * `%` represents dimensionless value of 1/100, and annotates values giving
226  //    a percentage (so the metric values are typically in the range of 0..100,
227  //    and a metric value `3` means "3 percent").
228  // * `10^2.%` indicates a metric contains a ratio, typically in the range
229  //    0..1, that will be multiplied by 100 and displayed as a percentage
230  //    (so a metric value `0.03` means "3 percent").
231  string unit = 5;
232
233  // A detailed description of the metric, which can be used in documentation.
234  string description = 6;
235
236  // A concise name for the metric, which can be displayed in user interfaces.
237  // Use sentence case without an ending period, for example "Request count".
238  // This field is optional but it is recommended to be set for any metrics
239  // associated with user-visible concepts, such as Quota.
240  string display_name = 7;
241
242  // Optional. Metadata which can be used to guide usage of the metric.
243  MetricDescriptorMetadata metadata = 10;
244
245  // Optional. The launch stage of the metric definition.
246  LaunchStage launch_stage = 12;
247
248  // Read-only. If present, then a [time
249  // series][google.monitoring.v3.TimeSeries], which is identified partially by
250  // a metric type and a
251  // [MonitoredResourceDescriptor][google.api.MonitoredResourceDescriptor], that
252  // is associated with this metric type can only be associated with one of the
253  // monitored resource types listed here.
254  repeated string monitored_resource_types = 13;
255}
256
257// A specific metric, identified by specifying values for all of the
258// labels of a [`MetricDescriptor`][google.api.MetricDescriptor].
259message Metric {
260  // An existing metric type, see
261  // [google.api.MetricDescriptor][google.api.MetricDescriptor]. For example,
262  // `custom.googleapis.com/invoice/paid/amount`.
263  string type = 3;
264
265  // The set of label values that uniquely identify this metric. All
266  // labels listed in the `MetricDescriptor` must be assigned values.
267  map<string, string> labels = 2;
268}
269