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
f99218fb
Commit
f99218fb
authored
Mar 04, 2021
by
Mikolaj Wawrzyniak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metric name suggestion generator
parent
7fbb521a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
0 deletions
+93
-0
lib/gitlab/usage/metrics/names_suggestions/generator.rb
lib/gitlab/usage/metrics/names_suggestions/generator.rb
+56
-0
spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb
.../gitlab/usage/metrics/names_suggestions/generator_spec.rb
+37
-0
No files found.
lib/gitlab/usage/metrics/names_suggestions/generator.rb
0 → 100644
View file @
f99218fb
# frozen_string_literal: true
module
Gitlab
module
Usage
module
Metrics
module
NamesSuggestions
class
Generator
<
::
Gitlab
::
UsageData
class
<<
self
def
generate
(
key_path
)
uncached_data
.
deep_stringify_keys
.
dig
(
*
key_path
.
split
(
'.'
))
end
private
def
count
(
relation
,
column
=
nil
,
batch:
true
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
"count_
#{
parse_target_and_source
(
column
,
relation
)
}
"
end
def
distinct_count
(
relation
,
column
=
nil
,
batch:
true
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
"count_distinct_
#{
parse_target_and_source
(
column
,
relation
)
}
"
end
def
redis_usage_counter
"names_suggestions_for_redis_counters_are_not_supported_yet"
end
def
redis_usage_data_totals
(
counter
)
counter
.
fallback_totals
.
transform_values
{
|
_
|
"names_suggestions_for_redis_counters_are_not_supported_yet"
}
end
def
sum
(
relation
,
column
,
*
rest
)
"sum_
#{
parse_target_and_source
(
column
,
relation
)
}
"
end
def
estimate_batch_distinct_count
(
relation
,
column
=
nil
,
*
rest
)
"estimate_distinct_
#{
parse_target_and_source
(
column
,
relation
)
}
"
end
def
add
(
*
args
)
"add_
#{
args
.
join
(
'_and_'
)
}
"
end
def
parse_target_and_source
(
column
,
relation
)
if
column
"
#{
column
}
_from_
#{
relation
.
table_name
}
"
else
relation
.
table_name
end
end
end
end
end
end
end
end
spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb
0 → 100644
View file @
f99218fb
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Usage
::
Metrics
::
NamesSuggestions
::
Generator
do
describe
'#generate'
do
context
'for count metrics'
do
it
'return correct name'
do
expect
(
described_class
.
generate
(
'counts.boards'
)).
to
eq
'count_boards'
end
end
context
'for count distinct metrics'
do
it
'return correct name'
do
expect
(
described_class
.
generate
(
'counts.issues_using_zoom_quick_actions'
)).
to
eq
'count_distinct_issue_id_from_zoom_meetings'
end
end
context
'for sum metrics'
do
it
'return correct name'
do
expect
(
described_class
.
generate
(
'counts.jira_imports_total_imported_issues_count'
)).
to
eq
'sum_imported_issues_count_from_jira_imports'
end
end
context
'for add metrics'
do
it
'return correct name'
do
expect
(
described_class
.
generate
(
'counts.snippets'
)).
to
eq
'add_count_snippets_and_count_snippets'
end
end
context
'for redis metrics'
do
it
'return correct name'
do
expect
(
described_class
.
generate
(
'analytics_unique_visits.analytics_unique_visits_for_any_target'
)).
to
eq
'names_suggestions_for_redis_counters_are_not_supported_yet'
end
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