Commit 2d99203c authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'am-remove-mentions-of-generating-dictionary' into 'master'

Remove lib to generate metrics dictionary

See merge request gitlab-org/gitlab!68156
parents d9c3a744 3efc78f9
...@@ -10,14 +10,6 @@ Please check the ~"product intelligence" [guide](https://docs.gitlab.com/ee/deve ...@@ -10,14 +10,6 @@ Please check the ~"product intelligence" [guide](https://docs.gitlab.com/ee/deve
MSG MSG
UPDATE_DICTIONARY_MESSAGE = <<~MSG
When adding, changing, or updating metrics, please update the [Metrics Dictionary](https://docs.gitlab.com/ee/development/usage_ping/dictionary.html)
```shell
bundle exec rake gitlab:usage_data:generate_metrics_dictionary
```
MSG
# exit if not matching files # exit if not matching files
matching_changed_files = product_intelligence.matching_changed_files matching_changed_files = product_intelligence.matching_changed_files
return unless matching_changed_files.any? return unless matching_changed_files.any?
......
...@@ -7,7 +7,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w ...@@ -7,7 +7,7 @@ info: To determine the technical writer assigned to the Stage/Group associated w
<!--- <!---
This documentation is auto generated by a script. This documentation is auto generated by a script.
Please do not edit this file directly, check generate_metrics_dictionary task on lib/tasks/gitlab/usage_data.rake. Please do not edit this file directly, check generate_event_dictionary task on lib/tasks/gitlab/snowplow.rake.
---> --->
<!-- vale gitlab.Spelling = NO --> <!-- vale gitlab.Spelling = NO -->
......
This diff is collapsed.
...@@ -16,7 +16,7 @@ module Gitlab ...@@ -16,7 +16,7 @@ module Gitlab
<!--- <!---
This documentation is auto generated by a script. This documentation is auto generated by a script.
Please do not edit this file directly, check generate_metrics_dictionary task on lib/tasks/gitlab/usage_data.rake. Please do not edit this file directly, check generate_event_dictionary task on lib/tasks/gitlab/snowplow.rake.
---> --->
<!-- vale gitlab.Spelling = NO --> <!-- vale gitlab.Spelling = NO -->
......
# frozen_string_literal: true
module Gitlab
module Usage
module Docs
# Helper with functions to be used by HAML templates
module Helper
def auto_generated_comment
<<-MARKDOWN.strip_heredoc
---
stage: Growth
group: Product Intelligence
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
---
<!---
This documentation is auto generated by a script.
Please do not edit this file directly, check generate_metrics_dictionary task on lib/tasks/gitlab/usage_data.rake.
--->
MARKDOWN
end
def render_name(name)
"### `#{name}`"
end
def render_description(object)
return 'Missing description' unless object[:description].present?
object[:description]
end
def render_object_schema(object)
"[Object JSON schema](#{object.json_schema_path})"
end
def render_yaml_link(yaml_path)
"[YAML definition](#{yaml_path})"
end
def render_status(object)
"Status: #{format(:status, object[:status])}"
end
def render_owner(object)
"Group: `#{object[:product_group]}`"
end
def render_tiers(object)
"Tiers:#{format(:tier, object[:tier])}"
end
def render_data_category(object)
"Data Category: `#{object[:data_category]}`"
end
def format(key, value)
Gitlab::Usage::Docs::ValueFormatter.format(key, value)
end
end
end
end
end
# frozen_string_literal: true
module Gitlab
module Usage
module Docs
class Renderer
include Gitlab::Usage::Docs::Helper
DICTIONARY_PATH = Rails.root.join('doc', 'development', 'service_ping')
TEMPLATE_PATH = Rails.root.join('lib', 'gitlab', 'usage', 'docs', 'templates', 'default.md.haml')
def initialize(metrics_definitions)
@layout = Haml::Engine.new(File.read(TEMPLATE_PATH))
@metrics_definitions = metrics_definitions.sort
end
def contents
# Render and remove an extra trailing new line
@contents ||= @layout.render(self, metrics_definitions: @metrics_definitions).sub!(/\n(?=\Z)/, '')
end
def write
filename = DICTIONARY_PATH.join('dictionary.md').to_s
FileUtils.mkdir_p(DICTIONARY_PATH)
File.write(filename, contents)
filename
end
end
end
end
end
= auto_generated_comment
:plain
# Metrics Dictionary
This file is autogenerated, please do not edit directly.
To generate these files from the GitLab repository, run:
```shell
bundle exec rake gitlab:usage_data:generate_metrics_dictionary
```
The Metrics Dictionary is based on the following metrics definition YAML files:
- [`config/metrics`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/config/metrics)
- [`ee/config/metrics`](https://gitlab.com/gitlab-org/gitlab/-/tree/master/ee/config/metrics)
Each table includes a `milestone`, which corresponds to the GitLab version when the metric
was released.
<!-- vale off -->
<!-- Docs linting disabled after this line. -->
<!-- See https://docs.gitlab.com/ee/development/documentation/testing.html#disable-vale-tests -->
## Metrics Definitions
\
- metrics_definitions.each do |name, object|
= render_name(name)
\
= render_description(object.attributes)
- if object.has_json_schema?
\
= render_object_schema(object)
\
= render_yaml_link(object.yaml_path)
\
= render_owner(object.attributes)
- if object.attributes[:data_category].present?
\
= render_data_category(object.attributes)
\
= render_status(object.attributes)
\
= render_tiers(object.attributes)
\
# frozen_string_literal: true
module Gitlab
module Usage
module Docs
class ValueFormatter
def self.format(key, value)
return '' unless value.present?
case key
when :key_path
"**`#{value}`**"
when :data_source
value.to_s.capitalize
when :product_group, :product_category, :status
"`#{value}`"
when :introduced_by_url
"[Introduced by](#{value})"
when :distribution, :tier
Array(value).map { |tier| " `#{tier}`" }.join(',')
else
value
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::Docs::Helper do
subject(:helper) { klass.new }
let_it_be(:klass) do
Class.new do
include Gitlab::Usage::Docs::Helper
end
end
let(:metric_definition) do
{
data_category: 'standard',
name: 'test_metric',
description: description,
product_group: 'group::product intelligence',
status: 'data_available',
tier: %w(free premium)
}
end
let(:description) { 'Metric description' }
describe '#render_name' do
it { expect(helper.render_name(metric_definition[:name])).to eq('### `test_metric`') }
end
describe '#render_description' do
context 'without description' do
let(:description) { nil }
it { expect(helper.render_description(metric_definition)).to eq('Missing description') }
end
context 'without description' do
it { expect(helper.render_description(metric_definition)).to eq('Metric description') }
end
end
describe '#render_yaml_link' do
let(:yaml_link) { 'config/metrics/license/test_metric.yml' }
let(:expected) { "[YAML definition](#{yaml_link})" }
it { expect(helper.render_yaml_link(yaml_link)).to eq(expected) }
end
describe '#render_status' do
let(:expected) { "Status: `data_available`" }
it { expect(helper.render_status(metric_definition)).to eq(expected) }
end
describe '#render_owner' do
let(:expected) { "Group: `group::product intelligence`" }
it { expect(helper.render_owner(metric_definition)).to eq(expected) }
end
describe '#render_tiers' do
let(:expected) { "Tiers: `free`, `premium`" }
it { expect(helper.render_tiers(metric_definition)).to eq(expected) }
end
describe '#render_data_category' do
let(:expected) { 'Data Category: `standard`' }
it { expect(helper.render_data_category(metric_definition)).to eq(expected) }
end
describe '#render_owner' do
let(:expected) { "Group: `group::product intelligence`" }
it { expect(helper.render_owner(metric_definition)).to eq(expected) }
end
end
# frozen_string_literal: true
require 'spec_helper'
CODE_REGEX = %r{<code>(.*)</code>}.freeze
RSpec.describe Gitlab::Usage::Docs::Renderer do
describe 'contents' do
let(:dictionary_path) { Gitlab::Usage::Docs::Renderer::DICTIONARY_PATH }
let(:items) { Gitlab::Usage::MetricDefinition.definitions.first(10).to_h }
it 'generates dictionary for given items' do
generated_dictionary = described_class.new(items).contents
generated_dictionary_keys = RDoc::Markdown
.parse(generated_dictionary)
.table_of_contents
.select { |metric_doc| metric_doc.level == 3 }
.map { |item| item.text.match(CODE_REGEX)&.captures&.first }
expect(generated_dictionary_keys).to match_array(items.keys)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::Docs::ValueFormatter do
describe '.format' do
using RSpec::Parameterized::TableSyntax
where(:key, :value, :expected_value) do
:product_group | 'growth::product intelligence' | '`growth::product intelligence`'
:data_source | 'redis' | 'Redis'
:data_source | 'ruby' | 'Ruby'
:introduced_by_url | 'http://test.com' | '[Introduced by](http://test.com)'
:tier | %w(gold premium) | ' `gold`, `premium`'
:distribution | %w(ce ee) | ' `ce`, `ee`'
:key_path | 'key.path' | '**`key.path`**'
:milestone | '13.4' | '13.4'
:status | 'data_available' | '`data_available`'
end
with_them do
subject { described_class.format(key, value) }
it { is_expected.to eq(expected_value) }
end
end
end
...@@ -177,7 +177,6 @@ RSpec.describe Tooling::Danger::ProjectHelper do ...@@ -177,7 +177,6 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'ee/config/metrics/counts_7d/20210216174919_g_analytics_issues_weekly.yml' | [:product_intelligence] 'ee/config/metrics/counts_7d/20210216174919_g_analytics_issues_weekly.yml' | [:product_intelligence]
'lib/gitlab/usage_data_counters/aggregated_metrics/common.yml' | [:product_intelligence] 'lib/gitlab/usage_data_counters/aggregated_metrics/common.yml' | [:product_intelligence]
'lib/gitlab/usage_data_counters/hll_redis_counter.rb' | [:backend, :product_intelligence] 'lib/gitlab/usage_data_counters/hll_redis_counter.rb' | [:backend, :product_intelligence]
'doc/development/usage_ping/dictionary.md' | [:docs, :product_intelligence]
'lib/gitlab/tracking.rb' | [:backend, :product_intelligence] 'lib/gitlab/tracking.rb' | [:backend, :product_intelligence]
'spec/lib/gitlab/tracking_spec.rb' | [:backend, :product_intelligence] 'spec/lib/gitlab/tracking_spec.rb' | [:backend, :product_intelligence]
'app/helpers/tracking_helper.rb' | [:backend, :product_intelligence] 'app/helpers/tracking_helper.rb' | [:backend, :product_intelligence]
......
...@@ -39,7 +39,6 @@ module Tooling ...@@ -39,7 +39,6 @@ module Tooling
%r{\A(ee/)?config/feature_flags/} => :feature_flag, %r{\A(ee/)?config/feature_flags/} => :feature_flag,
%r{\Adoc/development/usage_ping/dictionary\.md\z} => [:docs, :product_intelligence],
%r{\Adoc/.*(\.(md|png|gif|jpg|yml))\z} => :docs, %r{\Adoc/.*(\.(md|png|gif|jpg|yml))\z} => :docs,
%r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :docs, %r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :docs,
%r{\Adata/whats_new/} => :docs, %r{\Adata/whats_new/} => :docs,
......
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