1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef COMPONENTS_METRICS_STRUCTURED_LIB_HISTOGRAM_UTIL_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_LIB_HISTOGRAM_UTIL_H_ 7 8 namespace metrics::structured { 9 10 // Describes the action taken by KeyData::ValidateAndGetKey on a particular user 11 // event key. A key can either be valid with no action taken, missing and so 12 // created, or out of its rotation period and so re-created. These values are 13 // persisted to logs. Entries should not be renumbered and numeric values should 14 // never be reused. 15 enum class KeyValidationState { 16 kValid = 0, 17 kCreated = 1, 18 kRotated = 2, 19 kMaxValue = kRotated, 20 }; 21 22 // Possible internal errors of the structured metrics system. These are events 23 // we expect to never see, so only the absolute counts should be looked at, the 24 // bucket proportion doesn't make sense. These values are persisted to logs. 25 // Entries should not be renumbered and numeric values should never be reused. 26 enum class StructuredMetricsError { 27 kMissingKey = 0, 28 kWrongKeyLength = 1, 29 kMissingLastRotation = 2, 30 kMissingRotationPeriod = 3, 31 kFailedUintConversion = 4, 32 kKeyReadError = 5, 33 kKeyParseError = 6, 34 kKeyWriteError = 7, 35 kKeySerializationError = 8, 36 kEventReadError = 9, 37 kEventParseError = 10, 38 kEventWriteError = 11, 39 kEventSerializationError = 12, 40 kUninitializedClient = 13, 41 kInvalidEventParsed = 14, 42 kMaxValue = kInvalidEventParsed, 43 }; 44 45 // Logs an error state in Structured metrics. 46 void LogInternalError(StructuredMetricsError error); 47 48 // Logs the key validation state. This captures the key state when keys are 49 // requested to be validated. 50 void LogKeyValidation(KeyValidationState state); 51 52 } // namespace metrics::structured 53 54 #endif // COMPONENTS_METRICS_STRUCTURED_LIB_HISTOGRAM_UTIL_H_ 55