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
81c3921e
Commit
81c3921e
authored
Oct 05, 2021
by
Luis Mejia
Committed by
Alper Akgun
Oct 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exclude removed metrics from with_instrumentation_class method
parent
77299e52
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
3 deletions
+39
-3
ee/spec/lib/gitlab/usage_data_metrics_spec.rb
ee/spec/lib/gitlab/usage_data_metrics_spec.rb
+1
-1
lib/gitlab/usage/metric_definition.rb
lib/gitlab/usage/metric_definition.rb
+6
-1
spec/lib/gitlab/usage/metric_definition_spec.rb
spec/lib/gitlab/usage/metric_definition_spec.rb
+31
-0
spec/lib/gitlab/usage_data_metrics_spec.rb
spec/lib/gitlab/usage_data_metrics_spec.rb
+1
-1
No files found.
ee/spec/lib/gitlab/usage_data_metrics_spec.rb
View file @
81c3921e
...
@@ -26,7 +26,7 @@ RSpec.describe Gitlab::UsageDataMetrics do
...
@@ -26,7 +26,7 @@ RSpec.describe Gitlab::UsageDataMetrics do
let
(
:metric_files_key_paths
)
do
let
(
:metric_files_key_paths
)
do
Gitlab
::
Usage
::
MetricDefinition
Gitlab
::
Usage
::
MetricDefinition
.
definitions
.
definitions
.
select
{
|
k
,
v
|
v
.
attributes
[
:data_source
]
==
'redis_hll'
&&
v
.
key_path
.
starts_with?
(
'redis_hll_counters'
)
}
.
select
{
|
k
,
v
|
v
.
attributes
[
:data_source
]
==
'redis_hll'
&&
v
.
key_path
.
starts_with?
(
'redis_hll_counters'
)
&&
v
.
available?
}
.
keys
.
keys
.
sort
.
sort
end
end
...
...
lib/gitlab/usage/metric_definition.rb
View file @
81c3921e
...
@@ -6,6 +6,7 @@ module Gitlab
...
@@ -6,6 +6,7 @@ module Gitlab
METRIC_SCHEMA_PATH
=
Rails
.
root
.
join
(
'config'
,
'metrics'
,
'schema.json'
)
METRIC_SCHEMA_PATH
=
Rails
.
root
.
join
(
'config'
,
'metrics'
,
'schema.json'
)
BASE_REPO_PATH
=
'https://gitlab.com/gitlab-org/gitlab/-/blob/master'
BASE_REPO_PATH
=
'https://gitlab.com/gitlab-org/gitlab/-/blob/master'
SKIP_VALIDATION_STATUSES
=
%w[deprecated removed]
.
to_set
.
freeze
SKIP_VALIDATION_STATUSES
=
%w[deprecated removed]
.
to_set
.
freeze
AVAILABLE_STATUSES
=
%w[active data_available implemented deprecated]
.
freeze
InvalidError
=
Class
.
new
(
RuntimeError
)
InvalidError
=
Class
.
new
(
RuntimeError
)
...
@@ -59,6 +60,10 @@ module Gitlab
...
@@ -59,6 +60,10 @@ module Gitlab
attributes
[
:data_category
]
&
.
downcase!
attributes
[
:data_category
]
&
.
downcase!
end
end
def
available?
AVAILABLE_STATUSES
.
include?
(
attributes
[
:status
])
end
alias_method
:to_dictionary
,
:to_h
alias_method
:to_dictionary
,
:to_h
class
<<
self
class
<<
self
...
@@ -76,7 +81,7 @@ module Gitlab
...
@@ -76,7 +81,7 @@ module Gitlab
end
end
def
with_instrumentation_class
def
with_instrumentation_class
all
.
select
{
|
definition
|
definition
.
attributes
[
:instrumentation_class
].
present?
}
all
.
select
{
|
definition
|
definition
.
attributes
[
:instrumentation_class
].
present?
&&
definition
.
available?
}
end
end
def
schemer
def
schemer
...
...
spec/lib/gitlab/usage/metric_definition_spec.rb
View file @
81c3921e
...
@@ -49,6 +49,37 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
...
@@ -49,6 +49,37 @@ RSpec.describe Gitlab::Usage::MetricDefinition do
expect
{
described_class
.
definitions
}.
not_to
raise_error
expect
{
described_class
.
definitions
}.
not_to
raise_error
end
end
describe
'#with_instrumentation_class'
do
let
(
:metric_status
)
{
'active'
}
let
(
:all_definitions
)
do
metrics_definitions
=
[
{
key_path:
'metric1'
,
instrumentation_class:
'RedisHLLMetric'
,
status:
'data_available'
},
{
key_path:
'metric2'
,
instrumentation_class:
'RedisHLLMetric'
,
status:
'implemented'
},
{
key_path:
'metric3'
,
instrumentation_class:
'RedisHLLMetric'
,
status:
'deprecated'
},
{
key_path:
'metric4'
,
instrumentation_class:
'RedisHLLMetric'
,
status:
metric_status
},
{
key_path:
'metric5'
,
status:
'active'
},
{
key_path:
'metric_missing_status'
}
]
metrics_definitions
.
map
{
|
definition
|
described_class
.
new
(
definition
[
:key_path
],
definition
.
symbolize_keys
)
}
end
before
do
allow
(
described_class
).
to
receive
(
:all
).
and_return
(
all_definitions
)
end
it
'includes definitions with instrumentation_class'
do
expect
(
described_class
.
with_instrumentation_class
.
count
).
to
eq
(
4
)
end
context
'with removed metric'
do
let
(
:metric_status
)
{
'removed'
}
it
'excludes removed definitions'
do
expect
(
described_class
.
with_instrumentation_class
.
count
).
to
eq
(
3
)
end
end
end
describe
'#key'
do
describe
'#key'
do
subject
{
definition
.
key
}
subject
{
definition
.
key
}
...
...
spec/lib/gitlab/usage_data_metrics_spec.rb
View file @
81c3921e
...
@@ -46,7 +46,7 @@ RSpec.describe Gitlab::UsageDataMetrics do
...
@@ -46,7 +46,7 @@ RSpec.describe Gitlab::UsageDataMetrics do
let
(
:metric_files_key_paths
)
do
let
(
:metric_files_key_paths
)
do
Gitlab
::
Usage
::
MetricDefinition
Gitlab
::
Usage
::
MetricDefinition
.
definitions
.
definitions
.
select
{
|
k
,
v
|
v
.
attributes
[
:data_source
]
==
'redis_hll'
&&
v
.
key_path
.
starts_with?
(
'redis_hll_counters'
)
}
.
select
{
|
k
,
v
|
v
.
attributes
[
:data_source
]
==
'redis_hll'
&&
v
.
key_path
.
starts_with?
(
'redis_hll_counters'
)
&&
v
.
available?
}
.
keys
.
keys
.
sort
.
sort
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