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