Commit 5618ea7a authored by Vladimir Shushlin's avatar Vladimir Shushlin Committed by Shinya Maeda

Add metric for users associating group milestones to releases

Changelog: added
parent a538eac7
......@@ -34,6 +34,7 @@ class Release < ApplicationRecord
project: [:project_feature, :route, { namespace: :route }])
}
scope :with_milestones, -> { joins(:milestone_releases) }
scope :with_group_milestones, -> { joins(:milestones).where.not(milestones: { group_id: nil }) }
scope :recent, -> { sorted.limit(MAX_NUMBER_TO_DISPLAY) }
scope :without_evidence, -> { left_joins(:evidences).where(::Releases::Evidence.arel_table[:id].eq(nil)) }
scope :released_within_2hrs, -> { where(released_at: Time.zone.now - 1.hour..Time.zone.now + 1.hour) }
......
---
key_path: usage_activity_by_stage_monthly.release.releases_with_group_milestones
description: Unique users creating releases with group milestones associated
product_section: ops
product_stage: release
product_group: 'group::release'
product_category: Release Orchestration
value_type: number
status: active
milestone: "14.4"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71650
time_frame: 28d
data_source: database
instrumentation_class: 'CountUsersAssociatingGroupMilestonesToReleasesMetric'
data_category: optional
performance_indicator_type:
- smau
distribution:
- ee
tier:
- premium
- ultimate
---
key_path: usage_activity_by_stage.release.releases_with_group_milestones
description: Unique users creating releases with group milestones associated
product_section: ops
product_stage: release
product_group: 'group::release'
product_category: Release Orchestration
value_type: number
status: active
milestone: "14.4"
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71650
time_frame: all
data_source: database
instrumentation_class: 'CountUsersAssociatingGroupMilestonesToReleasesMetric'
data_category: optional
performance_indicator_type: []
distribution:
- ee
tier:
- premium
- ultimate
......@@ -344,8 +344,10 @@ module EE
# Omitted because no user, creator or author associated: `environments`, `feature_flags`, `in_review_folder`, `pages_domains`
override :usage_activity_by_stage_release
def usage_activity_by_stage_release(time_period)
time_frame = metric_time_period(time_period)
super.merge({
projects_mirrored_with_pipelines_enabled: distinct_count(::Project.mirrored_with_enabled_pipelines.where(time_period), :creator_id)
projects_mirrored_with_pipelines_enabled: distinct_count(::Project.mirrored_with_enabled_pipelines.where(time_period), :creator_id),
releases_with_group_milestones: add_metric('CountUsersAssociatingGroupMilestonesToReleasesMetric', time_frame: time_frame)
})
end
......
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class CountUsersAssociatingGroupMilestonesToReleasesMetric < DatabaseMetric
operation :distinct_count, column: :author_id
relation { Release.with_group_milestones }
start { Release.minimum(:author_id) }
finish { Release.maximum(:author_id) }
end
end
end
end
end
......@@ -542,15 +542,23 @@ RSpec.describe Gitlab::UsageData do
describe 'usage_activity_by_stage_release' do
it 'includes accurate usage_activity_by_stage data' do
stub_licensed_features(group_milestone_project_releases: true)
group_milestone = create(:milestone, :on_group)
project = create(:project, group: group_milestone.group)
for_defined_days_back do
create(:project, :mirror, mirror_trigger_builds: true)
create(:release, created_at: 3.days.ago, project: project, milestones: [group_milestone])
end
expect(described_class.usage_activity_by_stage_release({})).to include(
projects_mirrored_with_pipelines_enabled: 2
projects_mirrored_with_pipelines_enabled: 2,
releases_with_group_milestones: 2
)
expect(described_class.usage_activity_by_stage_release(described_class.monthly_time_range_db_params)).to include(
projects_mirrored_with_pipelines_enabled: 1
projects_mirrored_with_pipelines_enabled: 1,
releases_with_group_milestones: 1
)
end
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountUsersAssociatingGroupMilestonesToReleasesMetric do
before do
stub_licensed_features(group_milestone_project_releases: true)
end
let(:group_milestone) { create(:milestone, :on_group) }
let(:project) { create(:project, group: group_milestone.group) }
let!(:release) { create(:release, created_at: 3.days.ago) }
let!(:release_with_milestone) { create(:release, :with_milestones, created_at: 3.days.ago) }
let!(:release_with_group_milestone) { create(:release, created_at: 3.days.ago, project: project, milestones: [group_milestone]) }
it_behaves_like 'a correct instrumented metric value', { time_frame: '28d', data_source: 'database' } do
let(:expected_value) { 1 }
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