Skip to content

Add custom fallback to GenericMetric

What does this MR do?

Adds the possibility to have a custom fallback value for GenericMetric.

The default value for fallback is -1

The custom fallback could be of any value. Numeric, Boolean, Array, Hash. The logic should be, we should return the custom value we set when there is any exception raised.

This is needed for some of the metrics we have in [usage_data.rb](uhttps://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/usage_data.rb#L257

Example:

ldap_encrypted_secrets_enabled: alt_usage_data(fallback: nil) { Gitlab::Auth::Ldap::Config.encrypted_secrets.active? },
 operating_system: alt_usage_data(fallback: nil) { operating_system },

Usage for this would be

class Exmple < GenericMetric
  fallback(-2)
  value { Gitlab::Database.version }
end

Screenshots or Screencasts (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

Does this MR contain changes to processing or storing of credentials or tokens, authorization and authentication methods or other items described in the security review guidelines? If not, then delete this Security section.

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Alina Mihaila

Merge request reports