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
2e92c887
Commit
2e92c887
authored
Jul 21, 2021
by
alinamihaila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create instance in add_metric method
parent
51ca20d9
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
33 additions
and
25 deletions
+33
-25
doc/development/service_ping/index.md
doc/development/service_ping/index.md
+1
-1
lib/gitlab/usage/metrics/names_suggestions/generator.rb
lib/gitlab/usage/metrics/names_suggestions/generator.rb
+4
-2
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+6
-6
lib/gitlab/usage_data_non_sql_metrics.rb
lib/gitlab/usage_data_non_sql_metrics.rb
+4
-2
lib/gitlab/usage_data_queries.rb
lib/gitlab/usage_data_queries.rb
+4
-2
lib/gitlab/utils/usage_data.rb
lib/gitlab/utils/usage_data.rb
+4
-2
spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb
.../gitlab/usage/metrics/names_suggestions/generator_spec.rb
+3
-3
spec/lib/gitlab/usage_data_non_sql_metrics_spec.rb
spec/lib/gitlab/usage_data_non_sql_metrics_spec.rb
+2
-2
spec/lib/gitlab/usage_data_queries_spec.rb
spec/lib/gitlab/usage_data_queries_spec.rb
+3
-3
spec/lib/gitlab/utils/usage_data_spec.rb
spec/lib/gitlab/utils/usage_data_spec.rb
+2
-2
No files found.
doc/development/service_ping/index.md
View file @
2e92c887
...
...
@@ -400,7 +400,7 @@ For example, we have the following instrumentation class:
You should add it to
`usage_data.rb`
as follows:
```
ruby
boards:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
CountBoardsMetric
.
new
(
time_frame:
'all'
)
),
boards:
add_metric
(
'CountBoardsMetric'
,
time_frame:
'all'
),
```
### Why batch counting
...
...
lib/gitlab/usage/metrics/names_suggestions/generator.rb
View file @
2e92c887
...
...
@@ -10,8 +10,10 @@ module Gitlab
uncached_data
.
deep_stringify_keys
.
dig
(
*
key_path
.
split
(
'.'
))
end
def
add_metric
(
metric
)
metric
.
suggested_name
def
add_metric
(
metric
,
time_frame:
'none'
)
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
suggested_name
end
private
...
...
lib/gitlab/usage_data.rb
View file @
2e92c887
...
...
@@ -72,8 +72,8 @@ module Gitlab
def
license_usage_data
{
recorded_at:
recorded_at
,
uuid:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
UuidMetric
.
new
),
hostname:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
HostnameMetric
.
new
),
uuid:
add_metric
(
'UuidMetric'
),
hostname:
add_metric
(
'HostnameMetric'
),
version:
alt_usage_data
{
Gitlab
::
VERSION
},
installation_type:
alt_usage_data
{
installation_type
},
active_user_count:
count
(
User
.
active
),
...
...
@@ -93,7 +93,7 @@ module Gitlab
{
counts:
{
assignee_lists:
count
(
List
.
assignee
),
boards:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
CountBoardsMetric
.
new
(
time_frame:
'all'
)
),
boards:
add_metric
(
'CountBoardsMetric'
,
time_frame:
'all'
),
ci_builds:
count
(
::
Ci
::
Build
),
ci_internal_pipelines:
count
(
::
Ci
::
Pipeline
.
internal
),
ci_external_pipelines:
count
(
::
Ci
::
Pipeline
.
external
),
...
...
@@ -138,7 +138,7 @@ module Gitlab
in_review_folder:
count
(
::
Environment
.
in_review_folder
),
grafana_integrated_projects:
count
(
GrafanaIntegration
.
enabled
),
groups:
count
(
Group
),
issues:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
CountIssuesMetric
.
new
(
time_frame:
'all'
)
),
issues:
add_metric
(
'CountIssuesMetric'
,
time_frame:
'all'
),
issues_created_from_gitlab_error_tracking_ui:
count
(
SentryIssue
),
issues_with_associated_zoom_link:
count
(
ZoomMeeting
.
added_to_issue
),
issues_using_zoom_quick_actions:
distinct_count
(
ZoomMeeting
,
:issue_id
),
...
...
@@ -257,7 +257,7 @@ module Gitlab
ldap_encrypted_secrets_enabled:
alt_usage_data
(
fallback:
nil
)
{
Gitlab
::
Auth
::
Ldap
::
Config
.
encrypted_secrets
.
active?
},
operating_system:
alt_usage_data
(
fallback:
nil
)
{
operating_system
},
gitaly_apdex:
alt_usage_data
{
gitaly_apdex
},
collected_data_categories:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
CollectedDataCategoriesMetric
.
new
(
time_frame:
'none'
)
)
collected_data_categories:
add_metric
(
'CollectedDataCategoriesMetric'
,
time_frame:
'none'
)
}
}
end
...
...
@@ -646,7 +646,7 @@ module Gitlab
def
usage_activity_by_stage_plan
(
time_period
)
time_frame
=
time_period
.
present?
?
'28d'
:
'none'
{
issues:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
CountUsersCreatingIssuesMetric
.
new
(
time_frame:
time_frame
)
),
issues:
add_metric
(
'CountUsersCreatingIssuesMetric'
,
time_frame:
time_frame
),
notes:
distinct_count
(
::
Note
.
where
(
time_period
),
:author_id
),
projects:
distinct_count
(
::
Project
.
where
(
time_period
),
:creator_id
),
todos:
distinct_count
(
::
Todo
.
where
(
time_period
),
:author_id
),
...
...
lib/gitlab/usage_data_non_sql_metrics.rb
View file @
2e92c887
...
...
@@ -5,8 +5,10 @@ module Gitlab
SQL_METRIC_DEFAULT
=
-
3
class
<<
self
def
add_metric
(
metric
)
metric
.
instrumentation
def
add_metric
(
metric
,
time_frame:
'none'
)
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
instrumentation
end
def
count
(
relation
,
column
=
nil
,
batch:
true
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
...
...
lib/gitlab/usage_data_queries.rb
View file @
2e92c887
...
...
@@ -5,8 +5,10 @@ module Gitlab
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
class
UsageDataQueries
<
UsageData
class
<<
self
def
add_metric
(
metric
)
metric
.
instrumentation
def
add_metric
(
metric
,
time_frame:
'none'
)
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
instrumentation
end
def
count
(
relation
,
column
=
nil
,
*
args
,
**
kwargs
)
...
...
lib/gitlab/utils/usage_data.rb
View file @
2e92c887
...
...
@@ -44,8 +44,10 @@ module Gitlab
DISTRIBUTED_HLL_FALLBACK
=
-
2
MAX_BUCKET_SIZE
=
100
def
add_metric
(
metric
)
metric
.
value
def
add_metric
(
metric
,
time_frame:
'none'
)
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
value
end
def
count
(
relation
,
column
=
nil
,
batch:
true
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
...
...
spec/lib/gitlab/usage/metrics/names_suggestions/generator_spec.rb
View file @
2e92c887
...
...
@@ -17,10 +17,10 @@ RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do
end
describe
'#add_metric'
do
let
(
:metric
)
{
double
(
:metric
,
suggested_name:
'counts_issues'
)
}
let
(
:metric
)
{
'CountIssuesMetric'
}
it
'computes the
metric valu
e for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'count
s
_issues'
)
it
'computes the
suggested nam
e for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'count_issues'
)
end
end
...
...
spec/lib/gitlab/usage_data_non_sql_metrics_spec.rb
View file @
2e92c887
...
...
@@ -6,10 +6,10 @@ RSpec.describe Gitlab::UsageDataNonSqlMetrics do
let
(
:default_count
)
{
Gitlab
::
UsageDataNonSqlMetrics
::
SQL_METRIC_DEFAULT
}
describe
'#add_metric'
do
let
(
:metric
)
{
double
(
:metric
,
instrumentation:
1
)
}
let
(
:metric
)
{
'UuidMetric'
}
it
'computes the metric value for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
1
)
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
Gitlab
::
CurrentSettings
.
uuid
)
end
end
...
...
spec/lib/gitlab/usage_data_queries_spec.rb
View file @
2e92c887
...
...
@@ -8,10 +8,10 @@ RSpec.describe Gitlab::UsageDataQueries do
end
describe
'#add_metric'
do
let
(
:metric
)
{
double
(
:metric
,
instrumentation:
'SELECT COUNT("users"."id") FROM "users"'
)
}
let
(
:metric
)
{
'CountBoardsMetric'
}
it
'
computes the metric value
for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'SELECT COUNT("
users"."id") FROM "user
s"'
)
it
'
builds the query
for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'SELECT COUNT("
boards"."id") FROM "board
s"'
)
end
end
...
...
spec/lib/gitlab/utils/usage_data_spec.rb
View file @
2e92c887
...
...
@@ -6,10 +6,10 @@ RSpec.describe Gitlab::Utils::UsageData do
include
Database
::
DatabaseHelpers
describe
'#add_metric'
do
let
(
:metric
)
{
double
(
:metric
,
value:
1
)
}
let
(
:metric
)
{
'UuidMetric'
}
it
'computes the metric value for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
1
)
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
Gitlab
::
CurrentSettings
.
uuid
)
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