Enable "By Architecture" in the `snapcraft metrics` CLI tooling

Good day! I would like to download all of my package metrics via the snapcraft metrics CLI utility however the “by architecture” option which exists on snapcraft.io is not available.

  • There was a previous request which relates to this
  • There was a GitHub issue to request the functionality and a PR confirming the added functionality.
  • This comment on this issue confirms the metric name as weekly_installed_base_by_architecture.
  • The feature is not documented within the metrics page.

Using the confirmed metric name yields the following error (format edited for your convenience):

Error: Invalid value for '--name': 'weekly_installed_base_by_architecture' is not one of 
'daily_device_change', 
'installed_base_by_channel', 
'installed_base_by_country', 
'installed_base_by_operating_system', 
'installed_base_by_version', 
'weekly_device_change', 
'weekly_installed_base_by_channel',
'weekly_installed_base_by_country', 
'weekly_installed_base_by_operating_system', 
'weekly_installed_base_by_version'.

I don’t know whether

  • the functionality did make it into the tool but was subsequently removed
  • the functionality didn’t in-fact make it into the tool.

I would appreciate it if the Snap team can clarify the situation, especially in regard to whether the daily & weekly metric can be added/enabled in snapcraft metrics.

Best regards

Daniel

1 Like

I wonder what would happen if you just cloned the snapcraft repo, added the two lines required for this and tried it? :smiley:

Worth a punt?

Surprisingly, I’ve got it working.

I updated snapcraft/snapcraft_legacy/storeapi/metrics.py and snapcraft/snapcraft_legacy/cli/_metrics.py accordingly.

class MetricsNames(enum.Enum):
    DAILY_DEVICE_CHANGE = "daily_device_change"
    INSTALLED_BASE_BY_CHANNEL = "installed_base_by_channel"
    INSTALLED_BASE_BY_COUNTRY = "installed_base_by_country"
    INSTALLED_BASE_BY_OPERATING_SYSTEM = "installed_base_by_operating_system"
    INSTALLED_BASE_BY_VERSION = "installed_base_by_version"
    INSTALLED_BASE_BY_ARCHITECTURE = "installed_base_by_architecture"  #  DWD
    WEEKLY_DEVICE_CHANGE = "weekly_device_change"
    WEEKLY_INSTALLED_BASE_BY_CHANNEL = "weekly_installed_base_by_channel"
    WEEKLY_INSTALLED_BASE_BY_COUNTRY = "weekly_installed_base_by_country"
    WEEKLY_INSTALLED_BASE_BY_OPERATING_SYSTEM = (
        "weekly_installed_base_by_operating_system"
    )
    WEEKLY_INSTALLED_BASE_BY_VERSION = "weekly_installed_base_by_version"
    WEEKLY_INSTALLED_BASE_BY_ARCHITECTURE = "weekly_installed_base_by_architecture"  #  DWD

and

METRIC_NAMES_TO_SERIES_LABEL_MAPPINGS = {
    metrics_module.MetricsNames.DAILY_DEVICE_CHANGE.value: "Devices",
    metrics_module.MetricsNames.INSTALLED_BASE_BY_CHANNEL.value: "Channel",
    metrics_module.MetricsNames.INSTALLED_BASE_BY_COUNTRY.value: "Country",
    metrics_module.MetricsNames.INSTALLED_BASE_BY_OPERATING_SYSTEM.value: "OS",
    metrics_module.MetricsNames.INSTALLED_BASE_BY_VERSION.value: "Version",
    metrics_module.MetricsNames.INSTALLED_BASE_BY_ARCHITECTURE.value: "Architecture",  # DWD
    metrics_module.MetricsNames.WEEKLY_DEVICE_CHANGE.value: "Devices",
    metrics_module.MetricsNames.WEEKLY_INSTALLED_BASE_BY_CHANNEL.value: "Channel",
    metrics_module.MetricsNames.WEEKLY_INSTALLED_BASE_BY_COUNTRY.value: "Country",
    metrics_module.MetricsNames.WEEKLY_INSTALLED_BASE_BY_OPERATING_SYSTEM.value: "OS",
    metrics_module.MetricsNames.WEEKLY_INSTALLED_BASE_BY_VERSION.value: "Version",
    metrics_module.MetricsNames.WEEKLY_INSTALLED_BASE_BY_ARCHITECTURE.value: "Architecture",  # DWD
}

respectively.

I’m running the test suite now. Once that’s all sorted I’ll see about a PR

1 Like

Awesome! Good work!

1 Like

Thank you, and thank you for your encouragement

PR: https://github.com/canonical/snapcraft/pull/4735

2 Likes

Merged :slight_smile: feat(metrics): get install base per architecture (#4735) · canonical/snapcraft@b712a84 · GitHub

1 Like