1 // Copyright 2020 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_HISTOGRAM_UTIL_H_ 6 #define COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_ 7 8 #include <string_view> 9 10 #include "components/prefs/persistent_pref_store.h" 11 12 namespace metrics::structured { 13 14 // Possible internal errors of the structured metrics system. These are events 15 // we expect to never see, so only the absolute counts should be looked at, the 16 // bucket proportion doesn't make sense. These values are persisted to logs. 17 // Entries should not be renumbered and numeric values should never be reused. 18 enum class StructuredMetricsError { 19 kMissingKey = 0, 20 kWrongKeyLength = 1, 21 kMissingLastRotation = 2, 22 kMissingRotationPeriod = 3, 23 kFailedUintConversion = 4, 24 kKeyReadError = 5, 25 kKeyParseError = 6, 26 kKeyWriteError = 7, 27 kKeySerializationError = 8, 28 kEventReadError = 9, 29 kEventParseError = 10, 30 kEventWriteError = 11, 31 kEventSerializationError = 12, 32 kUninitializedClient = 13, 33 kInvalidEventParsed = 14, 34 kMaxValue = kInvalidEventParsed, 35 }; 36 37 // Whether a single event was recorded correctly, or otherwise what error state 38 // occurred. These values are persisted to logs. Entries should not be 39 // renumbered and numeric values should never be reused. 40 enum class EventRecordingState { 41 kRecorded = 0, 42 kProviderUninitialized = 1, 43 kRecordingDisabled = 2, 44 kProviderMissing = 3, 45 kProjectDisallowed = 4, 46 kLogSizeExceeded = 5, 47 kMaxValue = kLogSizeExceeded, 48 }; 49 50 // Describes the action taken by KeyData::ValidateAndGetKey on a particular user 51 // event key. A key can either be valid with no action taken, missing and so 52 // created, or out of its rotation period and so re-created. These values are 53 // persisted to logs. Entries should not be renumbered and numeric values should 54 // never be reused. 55 enum class KeyValidationState { 56 kValid = 0, 57 kCreated = 1, 58 kRotated = 2, 59 kMaxValue = kRotated, 60 }; 61 62 void LogInternalError(StructuredMetricsError error); 63 64 void LogEventRecordingState(EventRecordingState state); 65 66 void LogKeyValidation(KeyValidationState state); 67 68 // Log how many structured metrics events were contained in a call to 69 // ProvideCurrentSessionData. 70 void LogNumEventsInUpload(int num_events); 71 72 // Logs the number of events that were recorded before device and user 73 // cryptographic keys have been loaded to hash events. These events will be kept 74 // in memory. 75 void LogNumEventsRecordedBeforeInit(int num_events); 76 77 // Logs the number of files processed per external metrics scan. 78 void LogNumFilesPerExternalMetricsScan(int num_files); 79 80 // Logs the file size of an event. 81 void LogEventFileSizeKB(int64_t file_size_kb); 82 83 // Logs the serialized size of an event when it is recorded in bytes. 84 void LogEventSerializedSizeBytes(int64_t event_size_bytes); 85 86 // Logs the StructuredMetrics uploaded size to UMA in bytes. 87 void LogUploadSizeBytes(int64_t upload_size_bytes); 88 89 // Logs the number of external metrics were scanned for an upload. 90 void LogExternalMetricsScanInUpload(int num_scans); 91 92 // Logs the number of external metrics that were dropped. 93 void LogDroppedExternalMetrics(int num_dropped); 94 95 // Logs the number of external metrics that were dropped per-project. 96 void LogDroppedProjectExternalMetrics(std::string_view project_name, 97 int num_dropped); 98 99 // Logs the number of external metrics produced per-project. 100 void LogProducedProjectExternalMetrics(std::string_view project_name, 101 int num_produced); 102 103 } // namespace metrics::structured 104 105 #endif // COMPONENTS_METRICS_STRUCTURED_HISTOGRAM_UTIL_H_ 106