Commit 6764083d authored by Allison Browne's avatar Allison Browne Committed by Peter Leitzen

Add issues_created_gitlab_alerts to usage ping

Add a new metric that records issues manually
created from alerts
parent d8ed2944
......@@ -74,6 +74,7 @@ class Issue < ApplicationRecord
scope :due_before, ->(date) { where('issues.due_date < ?', date) }
scope :due_between, ->(from_date, to_date) { where('issues.due_date >= ?', from_date).where('issues.due_date <= ?', to_date) }
scope :due_tomorrow, -> { where(due_date: Date.tomorrow) }
scope :not_authored_by, ->(user) { where.not(author_id: user) }
scope :order_due_date_asc, -> { reorder(::Gitlab::Database.nulls_last_order('due_date', 'ASC')) }
scope :order_due_date_desc, -> { reorder(::Gitlab::Database.nulls_last_order('due_date', 'DESC')) }
......@@ -90,6 +91,7 @@ class Issue < ApplicationRecord
scope :confidential_only, -> { where(confidential: true) }
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
# Takes one or more sets of composite IDs, expressed as hash-like records of
......
---
title: Add issues_created_gitlab_alerts to usage ping
merge_request: 31802
author:
type: added
......@@ -315,6 +315,7 @@ but commented out to help encourage others to add to it in the future. -->
|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|
|issues_created_gitlab_alerts|counts|monitor|issues created from alerts by non-alert bot users|
|ldap_group_links|counts||
|ldap_keys|counts||
|ldap_users|counts||
......
......@@ -114,6 +114,7 @@ module Gitlab
issues_with_associated_zoom_link: count(ZoomMeeting.added_to_issue),
issues_using_zoom_quick_actions: distinct_count(ZoomMeeting, :issue_id),
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)),
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)),
......
......@@ -28,11 +28,10 @@ FactoryBot.define do
create(:project_error_tracking_setting, project: projects[1], enabled: false)
create(:alerts_service, project: projects[0])
create(:alerts_service, :inactive, project: projects[1])
create_list(:issue, 2, project: projects[0], author: User.alert_bot)
alert_bot_issues = create_list(:issue, 2, project: projects[0], author: User.alert_bot)
create_list(:issue, 2, project: projects[1], author: User.alert_bot)
create_list(:issue, 4, project: projects[0])
create(:prometheus_alert, project: projects[0])
create(:prometheus_alert, project: projects[0])
issues = create_list(:issue, 4, project: projects[0])
create_list(:prometheus_alert, 2, project: projects[0])
create(:prometheus_alert, project: projects[1])
create(:zoom_meeting, project: projects[0], issue: projects[0].issues[0], issue_status: :added)
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[1], issue_status: :removed)
......@@ -50,6 +49,10 @@ FactoryBot.define do
create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_project])
create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_group])
# Alert Issues
create(:alert_management_alert, issue: issues[0], project: projects[0])
create(:alert_management_alert, issue: alert_bot_issues[0], project: projects[0])
# Enabled clusters
gcp_cluster = create(:cluster_provider_gcp, :created).cluster
create(:cluster_provider_aws, :created)
......
......@@ -62,6 +62,7 @@ describe Gitlab::UsageData, :aggregate_failures do
expect(count_data[:issues_using_zoom_quick_actions]).to eq(3)
expect(count_data[:issues_with_embedded_grafana_charts_approx]).to eq(2)
expect(count_data[:incident_issues]).to eq(4)
expect(count_data[:issues_created_gitlab_alerts]).to eq(1)
expect(count_data[:alert_bot_incident_issues]).to eq(4)
expect(count_data[:incident_labeled_issues]).to eq(3)
......
......@@ -80,6 +80,18 @@ describe Issue do
end
end
describe '.with_alert_management_alerts' do
subject { described_class.with_alert_management_alerts }
it 'gets only issues with alerts' do
alert = create(:alert_management_alert, issue: create(:issue))
issue = create(:issue)
expect(subject).to contain_exactly(alert.issue)
expect(subject).not_to include(issue)
end
end
describe 'locking' do
using RSpec::Parameterized::TableSyntax
......
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