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
fc099c90
Commit
fc099c90
authored
Feb 01, 2021
by
Alina Mihaila
Committed by
Robert Speicher
Feb 01, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add usage_metric_definition generator to generate new yaml metric file
parent
1b52bc22
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
0 deletions
+92
-0
generator_templates/usage_metric_definition/metric_definition.yml
...r_templates/usage_metric_definition/metric_definition.yml
+14
-0
lib/generators/gitlab/usage_metric_definition_generator.rb
lib/generators/gitlab/usage_metric_definition_generator.rb
+78
-0
No files found.
generator_templates/usage_metric_definition/metric_definition.yml
0 → 100644
View file @
fc099c90
# See Usage Ping metrics dictionary docs https://docs.gitlab.com/ee/development/usage_ping/metrics_dictionary.html
key_path
:
<%= key_path %>
value_type
:
product_category
:
stage
:
status
:
milestone
:
introduced_by_url
:
group
:
time_frame
:
<%= time_frame %>
data_source
:
distribution
:
<%= distribution %>
# tier: ['free', 'starter', 'premium', 'ultimate', 'bronze', 'silver', 'gold']
tier
:
lib/generators/gitlab/usage_metric_definition_generator.rb
0 → 100644
View file @
fc099c90
# frozen_string_literal: true
require
'rails/generators'
module
Gitlab
class
UsageMetricDefinitionGenerator
<
Rails
::
Generators
::
Base
Directory
=
Struct
.
new
(
:name
,
:time_frame
)
do
def
match?
(
str
)
(
name
==
str
||
time_frame
==
str
)
&&
str
!=
'none'
end
end
TIME_FRAME_DIRS
=
[
Directory
.
new
(
'counts_7d'
,
'7d'
),
Directory
.
new
(
'counts_28d'
,
'28d'
),
Directory
.
new
(
'counts_all'
,
'all'
),
Directory
.
new
(
'settings'
,
'none'
),
Directory
.
new
(
'license'
,
'none'
)
].
freeze
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__
)
desc
'Generates a metric definition yml file'
class_option
:ee
,
type: :boolean
,
optional:
true
,
default:
false
,
desc:
'Indicates if metric is for ee'
class_option
:dir
,
type: :string
,
desc:
"Indicates the metric location. It must be one of:
#{
VALID_INPUT_DIRS
.
join
(
', '
)
}
"
argument
:key_path
,
type: :string
,
desc:
'Unique JSON key path for the metric'
def
create_metric_file
validate!
template
"metric_definition.yml"
,
file_path
end
def
time_frame
directory
&
.
time_frame
end
def
distribution
value
=
[
'ce'
]
value
<<
'ee'
if
ee?
value
end
private
def
file_path
path
=
File
.
join
(
'config'
,
'metrics'
,
directory
&
.
name
,
"
#{
file_name
}
.yml"
)
path
=
File
.
join
(
'ee'
,
path
)
if
ee?
path
end
def
validate!
raise
"--dir option is required"
unless
input_dir
.
present?
raise
"Invalid dir
#{
input_dir
}
, allowed options are
#{
VALID_INPUT_DIRS
.
join
(
', '
)
}
"
unless
directory
.
present?
end
def
ee?
options
[
:ee
]
end
def
input_dir
options
[
:dir
]
end
def
file_name
key_path
.
split
(
'.'
).
last
end
def
directory
@directory
||=
TIME_FRAME_DIRS
.
find
{
|
d
|
d
.
match?
(
input_dir
)
}
end
end
end
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