1/*
2 * Copyright (C) 2017 The Android Open Source Project
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
17syntax = "proto2";
18
19package android.os.statsd;
20
21option java_package = "com.android.internal.os";
22option java_outer_classname = "StatsdConfigProto";
23
24enum Position {
25  POSITION_UNKNOWN = 0;
26
27  FIRST = 1;
28
29  LAST = 2;
30
31  ANY = 3;
32
33  ALL = 4;
34}
35
36enum TimeUnit {
37  TIME_UNIT_UNSPECIFIED = 0;
38  ONE_MINUTE = 1;  // WILL BE GUARDRAILED TO 5 MINS UNLESS UID = SHELL OR ROOT
39  FIVE_MINUTES = 2;
40  TEN_MINUTES = 3;
41  THIRTY_MINUTES = 4;
42  ONE_HOUR = 5;
43  THREE_HOURS = 6;
44  SIX_HOURS = 7;
45  TWELVE_HOURS = 8;
46  ONE_DAY = 9;
47  ONE_WEEK = 10;
48  CTS = 1000;
49}
50
51message FieldMatcher {
52  optional int32 field = 1;
53
54  optional Position position = 2;
55
56  repeated FieldMatcher child = 3;
57}
58
59message StringReplacer {
60  // Regex for matching the string.
61  optional string regex = 1;
62
63  // String with which to replace the matched string.
64  optional string replacement = 2;
65}
66
67message FieldValueMatcher {
68  optional int32 field = 1;
69
70  optional Position position = 2;
71
72  oneof value_matcher {
73    bool eq_bool = 3;
74    string eq_string = 4;
75    int64 eq_int = 5;
76
77    int64 lt_int = 6;
78    int64 gt_int = 7;
79    float lt_float = 8;
80    float gt_float = 9;
81
82    int64 lte_int = 10;
83    int64 gte_int = 11;
84
85    MessageMatcher matches_tuple = 12;
86
87    StringListMatcher eq_any_string = 13;
88    StringListMatcher neq_any_string = 14;
89    IntListMatcher eq_any_int = 15;
90    IntListMatcher neq_any_int = 16;
91
92    string eq_wildcard_string = 17;
93    StringListMatcher eq_any_wildcard_string = 18;
94    StringListMatcher neq_any_wildcard_string = 19;
95  }
96
97  // Can only be present if either:
98  // 1. value_matcher is not set.
99  // 2. value_matcher is set to one that is applicable to string fields.
100  optional StringReplacer replace_string = 20;
101}
102
103message MessageMatcher {
104  repeated FieldValueMatcher field_value_matcher = 1;
105}
106
107message StringListMatcher {
108    repeated string str_value = 1;
109}
110
111message IntListMatcher {
112    repeated int64 int_value = 1;
113}
114
115enum LogicalOperation {
116  LOGICAL_OPERATION_UNSPECIFIED = 0;
117  AND = 1;
118  OR = 2;
119  NOT = 3;
120  NAND = 4;
121  NOR = 5;
122}
123
124message SimpleAtomMatcher {
125  optional int32 atom_id = 1;
126
127  repeated FieldValueMatcher field_value_matcher = 2;
128}
129
130message AtomMatcher {
131  optional int64 id = 1;
132
133  message Combination {
134    optional LogicalOperation operation = 1;
135
136    repeated int64 matcher = 2;
137  }
138  oneof contents {
139    SimpleAtomMatcher simple_atom_matcher = 2;
140    Combination combination = 3;
141  }
142}
143
144message SimplePredicate {
145  optional int64 start = 1;
146
147  optional int64 stop = 2;
148
149  optional bool count_nesting = 3 [default = true];
150
151  optional int64 stop_all = 4;
152
153  enum InitialValue {
154    UNKNOWN = 0;
155    FALSE = 1;
156  }
157
158  // If unspecified, the default value will be UNKNOWN for conditions without dimensions, and
159  // FALSE for conditions with dimensions.
160  optional InitialValue initial_value = 5;
161
162  optional FieldMatcher dimensions = 6;
163}
164
165message Predicate {
166  optional int64 id = 1;
167
168  message Combination {
169    optional LogicalOperation operation = 1;
170
171    repeated int64 predicate = 2;
172  }
173
174  oneof contents {
175    SimplePredicate simple_predicate = 2;
176    Combination combination = 3;
177  }
178}
179
180message StateMap {
181  message StateGroup {
182    optional int64 group_id = 1;
183
184    repeated int32 value = 2;
185  }
186
187  repeated StateGroup group = 1;
188}
189
190message State {
191  optional int64 id = 1;
192
193  optional int32 atom_id = 2;
194
195  optional StateMap map = 3;
196}
197
198message MetricConditionLink {
199  optional int64 condition = 1;
200
201  optional FieldMatcher fields_in_what = 2;
202
203  optional FieldMatcher fields_in_condition = 3;
204}
205
206message MetricStateLink {
207  optional int32 state_atom_id = 1;
208
209  optional FieldMatcher fields_in_what = 2;
210
211  optional FieldMatcher fields_in_state = 3;
212}
213
214message FieldFilter {
215  optional bool include_all = 1 [default = false];
216  optional FieldMatcher fields = 2;
217}
218
219message UploadThreshold {
220    oneof value_comparison {
221        int64 lt_int = 1;
222        int64 gt_int = 2;
223        float lt_float = 3;
224        float gt_float = 4;
225        int64 lte_int = 5;
226        int64 gte_int = 6;
227    }
228}
229
230message DimensionalSamplingInfo {
231    optional FieldMatcher sampled_what_field = 1;
232
233    optional int32 shard_count = 2;
234}
235
236message EventMetric {
237  optional int64 id = 1;
238
239  optional int64 what = 2;
240
241  optional int64 condition = 3;
242
243  repeated MetricConditionLink links = 4;
244
245  optional int32 sampling_percentage = 5 [default = 100];
246
247  optional FieldMatcher uid_fields = 6;
248
249  reserved 100;
250  reserved 101;
251}
252
253message CountMetric {
254  optional int64 id = 1;
255
256  optional int64 what = 2;
257
258  optional int64 condition = 3;
259
260  optional FieldMatcher dimensions_in_what = 4;
261
262  repeated int64 slice_by_state = 8;
263
264  optional TimeUnit bucket = 5;
265
266  repeated MetricConditionLink links = 6;
267
268  repeated MetricStateLink state_link = 9;
269
270  optional UploadThreshold threshold = 10;
271
272  optional bool split_bucket_for_app_upgrade = 11;
273
274  optional FieldMatcher dimensions_in_condition = 7 [deprecated = true];
275
276  optional DimensionalSamplingInfo dimensional_sampling_info = 12;
277
278  optional int32 max_dimensions_per_bucket = 13;
279
280  optional FieldMatcher uid_fields = 14;
281
282  reserved 100;
283  reserved 101;
284}
285
286message DurationMetric {
287  optional int64 id = 1;
288
289  optional int64 what = 2;
290
291  optional int64 condition = 3;
292
293  repeated int64 slice_by_state = 9;
294
295  repeated MetricConditionLink links = 4;
296
297  repeated MetricStateLink state_link = 10;
298
299  enum AggregationType {
300    SUM = 1;
301
302    MAX_SPARSE = 2;
303  }
304  optional AggregationType aggregation_type = 5 [default = SUM];
305
306  optional FieldMatcher dimensions_in_what = 6;
307
308  optional TimeUnit bucket = 7;
309
310  optional UploadThreshold threshold = 11;
311
312  optional bool split_bucket_for_app_upgrade = 12;
313
314  optional FieldMatcher dimensions_in_condition = 8 [deprecated = true];
315
316  optional DimensionalSamplingInfo dimensional_sampling_info = 13;
317
318  optional int32 max_dimensions_per_bucket = 14;
319
320  optional FieldMatcher uid_fields = 15;
321
322  reserved 100;
323  reserved 101;
324}
325
326message GaugeMetric {
327  optional int64 id = 1;
328
329  optional int64 what = 2;
330
331  optional int64 trigger_event = 12;
332
333  optional FieldFilter gauge_fields_filter = 3;
334
335  optional int64 condition = 4;
336
337  optional FieldMatcher dimensions_in_what = 5;
338
339  optional FieldMatcher dimensions_in_condition = 8 [deprecated = true];
340
341  optional TimeUnit bucket = 6;
342
343  repeated MetricConditionLink links = 7;
344
345  enum SamplingType {
346    RANDOM_ONE_SAMPLE = 1;
347    ALL_CONDITION_CHANGES = 2 [deprecated = true];
348    CONDITION_CHANGE_TO_TRUE = 3;
349    FIRST_N_SAMPLES = 4;
350  }
351  optional SamplingType sampling_type = 9 [default = RANDOM_ONE_SAMPLE] ;
352
353  optional int64 min_bucket_size_nanos = 10;
354
355  optional int64 max_num_gauge_atoms_per_bucket = 11 [default = 10];
356
357  optional int32 max_pull_delay_sec = 13 [default = 30];
358
359  optional bool split_bucket_for_app_upgrade = 14;
360
361  optional DimensionalSamplingInfo dimensional_sampling_info = 15;
362
363  optional int32 max_dimensions_per_bucket = 16;
364
365  optional int32 sampling_percentage = 17 [default = 100];
366
367  optional int32 pull_probability = 18 [default = 100];
368
369  optional FieldMatcher uid_fields = 19;
370
371  reserved 100;
372  reserved 101;
373}
374
375// Empty proto message to indicate that histogram bins are populated in the client process.
376// No additional configuration parameters are needed in this message.
377message ClientAggregatedBins {
378}
379
380message HistogramBinConfig {
381  message ExplicitBins {
382    repeated float bin = 1;
383  }
384
385  message GeneratedBins {
386    enum Strategy {
387      UNKNOWN = 0;
388      LINEAR = 1;
389      EXPONENTIAL = 2;
390    }
391
392    optional float min = 1;
393    optional float max = 2;
394    optional int32 count = 3;
395    optional Strategy strategy = 4;
396  }
397
398  optional int64 id = 1;
399  oneof binning_strategy {
400    GeneratedBins generated_bins = 2;
401    ExplicitBins explicit_bins = 3;
402    ClientAggregatedBins client_aggregated_bins = 4;
403  }
404}
405
406message ValueMetric {
407  optional int64 id = 1;
408
409  optional int64 what = 2;
410
411  optional FieldMatcher value_field = 3;
412
413  optional int64 condition = 4;
414
415  optional FieldMatcher dimensions_in_what = 5;
416
417  repeated int64 slice_by_state = 18;
418
419  optional TimeUnit bucket = 6;
420
421  repeated MetricConditionLink links = 7;
422
423  repeated MetricStateLink state_link = 19;
424
425  optional UploadThreshold threshold = 20;
426
427  optional int64 condition_correction_threshold_nanos = 21;
428
429  enum AggregationType {
430    SUM = 1;
431    MIN = 2;
432    MAX = 3;
433    AVG = 4;
434    HISTOGRAM = 5;
435  }
436  optional AggregationType aggregation_type = 8 [default = SUM];
437
438  repeated AggregationType aggregation_types = 25;
439
440  // The number of entries should match the number of times HISTOGRAM appears in aggregation_types.
441  // Each i'th HistogramBinConfig corresponds to the i'th HISTOGRAM entry in aggregation_types so
442  // ordering matters.
443  repeated HistogramBinConfig histogram_bin_configs = 26;
444
445  optional bool include_sample_size = 22;
446
447  optional int64 min_bucket_size_nanos = 10;
448
449  optional bool use_absolute_value_on_reset = 11 [default = false];
450
451  optional bool use_diff = 12;
452
453  optional bool use_zero_default_base = 15 [default = false];
454
455  enum ValueDirection {
456      UNKNOWN = 0;
457      INCREASING = 1;
458      DECREASING = 2;
459      ANY = 3;
460  }
461  optional ValueDirection value_direction = 13 [default = INCREASING];
462
463  optional bool skip_zero_diff_output = 14 [default = true];
464
465  optional int32 max_pull_delay_sec = 16 [default = 30];
466
467  optional bool split_bucket_for_app_upgrade = 17;
468
469  optional FieldMatcher dimensions_in_condition = 9 [deprecated = true];
470
471  optional DimensionalSamplingInfo dimensional_sampling_info = 23;
472
473  optional int32 max_dimensions_per_bucket = 24;
474
475  optional FieldMatcher uid_fields = 27;
476
477  reserved 100;
478  reserved 101;
479}
480
481message KllMetric {
482  optional int64 id = 1;
483
484  optional int64 what = 2;
485
486  optional FieldMatcher kll_field = 3;
487
488  optional int64 condition = 4;
489
490  optional FieldMatcher dimensions_in_what = 5;
491
492  optional TimeUnit bucket = 6;
493
494  repeated MetricConditionLink links = 7;
495
496  optional int64 min_bucket_size_nanos = 8;
497
498  optional bool split_bucket_for_app_upgrade = 9;
499
500  repeated int64 slice_by_state = 10;
501
502  repeated MetricStateLink state_link = 11;
503
504  optional DimensionalSamplingInfo dimensional_sampling_info = 12;
505
506  optional int32 max_dimensions_per_bucket = 13;
507
508  optional FieldMatcher uid_fields = 14;
509
510  reserved 100;
511  reserved 101;
512}
513
514message Alert {
515  optional int64 id = 1;
516
517  optional int64 metric_id = 2;
518
519  optional int32 num_buckets = 3;
520
521  optional int32 refractory_period_secs = 4;
522
523  optional double trigger_if_sum_gt = 5;
524
525  optional float probability_of_informing = 6 [default = 1.1];
526}
527
528message Alarm {
529  optional int64 id = 1;
530
531  optional int64 offset_millis = 2;
532
533  optional int64 period_millis = 3;
534
535  optional float probability_of_informing = 4 [default = 1.1];
536}
537
538message IncidentdDetails {
539  repeated int32 section = 1;
540
541  enum Destination {
542    AUTOMATIC = 0;
543    EXPLICIT = 1;
544  }
545  optional Destination dest = 2;
546
547  // Package name of the incident report receiver.
548  optional string receiver_pkg = 3;
549
550  // Class name of the incident report receiver.
551  optional string receiver_cls = 4;
552
553  optional string alert_description = 5;
554}
555
556message PerfettoDetails {
557  // The |trace_config| field is a proto-encoded message of type
558  // perfetto.protos.TraceConfig defined in
559  // //external/perfetto/protos/perfetto/config/. On device,
560  // statsd doesn't need to deserialize the message as it's just
561  // passed binary-encoded to the perfetto cmdline client.
562  optional bytes trace_config = 1;
563}
564
565message UprobestatsDetails {
566  // The |config| field is a proto-encoded message of type
567  // uprobestats.protos.UprobestatsConfig defined in
568  // //packages/modules/UprobeStats/src/config.proto. On device,
569  // statsd doesn't need to deserialize the message as it's just
570  // passed binary-encoded to the Uprobestats API.
571  optional bytes config = 1;
572}
573
574message BroadcastSubscriberDetails {
575  optional int64 subscriber_id = 1;
576  repeated string cookie = 2;
577}
578
579message Subscription {
580  optional int64 id = 1;
581
582  enum RuleType {
583    RULE_TYPE_UNSPECIFIED = 0;
584    ALARM = 1;
585    ALERT = 2;
586  }
587  optional RuleType rule_type = 2;
588
589  optional int64 rule_id = 3;
590
591  oneof subscriber_information {
592    IncidentdDetails incidentd_details = 4;
593    PerfettoDetails perfetto_details = 5;
594    BroadcastSubscriberDetails broadcast_subscriber_details = 6;
595    UprobestatsDetails uprobestats_details = 9;
596  }
597
598  optional float probability_of_informing = 7 [default = 1.1];
599
600  // This was used for perfprofd historically.
601  reserved 8;
602}
603
604enum ActivationType {
605  ACTIVATION_TYPE_UNKNOWN = 0;
606  ACTIVATE_IMMEDIATELY = 1;
607  ACTIVATE_ON_BOOT = 2;
608}
609
610message EventActivation {
611  optional int64 atom_matcher_id = 1;
612  optional int64 ttl_seconds = 2;
613  optional int64 deactivation_atom_matcher_id = 3;
614  optional ActivationType activation_type = 4;
615}
616
617message MetricActivation {
618  optional int64 metric_id = 1;
619
620  optional ActivationType activation_type = 3 [deprecated = true];
621
622  repeated EventActivation event_activation = 2;
623}
624
625message PullAtomPackages {
626    optional int32 atom_id = 1;
627
628    repeated string packages = 2;
629}
630
631message StatsdConfig {
632  optional int64 id = 1;
633
634  repeated EventMetric event_metric = 2;
635
636  repeated CountMetric count_metric = 3;
637
638  repeated ValueMetric value_metric = 4;
639
640  repeated GaugeMetric gauge_metric = 5;
641
642  repeated DurationMetric duration_metric = 6;
643
644  repeated KllMetric kll_metric = 25;
645
646  repeated AtomMatcher atom_matcher = 7;
647
648  repeated Predicate predicate = 8;
649
650  repeated Alert alert = 9;
651
652  repeated Alarm alarm = 10;
653
654  repeated Subscription subscription = 11;
655
656  repeated string allowed_log_source = 12;
657
658  repeated int64 no_report_metric = 13;
659
660  message Annotation {
661    optional int64 field_int64 = 1;
662    optional int32 field_int32 = 2;
663  }
664  repeated Annotation annotation = 14;
665
666  optional int64 ttl_in_seconds = 15;
667
668  optional bool hash_strings_in_metric_report = 16 [default = true];
669
670  repeated MetricActivation metric_activation = 17;
671
672  optional bool version_strings_in_metric_report = 18;
673
674  optional bool installer_in_metric_report = 19;
675
676  optional bool persist_locally = 20 [default = false];
677
678  repeated State state = 21;
679
680  repeated string default_pull_packages = 22;
681
682  repeated PullAtomPackages pull_atom_packages = 23;
683
684  repeated int32 whitelisted_atom_ids = 24;
685
686  optional uint32 package_certificate_hash_size_bytes = 26;
687
688  optional string restricted_metrics_delegate_package_name = 27;
689
690  optional int32 max_metrics_memory_kb = 28;
691
692  optional int32 soft_metrics_memory_kb = 29;
693
694  message StatsdConfigOptions {
695    optional bool use_v2_soft_memory_limit = 1;
696    optional bool omit_system_uids_in_uidmap = 2;
697    optional bool omit_unused_uids_in_uidmap = 3;
698    repeated string uidmap_package_allowlist = 4;
699  }
700
701  optional StatsdConfigOptions statsd_config_options = 30;
702
703  // Do not use.
704  reserved 1000, 1001;
705}
706