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
f400e279
Commit
f400e279
authored
Jul 23, 2021
by
Piotr Skorupa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RedisMetric instrumentation class
parent
b593c724
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
1 deletion
+81
-1
config/metrics/counts_all/20210216182006_source_code_pushes.yml
.../metrics/counts_all/20210216182006_source_code_pushes.yml
+4
-0
lib/generators/gitlab/usage_metric/usage_metric_generator.rb
lib/generators/gitlab/usage_metric/usage_metric_generator.rb
+2
-1
lib/gitlab/usage/metrics/instrumentations/redis_metric.rb
lib/gitlab/usage/metrics/instrumentations/redis_metric.rb
+51
-0
rubocop/rubocop-usage-data.yml
rubocop/rubocop-usage-data.yml
+1
-0
spec/lib/gitlab/usage/metrics/instrumentations/redis_metric_spec.rb
...itlab/usage/metrics/instrumentations/redis_metric_spec.rb
+23
-0
No files found.
config/metrics/counts_all/20210216182006_source_code_pushes.yml
View file @
f400e279
...
...
@@ -10,6 +10,10 @@ value_type: number
status
:
data_available
time_frame
:
all
data_source
:
redis
instrumentation_class
:
RedisMetric
options
:
counter_class
:
SourceCodeCounter
event
:
pushes
distribution
:
-
ce
-
ee
...
...
lib/generators/gitlab/usage_metric/usage_metric_generator.rb
View file @
f400e279
...
...
@@ -11,7 +11,8 @@ module Gitlab
ALLOWED_SUPERCLASSES
=
{
generic:
'Generic'
,
database:
'Database'
database:
'Database'
,
redis:
'Redis'
}.
freeze
ALLOWED_OPERATIONS
=
%w(count distinct_count)
.
freeze
...
...
lib/gitlab/usage/metrics/instrumentations/redis_metric.rb
0 → 100644
View file @
f400e279
# frozen_string_literal: true
module
Gitlab
module
Usage
module
Metrics
module
Instrumentations
# Usage example
#
# In metric YAML definition:
#
# instrumentation_class: RedisMetric
# options:
# event: pushes
# counter_class: SourceCodeCounter
#
class
RedisMetric
<
BaseMetric
include
Gitlab
::
UsageDataCounters
::
RedisCounter
def
initialize
(
time_frame
:,
options:
{})
super
raise
ArgumentError
,
"'event' option is required"
unless
metric_event
.
present?
raise
ArgumentError
,
"'counter class' option is required"
unless
counter_class
.
present?
end
def
metric_event
options
[
:event
]
end
def
counter_class_name
options
[
:counter_class
]
end
def
counter_class
"Gitlab::UsageDataCounters::
#{
counter_class_name
}
"
.
constantize
end
def
value
redis_usage_data
do
counter_class
.
read
(
metric_event
)
end
end
def
suggested_name
Gitlab
::
Usage
::
Metrics
::
NameSuggestion
.
for
(
:redis
)
end
end
end
end
end
end
rubocop/rubocop-usage-data.yml
View file @
f400e279
...
...
@@ -122,3 +122,4 @@ UsageData/InstrumentationSuperclass:
-
:DatabaseMetric
-
:GenericMetric
-
:RedisHLLMetric
-
:RedisMetric
spec/lib/gitlab/usage/metrics/instrumentations/redis_metric_spec.rb
0 → 100644
View file @
f400e279
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
RedisMetric
,
:clean_gitlab_redis_shared_state
do
before
do
4
.
times
do
Gitlab
::
UsageDataCounters
::
SourceCodeCounter
.
count
(
:pushes
)
end
end
let
(
:expected_value
)
{
4
}
it_behaves_like
'a correct instrumented metric value'
,
{
options:
{
event:
'pushes'
,
counter_class:
'SourceCodeCounter'
}
}
it
'raises an exception if event option is not present'
do
expect
{
described_class
.
new
(
counter_class:
'SourceCodeCounter'
)
}.
to
raise_error
(
ArgumentError
)
end
it
'raises an exception if counter_class option is not present'
do
expect
{
described_class
.
new
(
event:
'pushes'
)
}.
to
raise_error
(
ArgumentError
)
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