Commit b1f3dd8d authored by Allison Browne's avatar Allison Browne Committed by Mayra Cabrera

Add count of all alerts to uage ping

Add count of all alerts to usage ping and add a second
metric for manually created alerts
parent 343beb6b
...@@ -59,6 +59,9 @@ class Issue < ApplicationRecord ...@@ -59,6 +59,9 @@ class Issue < ApplicationRecord
has_one :sentry_issue has_one :sentry_issue
has_one :alert_management_alert, class_name: 'AlertManagement::Alert' has_one :alert_management_alert, class_name: 'AlertManagement::Alert'
has_and_belongs_to_many :self_managed_prometheus_alert_events, join_table: :issues_self_managed_prometheus_alert_events # rubocop: disable Rails/HasAndBelongsToMany
has_and_belongs_to_many :prometheus_alert_events, join_table: :issues_prometheus_alert_events # rubocop: disable Rails/HasAndBelongsToMany
has_many :prometheus_alerts, through: :prometheus_alert_events
accepts_nested_attributes_for :sentry_issue accepts_nested_attributes_for :sentry_issue
...@@ -86,12 +89,14 @@ class Issue < ApplicationRecord ...@@ -86,12 +89,14 @@ class Issue < ApplicationRecord
scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) } scope :preload_associated_models, -> { preload(:assignees, :labels, project: :namespace) }
scope :with_api_entity_associations, -> { preload(:timelogs, :assignees, :author, :notes, :labels, project: [:route, { namespace: :route }] ) } scope :with_api_entity_associations, -> { preload(:timelogs, :assignees, :author, :notes, :labels, project: [:route, { namespace: :route }] ) }
scope :with_label_attributes, ->(label_attributes) { joins(:labels).where(labels: label_attributes) } scope :with_label_attributes, ->(label_attributes) { joins(:labels).where(labels: label_attributes) }
scope :with_alert_management_alerts, -> { joins(:alert_management_alert) }
scope :with_prometheus_alert_events, -> { joins(:issues_prometheus_alert_events) }
scope :with_self_managed_prometheus_alert_events, -> { joins(:issues_self_managed_prometheus_alert_events) }
scope :public_only, -> { where(confidential: false) } scope :public_only, -> { where(confidential: false) }
scope :confidential_only, -> { where(confidential: true) } scope :confidential_only, -> { where(confidential: true) }
scope :counts_by_state, -> { reorder(nil).group(:state_id).count } scope :counts_by_state, -> { reorder(nil).group(:state_id).count }
scope :with_alert_management_alerts, -> { joins(:alert_management_alert) }
# An issue can be uniquely identified by project_id and iid # An issue can be uniquely identified by project_id and iid
# Takes one or more sets of composite IDs, expressed as hash-like records of # Takes one or more sets of composite IDs, expressed as hash-like records of
......
---
title: Add count of alerts from all sources to usage ping
merge_request: 33220
author:
type: added
...@@ -358,10 +358,10 @@ On GitLab.com, we have DangerBot setup to monitor Telemetry related files and Da ...@@ -358,10 +358,10 @@ On GitLab.com, we have DangerBot setup to monitor Telemetry related files and Da
| `grafana_integrated_projects` | `counts` | | | | `grafana_integrated_projects` | `counts` | | |
| `groups` | `counts` | | | | `groups` | `counts` | | |
| `issues` | `counts` | | | | `issues` | `counts` | | |
| `issues_created_from_gitlab_error_tracking_ui` | `counts` | | | | `issues_created_from_gitlab_error_tracking_ui` | `counts` | `monitor` | |
| `issues_with_associated_zoom_link` | `counts` | | | | `issues_with_associated_zoom_link` | `counts` | `monitor` | |
| `issues_using_zoom_quick_actions` | `counts` | | | | `issues_using_zoom_quick_actions` | `counts` | `monitor` | |
| `issues_with_embedded_grafana_charts_approx` | `counts` | | | | `issues_with_embedded_grafana_charts_approx` | `counts` | `monitor` | |
| `issues_with_health_status` | `counts` | | | | `issues_with_health_status` | `counts` | | |
| `keys` | `counts` | | | | `keys` | `counts` | | |
| `label_lists` | `counts` | | | | `label_lists` | `counts` | | |
...@@ -373,7 +373,7 @@ On GitLab.com, we have DangerBot setup to monitor Telemetry related files and Da ...@@ -373,7 +373,7 @@ On GitLab.com, we have DangerBot setup to monitor Telemetry related files and Da
| `projects` | `counts` | | | | `projects` | `counts` | | |
| `projects_imported_from_github` | `counts` | | | | `projects_imported_from_github` | `counts` | | |
| `projects_with_repositories_enabled` | `counts` | | | | `projects_with_repositories_enabled` | `counts` | | |
| `projects_with_error_tracking_enabled` | `counts` | | | | `projects_with_error_tracking_enabled` | `counts` | `monitor` | |
| `protected_branches` | `counts` | | | | `protected_branches` | `counts` | | |
| `releases` | `counts` |`release` | Unique release tags | | `releases` | `counts` |`release` | Unique release tags |
| `remote_mirrors` | `counts` | | | | `remote_mirrors` | `counts` | | |
...@@ -462,6 +462,8 @@ On GitLab.com, we have DangerBot setup to monitor Telemetry related files and Da ...@@ -462,6 +462,8 @@ On GitLab.com, we have DangerBot setup to monitor Telemetry related files and Da
| `alert_bot_incident_issues` | `counts` | `monitor` | Issues created by the alert bot | | `alert_bot_incident_issues` | `counts` | `monitor` | Issues created by the alert bot |
| `incident_labeled_issues` | `counts` | `monitor` | Issues with the incident label | | `incident_labeled_issues` | `counts` | `monitor` | Issues with the incident label |
| `issues_created_gitlab_alerts` | `counts` | `monitor` | Issues created from alerts by non-alert bot users | | `issues_created_gitlab_alerts` | `counts` | `monitor` | Issues created from alerts by non-alert bot users |
| `issues_created_manually_from_alerts` | `counts` | `monitor` | Issues created from alerts by non-alert bot users |
| `issues_created_from_alerts` | `counts` | `monitor` | Issues created from Prometheus and alert management alerts |
| `ldap_group_links` | `counts` | | | | `ldap_group_links` | `counts` | | |
| `ldap_keys` | `counts` | | | | `ldap_keys` | `counts` | | |
| `ldap_users` | `counts` | | | | `ldap_users` | `counts` | | |
......
...@@ -36,10 +36,6 @@ module EE ...@@ -36,10 +36,6 @@ module EE
has_one :status_page_published_incident, class_name: 'StatusPage::PublishedIncident', inverse_of: :issue has_one :status_page_published_incident, class_name: 'StatusPage::PublishedIncident', inverse_of: :issue
has_and_belongs_to_many :self_managed_prometheus_alert_events, join_table: :issues_self_managed_prometheus_alert_events
has_and_belongs_to_many :prometheus_alert_events, join_table: :issues_prometheus_alert_events
has_many :prometheus_alerts, through: :prometheus_alert_events
has_many :vulnerability_links, class_name: 'Vulnerabilities::IssueLink', inverse_of: :issue has_many :vulnerability_links, class_name: 'Vulnerabilities::IssueLink', inverse_of: :issue
has_many :related_vulnerabilities, through: :vulnerability_links, source: :vulnerability has_many :related_vulnerabilities, through: :vulnerability_links, source: :vulnerability
......
...@@ -178,9 +178,6 @@ RSpec.describe Issue do ...@@ -178,9 +178,6 @@ RSpec.describe Issue do
end end
describe 'relations' do describe 'relations' do
it { is_expected.to have_and_belong_to_many(:prometheus_alert_events) }
it { is_expected.to have_and_belong_to_many(:self_managed_prometheus_alert_events) }
it { is_expected.to have_many(:prometheus_alerts) }
it { is_expected.to have_many(:vulnerability_links).class_name('Vulnerabilities::IssueLink').inverse_of(:issue) } it { is_expected.to have_many(:vulnerability_links).class_name('Vulnerabilities::IssueLink').inverse_of(:issue) }
it { is_expected.to have_many(:related_vulnerabilities).through(:vulnerability_links).source(:vulnerability) } it { is_expected.to have_many(:related_vulnerabilities).through(:vulnerability_links).source(:vulnerability) }
it { is_expected.to belong_to(:promoted_to_epic).class_name('Epic') } it { is_expected.to belong_to(:promoted_to_epic).class_name('Epic') }
......
...@@ -69,6 +69,7 @@ module Gitlab ...@@ -69,6 +69,7 @@ module Gitlab
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def system_usage_data def system_usage_data
alert_bot_incident_count = count(::Issue.authored(::User.alert_bot)) alert_bot_incident_count = count(::Issue.authored(::User.alert_bot))
issues_created_manually_from_alerts = count(Issue.with_alert_management_alerts.not_authored_by(::User.alert_bot))
{ {
counts: { counts: {
...@@ -119,7 +120,9 @@ module Gitlab ...@@ -119,7 +120,9 @@ module Gitlab
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),
issues_with_embedded_grafana_charts_approx: grafana_embed_usage_data, issues_with_embedded_grafana_charts_approx: grafana_embed_usage_data,
issues_created_gitlab_alerts: count(Issue.with_alert_management_alerts.not_authored_by(::User.alert_bot)), issues_created_from_alerts: total_alert_issues,
issues_created_gitlab_alerts: issues_created_manually_from_alerts,
issues_created_manually_from_alerts: issues_created_manually_from_alerts,
incident_issues: alert_bot_incident_count, incident_issues: alert_bot_incident_count,
alert_bot_incident_issues: alert_bot_incident_count, alert_bot_incident_issues: alert_bot_incident_count,
incident_labeled_issues: count(::Issue.with_label_attributes(IncidentManagement::CreateIssueService::INCIDENT_LABEL)), incident_labeled_issues: count(::Issue.with_label_attributes(IncidentManagement::CreateIssueService::INCIDENT_LABEL)),
...@@ -449,6 +452,16 @@ module Gitlab ...@@ -449,6 +452,16 @@ module Gitlab
private private
def total_alert_issues
# Remove prometheus table queries once they are deprecated
# To be removed with https://gitlab.com/gitlab-org/gitlab/-/issues/217407.
[
count(Issue.with_alert_management_alerts),
count(::Issue.with_self_managed_prometheus_alert_events),
count(::Issue.with_prometheus_alert_events)
].reduce(:+)
end
def user_minimum_id def user_minimum_id
strong_memoize(:user_minimum_id) do strong_memoize(:user_minimum_id) do
::User.minimum(:id) ::User.minimum(:id)
......
...@@ -58,6 +58,7 @@ FactoryBot.define do ...@@ -58,6 +58,7 @@ FactoryBot.define do
# Alert Issues # Alert Issues
create(:alert_management_alert, issue: issues[0], project: projects[0]) create(:alert_management_alert, issue: issues[0], project: projects[0])
create(:alert_management_alert, issue: alert_bot_issues[0], project: projects[0]) create(:alert_management_alert, issue: alert_bot_issues[0], project: projects[0])
create(:self_managed_prometheus_alert_event, related_issues: [issues[1]], project: projects[0])
# Enabled clusters # Enabled clusters
gcp_cluster = create(:cluster_provider_gcp, :created).cluster gcp_cluster = create(:cluster_provider_gcp, :created).cluster
......
...@@ -76,6 +76,8 @@ describe Gitlab::UsageData, :aggregate_failures do ...@@ -76,6 +76,8 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:issues_with_embedded_grafana_charts_approx]).to eq(2) expect(count_data[:issues_with_embedded_grafana_charts_approx]).to eq(2)
expect(count_data[:incident_issues]).to eq(4) expect(count_data[:incident_issues]).to eq(4)
expect(count_data[:issues_created_gitlab_alerts]).to eq(1) expect(count_data[:issues_created_gitlab_alerts]).to eq(1)
expect(count_data[:issues_created_from_alerts]).to eq(3)
expect(count_data[:issues_created_manually_from_alerts]).to eq(1)
expect(count_data[:alert_bot_incident_issues]).to eq(4) expect(count_data[:alert_bot_incident_issues]).to eq(4)
expect(count_data[:incident_labeled_issues]).to eq(3) expect(count_data[:incident_labeled_issues]).to eq(3)
......
...@@ -21,6 +21,9 @@ describe Issue do ...@@ -21,6 +21,9 @@ describe Issue do
it { is_expected.to have_one(:alert_management_alert) } it { is_expected.to have_one(:alert_management_alert) }
it { is_expected.to have_many(:resource_milestone_events) } it { is_expected.to have_many(:resource_milestone_events) }
it { is_expected.to have_many(:resource_state_events) } it { is_expected.to have_many(:resource_state_events) }
it { is_expected.to have_and_belong_to_many(:prometheus_alert_events) }
it { is_expected.to have_and_belong_to_many(:self_managed_prometheus_alert_events) }
it { is_expected.to have_many(:prometheus_alerts) }
describe 'versions.most_recent' do describe 'versions.most_recent' do
it 'returns the most recent version' do it 'returns the most recent version' do
......
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