Commit 57b6e1f6 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'add-instrumentation-class-for-licence-management-jobs' into 'master'

Add LicenceManagementJobs instrumentation class

See merge request gitlab-org/gitlab!72083
parents 95bbd574 dcb14460
...@@ -171,6 +171,7 @@ module Ci ...@@ -171,6 +171,7 @@ module Ci
scope :with_live_trace, -> { where('EXISTS (?)', Ci::BuildTraceChunk.where('ci_builds.id = ci_build_trace_chunks.build_id').select(1)) } scope :with_live_trace, -> { where('EXISTS (?)', Ci::BuildTraceChunk.where('ci_builds.id = ci_build_trace_chunks.build_id').select(1)) }
scope :with_stale_live_trace, -> { with_live_trace.finished_before(12.hours.ago) } scope :with_stale_live_trace, -> { with_live_trace.finished_before(12.hours.ago) }
scope :finished_before, -> (date) { finished.where('finished_at < ?', date) } scope :finished_before, -> (date) { finished.where('finished_at < ?', date) }
scope :license_management_jobs, -> { where(name: %i(license_management license_scanning)) } # handle license rename https://gitlab.com/gitlab-org/gitlab/issues/8911
scope :with_secure_reports_from_config_options, -> (job_types) do scope :with_secure_reports_from_config_options, -> (job_types) do
joins(:metadata).where("ci_builds_metadata.config_options -> 'artifacts' -> 'reports' ?| array[:job_types]", job_types: job_types) joins(:metadata).where("ci_builds_metadata.config_options -> 'artifacts' -> 'reports' ?| array[:job_types]", job_types: job_types)
......
...@@ -6,6 +6,7 @@ product_stage: secure ...@@ -6,6 +6,7 @@ product_stage: secure
product_group: group::composition analysis product_group: group::composition analysis
product_category: license_compliance product_category: license_compliance
value_type: number value_type: number
instrumentation_class: LicenseManagementJobsMetric
status: active status: active
time_frame: all time_frame: all
data_source: database data_source: database
......
...@@ -144,13 +144,12 @@ module EE ...@@ -144,13 +144,12 @@ module EE
def security_products_usage def security_products_usage
results = SECURE_PRODUCT_TYPES.each_with_object({}) do |(secure_type, attribs), response| results = SECURE_PRODUCT_TYPES.each_with_object({}) do |(secure_type, attribs), response|
next if secure_type == :license_management
response[attribs[:name]] = count(::Ci::Build.where(name: secure_type)) # rubocop:disable CodeReuse/ActiveRecord response[attribs[:name]] = count(::Ci::Build.where(name: secure_type)) # rubocop:disable CodeReuse/ActiveRecord
end end
# handle license rename https://gitlab.com/gitlab-org/gitlab/issues/8911 results[:license_management_jobs] = add_metric("LicenseManagementJobsMetric")
license_scan_count = results.delete(:license_scanning_jobs)
results[:license_management_jobs] += license_scan_count > 0 ? license_scan_count : 0 if license_scan_count.is_a?(Integer)
results results
end end
......
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Instrumentations
class LicenseManagementJobsMetric < DatabaseMetric
operation :count
relation { ::Ci::Build.license_management_jobs }
end
end
end
end
end
...@@ -8,6 +8,7 @@ RSpec.describe 'Every metric definition' do ...@@ -8,6 +8,7 @@ RSpec.describe 'Every metric definition' do
let(:usage_ping) { Gitlab::UsageData.uncached_data } let(:usage_ping) { Gitlab::UsageData.uncached_data }
let(:ignored_usage_ping_key_patterns) do let(:ignored_usage_ping_key_patterns) do
%w( %w(
counts.license_scanning_jobs
license_add_ons license_add_ons
testing_total_unique_counts testing_total_unique_counts
user_auth_by_provider user_auth_by_provider
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Usage::Metrics::Instrumentations::LicenseManagementJobsMetric do
before do
create(:ci_build, name: :license_management)
end
it_behaves_like 'a correct instrumented metric value', { time_frame: 'none', data_source: 'ruby' } do
let(:expected_value) { 1 }
end
end
...@@ -215,6 +215,26 @@ RSpec.describe Ci::Build do ...@@ -215,6 +215,26 @@ RSpec.describe Ci::Build do
end end
end end
describe '.license_management_jobs' do
subject { described_class.license_management_jobs }
let!(:management_build) { create(:ci_build, :success, name: :license_management) }
let!(:scanning_build) { create(:ci_build, :success, name: :license_scanning) }
let!(:another_build) { create(:ci_build, :success, name: :another_type) }
it 'returns license_scanning jobs' do
is_expected.to include(scanning_build)
end
it 'returns license_management jobs' do
is_expected.to include(management_build)
end
it 'doesnt return filtered out jobs' do
is_expected.not_to include(another_build)
end
end
describe '.finished_before' do describe '.finished_before' do
subject { described_class.finished_before(date) } subject { described_class.finished_before(date) }
......
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