[software_delivery] Add litnay of metrics

This change adds metrics for pkg-resolver, system_updater, and pkg-cache.

Change-Id: I8adf04cf8c82808451dd7ec40619cca8d3aa3f38
diff --git a/fuchsia/software_delivery/metrics.yaml b/fuchsia/software_delivery/metrics.yaml
index 2b181c9..578be45 100644
--- a/fuchsia/software_delivery/metrics.yaml
+++ b/fuchsia/software_delivery/metrics.yaml
@@ -202,3 +202,493 @@
   meta_data:
     max_release_stage: GA
     expiration_date: "2020/04/15"
+
+################################################################################
+# Fetch Blob Success
+#
+# Used to log a 1 every time fetch_blob fails or succeeds. This statistic does
+# not dedup retries. This would happens a lot after a new package was registered
+# but infrequently after that. This would occur thousands of times after an
+# update over a few minute or so. Updates are expected to be monthly however. So
+# bursts of more than one per second are expected.
+################################################################################
+- id: 6
+  metric_name: fetch_blob
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: success
+        1: CreateBlob
+        2: BadHttpStatus
+        3: NoMirrors
+        4: ContentLengthMismatch
+        5: UnknownLength
+        6: BlobTooSmall
+        7: BlobTooLarge
+        8: Truncate
+        9: Write
+        10: Hyper
+        11: Http
+        12: BlobUrl
+  reports:
+    - report_name: fetch_blob_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: fetch_blob_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 100
+          step_size: 20
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Is Font Package Check
+#
+# Triggered each time the font resolver is asked to resolve a package. This
+# event logs a 1 and whether the package was a font package or not. We expect
+# this to happen rarely, only a few times after certain applications start.
+# Perhaps once per hour at most. We expect that only font packages should be
+# requested from the font resolver so we should never log a not_font result.
+################################################################################
+- id: 7
+  metric_name: is_font_package_check
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: not_font
+        1: font
+  reports:
+    - report_name: is_font_package_check_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: is_font_package_check_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 50
+          step_size: 1
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Font Manager Load Static Registry
+#
+# Occurs when the FontPackageManager tries to load a static registry. Logs a 1
+# along with the load result. This would only occur once per boot, so about once
+# per month.
+################################################################################
+- id: 8
+  metric_name: font_manager_load_static_registry
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: success
+        1: Io
+        2: Parse
+        3: PkgUrl
+  reports:
+    - report_name: is_font_package_check_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: font_manager_load_static_registry_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 20
+          step_size: 1
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Package Resolver Startup Duration
+#
+# Tracks the time it takes the package resolver to startup. Events occur
+# once per boot.
+################################################################################
+- id: 9
+  metric_name: pkg_resolver_startup_duration
+  metric_type: ELAPSED_TIME
+  reports:
+    - report_name: pkg_resolver_startup_duration_stats
+      id: 1
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 100
+          step_size: 250
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+      aggregation_type: MAX
+      window_size:
+        - 1
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+
+################################################################################
+# Repository Manager Load Static Configs
+#
+# Occurs when RepositoryManager attempts to load static repo configs. Logs a 1
+# along with the load result. Occurs once per boot.
+################################################################################
+- id: 10
+  metric_name: repository_manager_load_static_configs
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: success
+        1: Io
+        2: Parse
+        3: Overridden
+  reports:
+    - report_name: repository_manager_load_static_configs_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: repository_manager_load_static_configs_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 30
+          step_size: 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+      window_size:
+        - 1
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Repository Manager Load Repository for Channel
+#
+# Occurs when RepositoryManager tries to find a repo config for a channel. Logs
+# a 1 and whether loading the repository was successful or not. Occurs once per
+# boot.
+################################################################################
+- id: 11
+  metric_name: repository_manager_load_repository_for_channel
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: failure
+        1: success
+  reports:
+    - report_name: repository_manager_load_repository_for_channel_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: repository_manager_load_repository_for_channel_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 30
+          step_size: 1
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Create TUF Client
+#
+# Triggers when Repository tries to create a tuf client. Logs a 1 and the status
+# of creating the TUF client. This happens once per boot.
+################################################################################
+- id: 12
+  metric_name: create_tuf_client
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: success
+        1: BadSignature
+        2: Encoding
+        3: ExpiredMetadata
+        4: IllegalArgument
+        5: MissingMetadata
+        6: NoSupportedHashAlgorithm
+        7: NotFound
+        8: Opaque
+        9: Programming
+        10: TargetUnavaliable
+        11: UnknownKeyType
+        12: VerificationFailure
+  reports:
+    - report_name: create_tuf_client_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: create_tuf_client_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 30
+          step_size: 1
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Update TUF Client
+#
+# Occurs when UpdatingTufClient tries to update. Logs a 1 and the update status.
+# If an error occurs it logs the error type. This would happen roughly once per
+# month.
+################################################################################
+- id: 13
+  metric_name: update_tuf_client
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: success
+        1: BadSignature
+        2: Encoding
+        3: ExpiredMetadata
+        4: IllegalArgument
+        5: MissingMetadata
+        6: NoSupportedHashAlgorithm
+        7: NotFound
+        8: Opaque
+        9: Programming
+        10: TargetUnavaliable
+        11: UnknownKeyType
+        12: VerificationFailure
+  reports:
+    - report_name: update_tuf_client_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: update_tuf_client_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 20
+          step_size: 1
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Resolve
+#
+# Triggers when resolving a package. Logs a 1 and the status of the resolve
+# which indicates the error type or if everything was succesful. Event codes for
+# each status are positive versions of the execulisively negative error codes
+# used in zircon. This would happen basically every time a componet was run or
+# in a burst after an OTA. It's not clear how often this would happen but bursts
+# of greater than one per second are expected, such as at boot. After that
+# running a componet is expected to be much more rare.
+################################################################################
+- id: 14
+  metric_name: resolve
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: ZX_OK
+        1: ZX_ERR_INTERNAL
+        2: ZX_ERR_NOT_SUPPORTED
+        3: ZX_ERR_NO_RESOURCES
+        4: ZX_ERR_NO_MEMORY
+        6: ZX_ERR_INTERNAL_INTR_RETRY
+        10: ZX_ERR_INVALID
+        11: ZX_ERR_BAD_HANDLE
+        12: ZX_ERR_WRONG_TYPE
+        13: ZX_ERR_BAD_SYSCALL
+        14: ZX_ERR_OUT_OF_RANGE
+        15: ZX_ERR_BUFFER_TOO_SMALL
+        20: ZX_ERR_BAD_STATE
+        21: ZX_ERR_TIMED_OUT
+        22: ZX_ERR_SHOULD_WAIT
+        23: ZX_ERR_CANCLED
+        24: ZX_ERR_PEER_CLOSED
+        25: ZX_ERR_NOT_FOUND
+        26: ZX_ERR_ALREADY_EXISTS
+        27: ZX_ERR_ALREADY_BOUND
+        28: ZX_ERR_UNAVAILABLE
+        30: ZX_ERR_ACCESS_DENIED
+        40: ZX_ERR_IO
+        41: ZX_ERR_IO_REFUSED
+        42: ZX_ERR_IO_DATA_INTEGRITY
+        43: ZX_ERR_IO_DATA_LOSS
+        44: ZX_ERR_IO_NOT_PRESENT
+        45: ZX_ERR_IO_OVERRUN
+        46: ZX_ERR_IO_MISSED_DEADLINE
+        47: ZX_ERR_IO_INVALID
+        50: ZX_ERR_BAD_PATH
+        51: ZX_ERR_NOT_DIR
+        52: ZX_ERR_NOT_FILE
+        53: ZX_ERR_FILE_BIG
+        54: ZX_ERR_NO_SPACE
+        55: ZX_ERR_NOT_EMPTY
+        60: ZX_ERR_STOP
+        61: ZX_ERR_NEXT
+        62: ZX_ERR_ASYNC
+        70: ZX_ERR_PROTOCOL_NOT_SUPPORTED
+        71: ZX_ERR_ADDRESS_UNREACHABLE
+        72: ZX_ERR_ADDRESS_IN_USE
+        73: ZX_ERR_NOT_CONNECTED
+        74: ZX_ERR_CONNECTION_REFUSED
+        75: ZX_ERR_CONNECTION_RESET
+        76: ZX_ERR_CONNECTION_ABORTED
+    - dimension: resolver_type
+      event_codes:
+        0: font
+        1: regular
+  reports:
+    - report_name: resolve_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: resolve_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 1000
+          step_size: 100
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Resolve Duration
+#
+# Occurs after a package has finished resolving, successful or otherwise. Tracks
+# how long it takes to resolve a package. This is expected to take under a few
+# seconds. This event occurs in bursts during boot or after OTA and then rarely
+# after that. Bursts of greater than one per second are expected.
+################################################################################
+- id: 15
+  metric_name: resolve_duration
+  metric_type: ELAPSED_TIME
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: failure
+        1: success
+    - dimension: resolver_type
+      event_codes:
+        0: font
+        1: regular
+  reports:
+    - report_name: resolve_duration_stats
+      id: 1
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 600
+          step_size: 1000
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+      aggregation_type: MAX
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"
+
+################################################################################
+# Package Cache Open
+#
+# Occurs whenever a blob is opened in pkg-cache. Logs a 1 and the open status.
+# If an error does occur it gives the error type. It's expected to occur in
+# bursts during boot at greater than one per second but then become rare after
+# that.
+################################################################################
+- id: 16
+  metric_name: pkg_cache_open
+  metric_type: EVENT_COUNT
+  metric_dimensions:
+    - dimension: result
+      event_codes:
+        0: success
+        1: NotFound
+        2: Io
+  reports:
+    - report_name: pkg_cache_open_stats
+      id: 1
+      report_type: PER_DEVICE_NUMERIC_STATS
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+    - report_name: pkg_cache_open_hist
+      id: 2
+      report_type: PER_DEVICE_HISTOGRAM
+      int_buckets:
+        linear:
+          floor: 0
+          num_buckets: 300
+          step_size: 10
+      window_size:
+        - 1
+      system_profile_field: [BOARD_NAME, PRODUCT_NAME, SYSTEM_VERSION, CHANNEL]
+  meta_data:
+    max_release_stage: GA
+    expiration_date: "2021/03/18"