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
7c19a242
Commit
7c19a242
authored
Oct 26, 2018
by
Reuben Pereira
Committed by
Sean McGivern
Oct 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add metric to track projects with atleast 1 alert to usage ping data
parent
a62e2103
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
1 deletion
+36
-1
ee/app/models/prometheus_alert.rb
ee/app/models/prometheus_alert.rb
+5
-0
ee/changelogs/unreleased/rpereira2-7828_add-alerts-count.yml
ee/changelogs/unreleased/rpereira2-7828_add-alerts-count.yml
+5
-0
ee/lib/ee/gitlab/usage_data.rb
ee/lib/ee/gitlab/usage_data.rb
+2
-1
ee/spec/lib/gitlab/usage_data_spec.rb
ee/spec/lib/gitlab/usage_data_spec.rb
+7
-0
ee/spec/models/prometheus_alert_spec.rb
ee/spec/models/prometheus_alert_spec.rb
+17
-0
No files found.
ee/app/models/prometheus_alert.rb
View file @
7c19a242
...
@@ -23,6 +23,11 @@ class PrometheusAlert < ActiveRecord::Base
...
@@ -23,6 +23,11 @@ class PrometheusAlert < ActiveRecord::Base
scope
:for_metric
,
->
(
metric
)
{
where
(
prometheus_metric:
metric
)
}
scope
:for_metric
,
->
(
metric
)
{
where
(
prometheus_metric:
metric
)
}
def
self
.
distinct_projects
sub_query
=
self
.
group
(
:project_id
).
select
(
1
)
self
.
from
(
sub_query
)
end
def
self
.
operator_to_enum
(
op
)
def
self
.
operator_to_enum
(
op
)
OPERATORS_MAP
.
invert
.
fetch
(
op
)
OPERATORS_MAP
.
invert
.
fetch
(
op
)
end
end
...
...
ee/changelogs/unreleased/rpereira2-7828_add-alerts-count.yml
0 → 100644
View file @
7c19a242
---
title
:
Add a metric to the usage ping data to track the number of projects with at least one alert
merge_request
:
8058
author
:
type
:
other
ee/lib/ee/gitlab/usage_data.rb
View file @
7c19a242
...
@@ -99,7 +99,8 @@ module EE
...
@@ -99,7 +99,8 @@ module EE
ldap_keys:
count
(
::
LDAPKey
),
ldap_keys:
count
(
::
LDAPKey
),
ldap_users:
count
(
::
User
.
ldap
),
ldap_users:
count
(
::
User
.
ldap
),
projects_reporting_ci_cd_back_to_github:
count
(
::
GithubService
.
without_defaults
.
active
),
projects_reporting_ci_cd_back_to_github:
count
(
::
GithubService
.
without_defaults
.
active
),
projects_mirrored_with_pipelines_enabled:
projects_mirrored_with_pipelines_enabled
projects_mirrored_with_pipelines_enabled:
projects_mirrored_with_pipelines_enabled
,
projects_with_prometheus_alerts:
count
(
PrometheusAlert
.
distinct_projects
)
}).
merge
(
service_desk_counts
).
merge
(
security_products_usage
)
}).
merge
(
service_desk_counts
).
merge
(
security_products_usage
)
usage_data
usage_data
...
...
ee/spec/lib/gitlab/usage_data_spec.rb
View file @
7c19a242
...
@@ -14,6 +14,10 @@ describe Gitlab::UsageData do
...
@@ -14,6 +14,10 @@ describe Gitlab::UsageData do
create
(
:ci_build
,
name:
'dependency_scanning'
,
pipeline:
pipeline
)
create
(
:ci_build
,
name:
'dependency_scanning'
,
pipeline:
pipeline
)
create
(
:ci_build
,
name:
'license_management'
,
pipeline:
pipeline
)
create
(
:ci_build
,
name:
'license_management'
,
pipeline:
pipeline
)
create
(
:ci_build
,
name:
'sast'
,
pipeline:
pipeline
)
create
(
:ci_build
,
name:
'sast'
,
pipeline:
pipeline
)
create
(
:prometheus_alert
,
project:
projects
[
0
])
create
(
:prometheus_alert
,
project:
projects
[
0
])
create
(
:prometheus_alert
,
project:
projects
[
1
])
end
end
subject
{
described_class
.
data
}
subject
{
described_class
.
data
}
...
@@ -54,7 +58,10 @@ describe Gitlab::UsageData do
...
@@ -54,7 +58,10 @@ describe Gitlab::UsageData do
dependency_scanning_jobs
dependency_scanning_jobs
license_management_jobs
license_management_jobs
sast_jobs
sast_jobs
projects_with_prometheus_alerts
)
)
)
)
expect
(
count_data
[
:projects_with_prometheus_alerts
]).
to
eq
(
2
)
end
end
it
'gathers security products usage data'
do
it
'gathers security products usage data'
do
...
...
ee/spec/models/prometheus_alert_spec.rb
View file @
7c19a242
...
@@ -6,6 +6,23 @@ describe PrometheusAlert do
...
@@ -6,6 +6,23 @@ describe PrometheusAlert do
set
(
:project
)
{
build
(
:project
)
}
set
(
:project
)
{
build
(
:project
)
}
let
(
:metric
)
{
build
(
:prometheus_metric
)
}
let
(
:metric
)
{
build
(
:prometheus_metric
)
}
describe
'.distinct_projects'
do
let
(
:project1
)
{
create
(
:project
)
}
let
(
:project2
)
{
create
(
:project
)
}
before
do
create
(
:prometheus_alert
,
project:
project1
)
create
(
:prometheus_alert
,
project:
project1
)
create
(
:prometheus_alert
,
project:
project2
)
end
subject
{
described_class
.
distinct_projects
.
count
}
it
'returns a count of all distinct projects which have an alert'
do
expect
(
subject
).
to
eq
(
2
)
end
end
describe
'associations'
do
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
belong_to
(
:environment
)
}
it
{
is_expected
.
to
belong_to
(
:environment
)
}
...
...
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