Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f49a8dbf
Commit
f49a8dbf
authored
Mar 04, 2021
by
Mikolaj Wawrzyniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance metric definition generator
Include name suggestion in metric definition
parent
f99218fb
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
4 deletions
+62
-4
config/feature_flags/development/product_intelligence_metrics_names_suggestions.yml
...opment/product_intelligence_metrics_names_suggestions.yml
+8
-0
generator_templates/usage_metric_definition/metric_definition.yml
...r_templates/usage_metric_definition/metric_definition.yml
+1
-1
lib/generators/gitlab/usage_metric_definition_generator.rb
lib/generators/gitlab/usage_metric_definition_generator.rb
+11
-2
lib/gitlab/usage/metrics/names_suggestions/generator.rb
lib/gitlab/usage/metrics/names_suggestions/generator.rb
+0
-1
spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb
...nerators/gitlab/usage_metric_definition_generator_spec.rb
+36
-0
spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb
.../gitlab/usage/metrics/names_suggestions/generator_spec.rb
+6
-0
No files found.
config/feature_flags/development/product_intelligence_metrics_names_suggestions.yml
0 → 100644
View file @
f49a8dbf
---
name
:
product_intelligence_metrics_names_suggestions
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/55733
rollout_issue_url
:
https://gitlab.com/gitlab-org/gitlab/-/issues/323460
milestone
:
'
13.10'
type
:
development
group
:
group::product intelligence
default_enabled
:
false
generator_templates/usage_metric_definition/metric_definition.yml
View file @
f49a8dbf
---
# See Usage Ping metrics dictionary docs https://docs.gitlab.com/ee/development/usage_ping/metrics_dictionary.html
key_path
:
<%= key_path %>
key_path
:
<%= key_path %>
<%= metric_name_suggestion %>
description
:
product_section
:
product_stage
:
...
...
lib/generators/gitlab/usage_metric_definition_generator.rb
View file @
f49a8dbf
...
...
@@ -18,6 +18,9 @@ module Gitlab
Directory
.
new
(
'license'
,
'none'
,
'string'
)
].
freeze
TOP_LEVEL_DIR
=
'config'
TOP_LEVEL_DIR_EE
=
'ee'
VALID_INPUT_DIRS
=
(
TIME_FRAME_DIRS
.
flat_map
{
|
d
|
[
d
.
name
,
d
.
time_frame
]
}
-
%w(none)
).
freeze
source_root
File
.
expand_path
(
'../../../generator_templates/usage_metric_definition'
,
__dir__
)
...
...
@@ -56,9 +59,15 @@ module Gitlab
private
def
metric_name_suggestion
return
unless
Feature
.
enabled?
(
:product_intelligence_metrics_names_suggestions
,
default_enabled: :yaml
)
"
\n
name:
#{
Usage
::
Metrics
::
NamesSuggestions
::
Generator
.
generate
(
key_path
)
}
"
end
def
file_path
path
=
File
.
join
(
'config'
,
'metrics'
,
directory
&
.
name
,
"
#{
file_name
}
.yml"
)
path
=
File
.
join
(
'ee'
,
path
)
if
ee?
path
=
File
.
join
(
TOP_LEVEL_DIR
,
'metrics'
,
directory
&
.
name
,
"
#{
file_name
}
.yml"
)
path
=
File
.
join
(
TOP_LEVEL_DIR_EE
,
path
)
if
ee?
path
end
...
...
lib/gitlab/usage/metrics/names_suggestions/generator.rb
View file @
f49a8dbf
...
...
@@ -40,7 +40,6 @@ module Gitlab
"add_
#{
args
.
join
(
'_and_'
)
}
"
end
def
parse_target_and_source
(
column
,
relation
)
if
column
"
#{
column
}
_from_
#{
relation
.
table_name
}
"
...
...
spec/lib/generators/gitlab/usage_metric_definition_generator_spec.rb
0 → 100644
View file @
f49a8dbf
# frozen_string_literal: true
require
'spec_helper'
require
'rails/generators/testing/behaviour'
RSpec
.
describe
Gitlab
::
UsageMetricDefinitionGenerator
do
let
(
:temp_dir
)
{
Dir
.
mktmpdir
}
before
do
stub_const
(
"
#{
described_class
}
::TOP_LEVEL_DIR"
,
temp_dir
)
end
context
'with product_intelligence_metrics_names_suggestions feature ON'
do
it
'adds name key to metric definition'
do
stub_feature_flags
(
product_intelligence_metrics_names_suggestions:
true
)
expect
(
::
Gitlab
::
Usage
::
Metrics
::
NamesSuggestions
::
Generator
).
to
receive
(
:generate
).
and_return
(
'some name'
)
described_class
.
new
([
'counts_weekly.test_metric'
],
{
'dir'
=>
'7d'
}).
invoke_all
metric_definition_path
=
Dir
.
glob
(
File
.
join
(
temp_dir
,
'metrics/counts_7d/*_test_metric.yml'
)).
first
expect
(
YAML
.
safe_load
(
File
.
read
(
metric_definition_path
))).
to
include
(
"name"
=>
"some name"
)
end
end
context
'with product_intelligence_metrics_names_suggestions feature OFF'
do
it
'adds name key to metric definition'
do
stub_feature_flags
(
product_intelligence_metrics_names_suggestions:
false
)
expect
(
::
Gitlab
::
Usage
::
Metrics
::
NamesSuggestions
::
Generator
).
not_to
receive
(
:generate
)
described_class
.
new
([
'counts_weekly.test_metric'
],
{
'dir'
=>
'7d'
}).
invoke_all
metric_definition_path
=
Dir
.
glob
(
File
.
join
(
temp_dir
,
'metrics/counts_7d/*_test_metric.yml'
)).
first
expect
(
YAML
.
safe_load
(
File
.
read
(
metric_definition_path
)).
keys
).
not_to
include
(
:name
)
end
end
end
spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb
View file @
f49a8dbf
...
...
@@ -3,6 +3,12 @@
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Usage
::
Metrics
::
NamesSuggestions
::
Generator
do
include
UsageDataHelpers
before
do
stub_usage_data_connections
end
describe
'#generate'
do
context
'for count metrics'
do
it
'return correct name'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment