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
Hide 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:
...
@@ -400,7 +400,7 @@ For example, we have the following instrumentation class:
You should add it to
`usage_data.rb`
as follows:
You should add it to
`usage_data.rb`
as follows:
```
ruby
```
ruby
boards:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
CountBoardsMetric
.
new
(
time_frame:
'all'
)
),
boards:
add_metric
(
'CountBoardsMetric'
,
time_frame:
'all'
),
```
```
### Why batch counting
### Why batch counting
...
...
lib/gitlab/usage/metrics/names_suggestions/generator.rb
View file @
2e92c887
...
@@ -10,8 +10,10 @@ module Gitlab
...
@@ -10,8 +10,10 @@ module Gitlab
uncached_data
.
deep_stringify_keys
.
dig
(
*
key_path
.
split
(
'.'
))
uncached_data
.
deep_stringify_keys
.
dig
(
*
key_path
.
split
(
'.'
))
end
end
def
add_metric
(
metric
)
def
add_metric
(
metric
,
time_frame:
'none'
)
metric
.
suggested_name
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
suggested_name
end
end
private
private
...
...
lib/gitlab/usage_data.rb
View file @
2e92c887
...
@@ -72,8 +72,8 @@ module Gitlab
...
@@ -72,8 +72,8 @@ module Gitlab
def
license_usage_data
def
license_usage_data
{
{
recorded_at:
recorded_at
,
recorded_at:
recorded_at
,
uuid:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
UuidMetric
.
new
),
uuid:
add_metric
(
'UuidMetric'
),
hostname:
add_metric
(
Gitlab
::
Usage
::
Metrics
::
Instrumentations
::
HostnameMetric
.
new
),
hostname:
add_metric
(
'HostnameMetric'
),
version:
alt_usage_data
{
Gitlab
::
VERSION
},
version:
alt_usage_data
{
Gitlab
::
VERSION
},
installation_type:
alt_usage_data
{
installation_type
},
installation_type:
alt_usage_data
{
installation_type
},
active_user_count:
count
(
User
.
active
),
active_user_count:
count
(
User
.
active
),
...
@@ -93,7 +93,7 @@ module Gitlab
...
@@ -93,7 +93,7 @@ module Gitlab
{
{
counts:
{
counts:
{
assignee_lists:
count
(
List
.
assignee
),
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_builds:
count
(
::
Ci
::
Build
),
ci_internal_pipelines:
count
(
::
Ci
::
Pipeline
.
internal
),
ci_internal_pipelines:
count
(
::
Ci
::
Pipeline
.
internal
),
ci_external_pipelines:
count
(
::
Ci
::
Pipeline
.
external
),
ci_external_pipelines:
count
(
::
Ci
::
Pipeline
.
external
),
...
@@ -138,7 +138,7 @@ module Gitlab
...
@@ -138,7 +138,7 @@ module Gitlab
in_review_folder:
count
(
::
Environment
.
in_review_folder
),
in_review_folder:
count
(
::
Environment
.
in_review_folder
),
grafana_integrated_projects:
count
(
GrafanaIntegration
.
enabled
),
grafana_integrated_projects:
count
(
GrafanaIntegration
.
enabled
),
groups:
count
(
Group
),
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_created_from_gitlab_error_tracking_ui:
count
(
SentryIssue
),
issues_with_associated_zoom_link:
count
(
ZoomMeeting
.
added_to_issue
),
issues_with_associated_zoom_link:
count
(
ZoomMeeting
.
added_to_issue
),
issues_using_zoom_quick_actions:
distinct_count
(
ZoomMeeting
,
:issue_id
),
issues_using_zoom_quick_actions:
distinct_count
(
ZoomMeeting
,
:issue_id
),
...
@@ -257,7 +257,7 @@ module Gitlab
...
@@ -257,7 +257,7 @@ module Gitlab
ldap_encrypted_secrets_enabled:
alt_usage_data
(
fallback:
nil
)
{
Gitlab
::
Auth
::
Ldap
::
Config
.
encrypted_secrets
.
active?
},
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
},
operating_system:
alt_usage_data
(
fallback:
nil
)
{
operating_system
},
gitaly_apdex:
alt_usage_data
{
gitaly_apdex
},
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
end
...
@@ -646,7 +646,7 @@ module Gitlab
...
@@ -646,7 +646,7 @@ module Gitlab
def
usage_activity_by_stage_plan
(
time_period
)
def
usage_activity_by_stage_plan
(
time_period
)
time_frame
=
time_period
.
present?
?
'28d'
:
'none'
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
),
notes:
distinct_count
(
::
Note
.
where
(
time_period
),
:author_id
),
projects:
distinct_count
(
::
Project
.
where
(
time_period
),
:creator_id
),
projects:
distinct_count
(
::
Project
.
where
(
time_period
),
:creator_id
),
todos:
distinct_count
(
::
Todo
.
where
(
time_period
),
:author_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
...
@@ -5,8 +5,10 @@ module Gitlab
SQL_METRIC_DEFAULT
=
-
3
SQL_METRIC_DEFAULT
=
-
3
class
<<
self
class
<<
self
def
add_metric
(
metric
)
def
add_metric
(
metric
,
time_frame:
'none'
)
metric
.
instrumentation
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
instrumentation
end
end
def
count
(
relation
,
column
=
nil
,
batch:
true
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
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
...
@@ -5,8 +5,10 @@ module Gitlab
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/41091
class
UsageDataQueries
<
UsageData
class
UsageDataQueries
<
UsageData
class
<<
self
class
<<
self
def
add_metric
(
metric
)
def
add_metric
(
metric
,
time_frame:
'none'
)
metric
.
instrumentation
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
instrumentation
end
end
def
count
(
relation
,
column
=
nil
,
*
args
,
**
kwargs
)
def
count
(
relation
,
column
=
nil
,
*
args
,
**
kwargs
)
...
...
lib/gitlab/utils/usage_data.rb
View file @
2e92c887
...
@@ -44,8 +44,10 @@ module Gitlab
...
@@ -44,8 +44,10 @@ module Gitlab
DISTRIBUTED_HLL_FALLBACK
=
-
2
DISTRIBUTED_HLL_FALLBACK
=
-
2
MAX_BUCKET_SIZE
=
100
MAX_BUCKET_SIZE
=
100
def
add_metric
(
metric
)
def
add_metric
(
metric
,
time_frame:
'none'
)
metric
.
value
metric_class
=
"Gitlab::Usage::Metrics::Instrumentations::
#{
metric
}
"
.
constantize
metric_class
.
new
(
time_frame:
time_frame
).
value
end
end
def
count
(
relation
,
column
=
nil
,
batch:
true
,
batch_size:
nil
,
start:
nil
,
finish:
nil
)
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
...
@@ -17,10 +17,10 @@ RSpec.describe Gitlab::Usage::Metrics::NamesSuggestions::Generator do
end
end
describe
'#add_metric'
do
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
it
'computes the
suggested nam
e for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'count
s
_issues'
)
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'count_issues'
)
end
end
end
end
...
...
spec/lib/gitlab/usage_data_non_sql_metrics_spec.rb
View file @
2e92c887
...
@@ -6,10 +6,10 @@ RSpec.describe Gitlab::UsageDataNonSqlMetrics do
...
@@ -6,10 +6,10 @@ RSpec.describe Gitlab::UsageDataNonSqlMetrics do
let
(
:default_count
)
{
Gitlab
::
UsageDataNonSqlMetrics
::
SQL_METRIC_DEFAULT
}
let
(
:default_count
)
{
Gitlab
::
UsageDataNonSqlMetrics
::
SQL_METRIC_DEFAULT
}
describe
'#add_metric'
do
describe
'#add_metric'
do
let
(
:metric
)
{
double
(
:metric
,
instrumentation:
1
)
}
let
(
:metric
)
{
'UuidMetric'
}
it
'computes the metric value for given metric'
do
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
end
end
...
...
spec/lib/gitlab/usage_data_queries_spec.rb
View file @
2e92c887
...
@@ -8,10 +8,10 @@ RSpec.describe Gitlab::UsageDataQueries do
...
@@ -8,10 +8,10 @@ RSpec.describe Gitlab::UsageDataQueries do
end
end
describe
'#add_metric'
do
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
it
'
builds the query
for given metric'
do
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'SELECT COUNT("
users"."id") FROM "user
s"'
)
expect
(
described_class
.
add_metric
(
metric
)).
to
eq
(
'SELECT COUNT("
boards"."id") FROM "board
s"'
)
end
end
end
end
...
...
spec/lib/gitlab/utils/usage_data_spec.rb
View file @
2e92c887
...
@@ -6,10 +6,10 @@ RSpec.describe Gitlab::Utils::UsageData do
...
@@ -6,10 +6,10 @@ RSpec.describe Gitlab::Utils::UsageData do
include
Database
::
DatabaseHelpers
include
Database
::
DatabaseHelpers
describe
'#add_metric'
do
describe
'#add_metric'
do
let
(
:metric
)
{
double
(
:metric
,
value:
1
)
}
let
(
:metric
)
{
'UuidMetric'
}
it
'computes the metric value for given metric'
do
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
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