Commit c2e5c4c9 authored by Alina Mihaila's avatar Alina Mihaila Committed by Alper Akgun

Simplify metric definition:

  - Remove name attribute, currenlty doesn't add any
  value to metric definition
  - Use key_path for JSON key path,
  location in Usage Ping payload
  - Update docs
parent f37b7aee
name: deployments
key_path: counts_monthy.deployments
description: Total deployments count for recent 28 days
value_type: integer
stage: release
status: data_available
default_generation: generation_1
full_path:
generation_1: counts_monthy.deployments
milestone: 13.2
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35493
group: 'group::ops release'
......
name: g_project_management_issue_title_changed_weekly
key_path: redis_hll_counters.issues_edit.g_project_management_issue_title_changed_weekly
description: Distinct users count that changed issue title in a group for last recent week
value_type: integer
product_category: issue_tracking
stage: plan
status: data_available
default_generation: generation_1
full_path:
generation_1: redis_hll_counters.issues_edit.g_project_management_issue_title_changed_weekly
milestone: 13.6
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/229918
group: 'group::project management'
......
name: deployments
key_path: counts.deployments
description: Total deployments count
value_type: integer
stage: release
status: data_available
default_generation: generation_1
full_path:
generation_1: counts.deployments
milestone: 8.12
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/735
group: 'group::ops release'
......
name: recorded_at
key_path: recorded_at
description: When the Usage Ping computation was started
value_type: string
product_category: collection
stage: growth
status: data_available
default_generation: generation_1
full_path:
generation_1: recorded_at
milestone: 8.10
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/557
group: group::product analytics
......
name: uuid
key_path: uuid
description: GitLab instance unique identifier
value_type: string
product_category: collection
stage: growth
status: data_available
default_generation: generation_1
full_path:
generation_1: uuid
generation_2: license.uuid
milestone: 9.1
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1521
group: group::product analytics
......
{
"type": "object",
"required": ["name", "description", "value_type", "status", "default_generation", "full_path", "group", "time_frame", "data_source", "distribution", "tier"],
"required": ["key_path", "description", "value_type", "status", "group", "time_frame", "data_source", "distribution", "tier"],
"properties": {
"name": {
"key_path": {
"type": "string"
},
"description": {
......@@ -22,12 +22,6 @@
"type": ["string"],
"enum": ["data_available", "planned", "in_progress", "implmented"]
},
"default_generation": {
"type": "string"
},
"full_path": {
"type": "object"
},
"milestone": {
"type": ["number", "null"]
},
......
name: adapter
key_path: database.adapter
description: This metric only returns a value of PostgreSQL in supported versions of GitLab. It could be removed from the usage ping. Historically MySQL was also supported.
value_type: string
product_category: collection
stage: growth
status: data_available
default_generation: generation_1
full_path:
generation_1: database.adapter
group: group::enablement distribution
time_frame: none
data_source: database
......
......@@ -15,7 +15,7 @@ We are using [JSON Schema](https://gitlab.com/gitlab-org/gitlab/-/blob/master/co
This process is meant to ensure consistent and valid metrics defined for Usage Ping. All metrics *must*:
- Comply with the definied [JSON schema](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/schema.json).
- Have a unique `full_path` .
- Have a unique `key_path` .
- Have an owner.
All metrics are stored in YAML files:
......@@ -26,12 +26,10 @@ Each metric is definied in a separate YAML file consisting of a number of fields
| Field | Required | Additional information |
|---------------------|----------|----------------------------------------------------------------|
| `name` | yes | |
| `key_path` | yes | JSON key path for the metric, location in Usage Ping payload. |
| `description` | yes | |
| `value_type` | yes | |
| `status` | yes | |
| `default_generation`| yes | Default generation path of the metric. One full_path value. (1) |
| `full_path` | yes | Full path of the metric for one or multiple generations. Path of the metric in Usage Ping payload. (1) |
| `group` | yes | The [group](https://about.gitlab.com/handbook/product/categories/#devops-stages) that owns the metric. |
| `time_frame` | yes | `string`; may be set to a value like "7d" |
| `data_source` | yes | `string`: may be set to a value like `database` or `redis_hll`. |
......@@ -43,9 +41,6 @@ Each metric is definied in a separate YAML file consisting of a number of fields
| `milestone_removed` | no | The milestone when the metric is removed. |
| `introduced_by_url` | no | The URL to the Merge Request that introduced the metric. |
1. The default generation path is the location of the metric in the Usage Ping payload.
The `full_path` is the list locations for multiple Usage Ping generaations.
### Example metric definition
The linked [`uuid`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/license/uuid.yml)
......@@ -53,16 +48,12 @@ YAML file includes an example metric definition, where the `uuid` metric is the
instance unique identifier.
```yaml
name: uuid
key_path: uuid
description: GitLab instance unique identifier
value_type: string
product_category: collection
stage: growth
status: data_available
default_generation: generation_1
full_path:
generation_1: uuid
generation_2: license.uuid
milestone: 9.1
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1521
group: group::product intelligence
......
name: geo_nodes
key_path: counts.geo_nodes
description: Total number of sites in a Geo deployment
value_type: integer
product_category: disaster_recovery
stage: enablement
status: data_available
default_generation: generation_1
full_path:
generation_1: counts.geo_nodes
milestone: 11.2
group: 'group::geo'
time_frame: all
......
......@@ -7,16 +7,16 @@ module Gitlab
InvalidMetricError = Class.new(RuntimeError)
attr_accessor :default_generation_path, :value
attr_accessor :key_path, :value
validates :default_generation_path, presence: true
validates :key_path, presence: true
def definition
self.class.definitions[default_generation_path]
self.class.definitions[key_path]
end
def unflatten_default_path
unflatten(default_generation_path.split('.'), value)
def unflatten_key_path
unflatten(key_path.split('.'), value)
end
class << self
......
......@@ -13,9 +13,8 @@ module Gitlab
@attributes = opts
end
# The key is defined by default_generation and full_path
def key
full_path[default_generation.to_sym]
key_path
end
def to_h
......
......@@ -5,17 +5,13 @@ require 'spec_helper'
RSpec.describe Gitlab::Usage::MetricDefinition do
let(:attributes) do
{
name: 'uuid',
description: 'GitLab instance unique identifier',
value_type: 'string',
product_category: 'collection',
stage: 'growth',
status: 'data_available',
default_generation: 'generation_1',
full_path: {
generation_1: 'uuid',
generation_2: 'license.uuid'
},
key_path: 'uuid',
group: 'group::product analytics',
time_frame: 'none',
data_source: 'database',
......@@ -44,12 +40,11 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
using RSpec::Parameterized::TableSyntax
where(:attribute, :value) do
:name | nil
:description | nil
:value_type | nil
:value_type | 'test'
:status | nil
:default_generation | nil
:key_path | nil
:group | nil
:time_frame | nil
:time_frame | '29d'
......
......@@ -4,15 +4,15 @@ require 'spec_helper'
RSpec.describe Gitlab::Usage::Metric do
describe '#definition' do
it 'returns generation_1 metric definiton' do
expect(described_class.new(default_generation_path: 'uuid').definition).to be_an(Gitlab::Usage::MetricDefinition)
it 'returns key_path metric definiton' do
expect(described_class.new(key_path: 'uuid').definition).to be_an(Gitlab::Usage::MetricDefinition)
end
end
describe '#unflatten_default_path' do
using RSpec::Parameterized::TableSyntax
where(:default_generation_path, :value, :expected_hash) do
where(:key_path, :value, :expected_hash) do
'uuid' | nil | { uuid: nil }
'uuid' | '1111' | { uuid: '1111' }
'counts.issues' | nil | { counts: { issues: nil } }
......@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Usage::Metric do
end
with_them do
subject { described_class.new(default_generation_path: default_generation_path, value: value).unflatten_default_path }
subject { described_class.new(key_path: key_path, value: value).unflatten_key_path }
it { is_expected.to eq(expected_hash) }
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment