Commit ebf045fb authored by Allison Browne's avatar Allison Browne Committed by Peter Leitzen

Account for identical group labels

Labels are group or project scoped
parent 1e638da0
......@@ -84,6 +84,7 @@ class Issue < ApplicationRecord
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_label_attributes, ->(label_attributes) { joins(:labels).where(labels: label_attributes) }
scope :public_only, -> { where(confidential: false) }
scope :confidential_only, -> { where(confidential: true) }
......
---
title: Add incident_labeled_issues to usage ping
merge_request: 31406
author:
type: added
......@@ -312,7 +312,9 @@ but commented out to help encourage others to add to it in the future. -->
|epics|counts||
|feature_flags|counts||
|geo_nodes|counts||
|incident_issues|counts||
|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|
|ldap_group_links|counts||
|ldap_keys|counts||
|ldap_users|counts||
......
......@@ -63,6 +63,8 @@ module Gitlab
# rubocop: disable Metrics/AbcSize
# rubocop: disable CodeReuse/ActiveRecord
def system_usage_data
alert_bot_incident_count = count(::Issue.authored(::User.alert_bot))
{
counts: {
assignee_lists: count(List.assignee),
......@@ -112,7 +114,9 @@ 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,
incident_issues: count(::Issue.authored(::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)),
keys: count(Key),
label_lists: count(List.label),
lfs_objects: count(LfsObject),
......
......@@ -40,6 +40,16 @@ FactoryBot.define do
create_list(:zoom_meeting, 2, project: projects[0], issue: projects[0].issues[2], issue_status: :removed)
create(:sentry_issue, issue: projects[0].issues[0])
# Incident Labeled Issues
incident_label_attrs = IncidentManagement::CreateIssueService::INCIDENT_LABEL
incident_label = create(:label, project: projects[0], **incident_label_attrs)
create(:labeled_issue, project: projects[0], labels: [incident_label])
incident_group = create(:group)
incident_label_scoped_to_project = create(:label, project: projects[1], **incident_label_attrs)
incident_label_scoped_to_group = create(:group_label, group: incident_group, **incident_label_attrs)
create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_project])
create(:labeled_issue, project: projects[1], labels: [incident_label_scoped_to_group])
# Enabled clusters
gcp_cluster = create(:cluster_provider_gcp, :created).cluster
create(:cluster_provider_aws, :created)
......
......@@ -62,6 +62,8 @@ 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[:alert_bot_incident_issues]).to eq(4)
expect(count_data[:incident_labeled_issues]).to eq(3)
expect(count_data[:clusters_enabled]).to eq(6)
expect(count_data[:project_clusters_enabled]).to eq(4)
......
......@@ -1030,4 +1030,24 @@ describe Issue do
it { is_expected.to contain_exactly(design_a, design_c) }
end
end
describe '.with_label_attributes' do
subject { described_class.with_label_attributes(label_attributes) }
let(:label_attributes) { { title: 'hello world', description: 'hi' } }
it 'gets issues with given label attributes' do
label = create(:label, **label_attributes)
labeled_issue = create(:labeled_issue, project: label.project, labels: [label])
expect(subject).to include(labeled_issue)
end
it 'excludes issues without given label attributes' do
label = create(:label, title: 'GitLab', description: 'tanuki')
labeled_issue = create(:labeled_issue, project: label.project, labels: [label])
expect(subject).not_to include(labeled_issue)
end
end
end
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