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 description: Total deployments count for recent 28 days
value_type: integer value_type: integer
stage: release stage: release
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: counts_monthy.deployments
milestone: 13.2 milestone: 13.2
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35493 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/35493
group: 'group::ops release' 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 description: Distinct users count that changed issue title in a group for last recent week
value_type: integer value_type: integer
product_category: issue_tracking product_category: issue_tracking
stage: plan stage: plan
status: data_available 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 milestone: 13.6
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/229918 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/issues/229918
group: 'group::project management' group: 'group::project management'
......
name: deployments key_path: counts.deployments
description: Total deployments count description: Total deployments count
value_type: integer value_type: integer
stage: release stage: release
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: counts.deployments
milestone: 8.12 milestone: 8.12
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/735 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/735
group: 'group::ops release' group: 'group::ops release'
......
name: recorded_at key_path: recorded_at
description: When the Usage Ping computation was started description: When the Usage Ping computation was started
value_type: string value_type: string
product_category: collection product_category: collection
stage: growth stage: growth
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: recorded_at
milestone: 8.10 milestone: 8.10
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/557 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/557
group: group::product analytics group: group::product analytics
......
name: uuid key_path: uuid
description: GitLab instance unique identifier description: GitLab instance unique identifier
value_type: string value_type: string
product_category: collection product_category: collection
stage: growth stage: growth
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: uuid
generation_2: license.uuid
milestone: 9.1 milestone: 9.1
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1521 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1521
group: group::product analytics group: group::product analytics
......
{ {
"type": "object", "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": { "properties": {
"name": { "key_path": {
"type": "string" "type": "string"
}, },
"description": { "description": {
...@@ -22,12 +22,6 @@ ...@@ -22,12 +22,6 @@
"type": ["string"], "type": ["string"],
"enum": ["data_available", "planned", "in_progress", "implmented"] "enum": ["data_available", "planned", "in_progress", "implmented"]
}, },
"default_generation": {
"type": "string"
},
"full_path": {
"type": "object"
},
"milestone": { "milestone": {
"type": ["number", "null"] "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. 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 value_type: string
product_category: collection product_category: collection
stage: growth stage: growth
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: database.adapter
group: group::enablement distribution group: group::enablement distribution
time_frame: none time_frame: none
data_source: database data_source: database
......
...@@ -15,7 +15,7 @@ We are using [JSON Schema](https://gitlab.com/gitlab-org/gitlab/-/blob/master/co ...@@ -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*: 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). - 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. - Have an owner.
All metrics are stored in YAML files: 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 ...@@ -26,12 +26,10 @@ Each metric is definied in a separate YAML file consisting of a number of fields
| Field | Required | Additional information | | Field | Required | Additional information |
|---------------------|----------|----------------------------------------------------------------| |---------------------|----------|----------------------------------------------------------------|
| `name` | yes | | | `key_path` | yes | JSON key path for the metric, location in Usage Ping payload. |
| `description` | yes | | | `description` | yes | |
| `value_type` | yes | | | `value_type` | yes | |
| `status` | 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. | | `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" | | `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`. | | `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 ...@@ -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. | | `milestone_removed` | no | The milestone when the metric is removed. |
| `introduced_by_url` | no | The URL to the Merge Request that introduced the metric. | | `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 ### Example metric definition
The linked [`uuid`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/metrics/license/uuid.yml) 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 ...@@ -53,16 +48,12 @@ YAML file includes an example metric definition, where the `uuid` metric is the
instance unique identifier. instance unique identifier.
```yaml ```yaml
name: uuid key_path: uuid
description: GitLab instance unique identifier description: GitLab instance unique identifier
value_type: string value_type: string
product_category: collection product_category: collection
stage: growth stage: growth
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: uuid
generation_2: license.uuid
milestone: 9.1 milestone: 9.1
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1521 introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/1521
group: group::product intelligence group: group::product intelligence
......
name: geo_nodes key_path: counts.geo_nodes
description: Total number of sites in a Geo deployment description: Total number of sites in a Geo deployment
value_type: integer value_type: integer
product_category: disaster_recovery product_category: disaster_recovery
stage: enablement stage: enablement
status: data_available status: data_available
default_generation: generation_1
full_path:
generation_1: counts.geo_nodes
milestone: 11.2 milestone: 11.2
group: 'group::geo' group: 'group::geo'
time_frame: all time_frame: all
......
...@@ -7,16 +7,16 @@ module Gitlab ...@@ -7,16 +7,16 @@ module Gitlab
InvalidMetricError = Class.new(RuntimeError) 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 def definition
self.class.definitions[default_generation_path] self.class.definitions[key_path]
end end
def unflatten_default_path def unflatten_key_path
unflatten(default_generation_path.split('.'), value) unflatten(key_path.split('.'), value)
end end
class << self class << self
......
...@@ -13,9 +13,8 @@ module Gitlab ...@@ -13,9 +13,8 @@ module Gitlab
@attributes = opts @attributes = opts
end end
# The key is defined by default_generation and full_path
def key def key
full_path[default_generation.to_sym] key_path
end end
def to_h def to_h
......
...@@ -5,17 +5,13 @@ require 'spec_helper' ...@@ -5,17 +5,13 @@ require 'spec_helper'
RSpec.describe Gitlab::Usage::MetricDefinition do RSpec.describe Gitlab::Usage::MetricDefinition do
let(:attributes) do let(:attributes) do
{ {
name: 'uuid',
description: 'GitLab instance unique identifier', description: 'GitLab instance unique identifier',
value_type: 'string', value_type: 'string',
product_category: 'collection', product_category: 'collection',
stage: 'growth', stage: 'growth',
status: 'data_available', status: 'data_available',
default_generation: 'generation_1', default_generation: 'generation_1',
full_path: { key_path: 'uuid',
generation_1: 'uuid',
generation_2: 'license.uuid'
},
group: 'group::product analytics', group: 'group::product analytics',
time_frame: 'none', time_frame: 'none',
data_source: 'database', data_source: 'database',
...@@ -44,12 +40,11 @@ RSpec.describe Gitlab::Usage::MetricDefinition do ...@@ -44,12 +40,11 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:attribute, :value) do where(:attribute, :value) do
:name | nil
:description | nil :description | nil
:value_type | nil :value_type | nil
:value_type | 'test' :value_type | 'test'
:status | nil :status | nil
:default_generation | nil :key_path | nil
:group | nil :group | nil
:time_frame | nil :time_frame | nil
:time_frame | '29d' :time_frame | '29d'
......
...@@ -4,15 +4,15 @@ require 'spec_helper' ...@@ -4,15 +4,15 @@ require 'spec_helper'
RSpec.describe Gitlab::Usage::Metric do RSpec.describe Gitlab::Usage::Metric do
describe '#definition' do describe '#definition' do
it 'returns generation_1 metric definiton' do it 'returns key_path metric definiton' do
expect(described_class.new(default_generation_path: 'uuid').definition).to be_an(Gitlab::Usage::MetricDefinition) expect(described_class.new(key_path: 'uuid').definition).to be_an(Gitlab::Usage::MetricDefinition)
end end
end end
describe '#unflatten_default_path' do describe '#unflatten_default_path' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
where(:default_generation_path, :value, :expected_hash) do where(:key_path, :value, :expected_hash) do
'uuid' | nil | { uuid: nil } 'uuid' | nil | { uuid: nil }
'uuid' | '1111' | { uuid: '1111' } 'uuid' | '1111' | { uuid: '1111' }
'counts.issues' | nil | { counts: { issues: nil } } 'counts.issues' | nil | { counts: { issues: nil } }
...@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Usage::Metric do ...@@ -21,7 +21,7 @@ RSpec.describe Gitlab::Usage::Metric do
end end
with_them do 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) } it { is_expected.to eq(expected_hash) }
end 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