Commit c9ce4db3 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'rpereira2-7828_add-alerts-count1' into 'master'

Add metric to track projects with atleast 1 alert to usage ping data

See merge request gitlab-org/gitlab-ee!8058
parents a62e2103 7c19a242
......@@ -23,6 +23,11 @@ class PrometheusAlert < ActiveRecord::Base
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)
OPERATORS_MAP.invert.fetch(op)
end
......
---
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
......@@ -99,7 +99,8 @@ module EE
ldap_keys: count(::LDAPKey),
ldap_users: count(::User.ldap),
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)
usage_data
......
......@@ -14,6 +14,10 @@ describe Gitlab::UsageData do
create(:ci_build, name: 'dependency_scanning', pipeline: pipeline)
create(:ci_build, name: 'license_management', 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
subject { described_class.data }
......@@ -54,7 +58,10 @@ describe Gitlab::UsageData do
dependency_scanning_jobs
license_management_jobs
sast_jobs
projects_with_prometheus_alerts
))
expect(count_data[:projects_with_prometheus_alerts]).to eq(2)
end
it 'gathers security products usage data' do
......
......@@ -6,6 +6,23 @@ describe PrometheusAlert do
set(:project) { build(:project) }
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
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:environment) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment