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.
14syntax = "proto3";
15
16package cobalt;
17
18import "report_definition.proto";
19
20option java_multiple_files = true;
21option java_package = "com.google.cobalt";
22
23////////////////////////////////////////////////////////////////////////////////
24// NOTE: This file is used by the Cobalt client and the Cobalt servers.
25// The source-of-truth of this file is located in Cobalt's open source code
26// repository, and the file is copied to Android where it is used by the Cobalt
27// client. Do not edit the copy of this file in this Android repo as those edits
28// will be overwritten when the file is next copied.
29////////////////////////////////////////////////////////////////////////////////
30
31// A Metric is a category of Events that a user logs to Cobalt.
32//
33// A Metric belongs to a Project and has a name and a type.
34//
35// When an Event is logged in Cobalt's Logger interface, a Metric is
36// specified and the Event then belongs to that Metric.
37//
38// A MetricDefinition includes a list of ReportDefinitions. These are the
39// definitions of the Reports that should be run for that Metric. Generating a
40// Report involves the Cobalt client sending Observations to the server based
41// on the Events belonging to the Metric, and the server performing an analysis
42// of those Observations in order to generate the Report output.
43//
44// When an Observation is sent from a Cobalt client to the server, it contains
45// a Metric id and a Report id. This indicates that the
46// Observation is derived from the Events belonging to the Metric for the
47// purpose of generating the Report.
48//
49// A MetricDefinition is used to define a Metric.
50//
51// Next ID: 27
52message MetricDefinition {
53  reserved 6, 7, 9, 13, 14, 15, 17, 21, 23, 24;
54  reserved "event_codes", "event_code_buffer_max", "max_event_code", "parts", "proto_name",
55      "string_buffer_max", "replacement_metric_id", "no_replacement_metric", "customer_name",
56      "project_name";
57
58  // Unique name for this Metric within its owning project.
59  // The name must obey the syntax of a C variable name and must have length
60  // at most 64.
61  string metric_name = 1;
62
63  // These three numbers form this Metric's unique numerical ID in Cobalt. The
64  // Cobalt registry YAML parser will automatically set the value of
65  // customer_id and project_id based on the context of the YAML file.
66  // The user must manually set the |id| field to a number uniquely identifying
67  // this Metric within its project.
68  uint32 customer_id = 2;
69  uint32 project_id = 3;
70  uint32 id = 4;
71
72  // A Metric has one of the following types.
73  // Next ID: 12
74  enum MetricType {
75    reserved 1, 2, 3, 4, 5, 6, 7, 9999;
76    reserved "CUSTOM", "ELAPSED_TIME", "EVENT_COUNT", "EVENT_OCCURRED", "FRAME_RATE",
77        "INT_HISTOGRAM", "MEMORY_USAGE", "STRING_USED";
78
79    UNSET = 0;
80
81    // Records that an event has occurred one or many times.
82    //
83    // MetricDefinition fields:
84    // - metric_dimensions (0 or more)
85    // - metric_semantics (required)
86    OCCURRENCE = 8;
87
88    // Records an integer measurement.
89    //
90    // MetricDefinition fields:
91    // - metric_dimensions (0 or more)
92    // - metric_units (Either this field or metric_units_other is required.)
93    // - metric_units_other (Either metric_units or this field is required.)
94    // - metric_semantics (required)
95    INTEGER = 9;
96
97    // Records many approximate integer measurements.
98    //
99    // MetricDefinition fields:
100    // - metric_dimensions (0 or more)
101    // - int_buckets
102    // - metric_units (Either this field or metric_units other is required.)
103    // - metric_units_other (Either metric_units or this field is required.)
104    // - metric_semantics (required)
105    INTEGER_HISTOGRAM = 10;
106
107    // Records the fact that a string was observed.
108    //
109    // MetricDefinition fields:
110    // - metric_dimensions (0 or more)
111    // - metric_semantics (required)
112    // - string_candidate_file. (required)
113    STRING = 11;
114  }
115
116  MetricType metric_type = 5;
117
118  // A container for enumerated sets of event codes.
119  message MetricDimension {
120    // Name of the dimension. Used only in the generated library for the names
121    // of the constants.
122    string dimension = 1;
123
124    // The enumerated set of event codes for this dimension.
125    //
126    // The keys are the numeric codes and the values are the
127    // human-readable labels for the codes. It is OK to add new elements to this
128    // map or to change the spelling of labels after data collection has
129    // started. It is not OK to change the meaning of any of the codes.
130    //
131    // If an event code for a dimension is not passed to the Cobalt logger for
132    // an event that occurred, the value zero will be used. Therefore, it is
133    // not recommended to associate the zero event code with a meaningful
134    // label. Instead, omit the zero event code and your reports will contain
135    // event code labels of `<code 0>` when the event code was not specified,
136    // or specify an explicit zero value with a label of `Unknown` or `Unset`.
137    map<uint32, string> event_codes = 2;
138
139    // max_event_code is the maximal value for any event in this dimension.
140    // Subject to the following rules:
141    //
142    // 1. If you specify max_event_code, you cannot use a value greater than
143    //    that.
144    // 2. If you do not specify max_event_code, you can only use one of the
145    //    explicitly registered values (event_codes).
146    // 3. For the purposes of validation, each dimension is assigned a number
147    //    which is equal to max_event_code+1 if max_event_code is set, or else
148    //    equal to the number of registered values. The product of all of these
149    //    values must not exceed 1024.
150    // 4. Adding, removing, or changing max_event_code is allowed so long as the
151    //    above rules are not violated.
152    uint32 max_event_code = 3;
153
154    reserved 4;
155    reserved "also_treat_as_legacy";
156
157    // event_code_aliases is used by the code generator to generate additional
158    // enum variants. This is intended as a temporary step to allow a soft
159    // cross-repo rename of an event_code variant, and should be cleaned up as
160    // soon as possible.
161    //
162    // The expected use case is as follows (config abbridged for clarity):
163    //
164    // Step 1: Have a metric
165    //
166    //   event_codes:
167    //     - 1: BadName
168    //
169    // Step 2: Rename an event code, adding an alias
170    //
171    //   event_codes:
172    //     - 1: GoodName
173    //   event_code_aliases:
174    //     GoodName: BadName
175    //
176    // Step 3: After all references to `BadName` are removed
177    //
178    //   event_codes:
179    //     - 1: GoodName
180    //
181    map<string, string> event_code_aliases = 5;
182  }
183
184  // A list of MetricDimensions.
185  //
186  // This field is used in most Metric types.
187  repeated MetricDimension metric_dimensions = 16;
188
189  // For metrics of types INTEGER and INTEGER_HISTOGRAM, specifies the units of
190  // the integer. Either metric_units or metric_units_other must be specified.
191  // Use metric_units_other if none of the pre-defined MetricUnits are
192  // appropriate.
193  MetricUnits metric_units = 18;
194  string metric_units_other = 19;
195
196  // Specifies a list of pre-defined semantic categories for the metric.
197  // This should augment the description given in the comments.
198  repeated MetricSemantics metric_semantics = 20;
199
200  // The path to a list of candidate strings for a metric of type STRING.
201  //
202  // This is a required field for metrics of type STRING.
203  string string_candidate_file = 22;
204
205  // The set of buckets for the histograms for this metric. This field is used
206  // only with metrics of type INTEGER_HISTOGRAM.
207  IntegerBuckets int_buckets = 8;
208
209  /////////// The rest of the fields are used with all Metric types ///////////
210
211  // A TimeZonePolicy specifies how the day index of an Event should be computed
212  // based on the system time when the Event is logged.
213  enum TimeZonePolicy {
214    // Use the date in UTC at logging time to compute the day index.
215    UTC = 0;
216
217    // Use the device-local date at logging time to compute the day index.
218    LOCAL = 1;
219
220    // Use the time zone specified in the `other_time_zone` field to compute the
221    // day index.
222    OTHER_TIME_ZONE = 2;
223  }
224
225  // The TimeZonePolicy for this Metric (Optional. Defaults to UTC)
226  TimeZonePolicy time_zone_policy = 10;
227
228  // An IANA time zone identifier (https://iana.org/time-zones). Should be set if
229  // and only if the metric's `time_zone_policy` is OTHER_TIME_ZONE.
230  string other_time_zone = 25;
231
232  message Metadata {
233    reserved 2;
234    reserved "owner";
235
236    // The date after which this metric is no longer valid. If this field is not
237    // supplied, the metric is considered currently expired, and is not
238    // guaranteed to be reported by cobalt.
239    //
240    // The date must be expressed in yyyy/mm/dd form.
241    // It may be at most one year in the future.
242    string expiration_date = 1;
243
244    // Maximum ReleaseStage for which this Metric is allowed to be collected.
245    ReleaseStage max_release_stage = 4;
246
247    // If 'also_log_locally' is true, Cobalt will log it when it receives events
248    // associated with this metric.
249    bool also_log_locally = 5;
250  }
251  Metadata meta_data = 11;
252
253  // The Reports to run for this Metric.
254  repeated ReportDefinition reports = 12;
255
256  // Report IDs that have been previously used and deleted from this metric.
257  // These IDs must not be reused in new reports.
258  repeated uint32 deleted_report_ids = 26;
259}
260
261enum MetricUnits {
262  METRIC_UNITS_OTHER = 0;
263
264  // Units of time
265  NANOSECONDS = 1;
266  MICROSECONDS = 2;
267  MILLISECONDS = 3;
268  SECONDS = 4;
269  MINUTES = 5;
270
271  // Units of data size
272  BYTES = 6;
273  KIBIBYTES = 7;   // 2^10 bytes
274  KILOBYTES = 8;   // 10^3 bytes
275  MEBIBYTES = 9;   // 2^20 bytes
276  MEGABYTES = 10;  // 10^6 bytes
277}
278
279enum MetricSemantics {
280  METRIC_SEMANTICS_UNSPECIFIED = 0;
281
282  // The metric measure how much CPU is being used.
283  CPU = 1;
284
285  // The metric measures size of a data structure.
286  DATA_SIZE = 2;
287
288  // The metric measures frame rendering performance.
289  FRAME_RENDERING = 3;
290
291  // The metric measures the latency of an operation.
292  LATENCY = 4;
293
294  // The metric measures the amount of memory being used.
295  MEMORY_USAGE = 5;
296
297  // The metric measures something about the devices network communication.
298  NETWORK_COMMUNICATION = 6;
299
300  // The metric is being used to measure some property of the real world
301  // environment outside of the device.
302  OUTSIDE_ENVIRONMENT = 7;
303
304  // The metric is being used to track how often a feature or system is used.
305  USAGE_COUNTING = 8;
306}
307