Commit 851a2efd authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'eb-prometheus-monitoring-report-parsers' into 'master'

Instrument CI parsers

See merge request gitlab-org/gitlab!51241
parents bb44d1fa b45ecb95
---
title: Instrument CI parsers
merge_request: 51241
author:
type: added
...@@ -53,6 +53,8 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled? ...@@ -53,6 +53,8 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
if Gitlab.ee? && Gitlab::Runtime.sidekiq? if Gitlab.ee? && Gitlab::Runtime.sidekiq?
Gitlab::Metrics::Samplers::GlobalSearchSampler.instance.start Gitlab::Metrics::Samplers::GlobalSearchSampler.instance.start
end end
Gitlab::Ci::Parsers.instrument!
rescue IOError => e rescue IOError => e
Gitlab::ErrorTracking.track_exception(e) Gitlab::ErrorTracking.track_exception(e)
Gitlab::Metrics.error_detected! Gitlab::Metrics.error_detected!
...@@ -72,6 +74,8 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled? ...@@ -72,6 +74,8 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
unless Gitlab::Runtime.sidekiq? unless Gitlab::Runtime.sidekiq?
Gitlab::Metrics::RequestsRackMiddleware.initialize_metrics Gitlab::Metrics::RequestsRackMiddleware.initialize_metrics
end end
Gitlab::Ci::Parsers.instrument!
rescue IOError => e rescue IOError => e
Gitlab::ErrorTracking.track_exception(e) Gitlab::ErrorTracking.track_exception(e)
Gitlab::Metrics.error_detected! Gitlab::Metrics.error_detected!
......
...@@ -20,6 +20,10 @@ module Gitlab ...@@ -20,6 +20,10 @@ module Gitlab
rescue KeyError rescue KeyError
raise ParserNotFoundError, "Cannot find any parser matching file type '#{file_type}'" raise ParserNotFoundError, "Cannot find any parser matching file type '#{file_type}'"
end end
def self.instrument!
parsers.values.each { |parser_class| parser_class.prepend(Parsers::Instrumentation) }
end
end end
end end
end end
......
# frozen_string_literal: true
module Gitlab
module Ci
module Parsers
module Instrumentation
BUCKETS = [0.25, 1, 5, 10].freeze
def parse!(*args)
parser_result = nil
duration = Benchmark.realtime do
parser_result = super
end
labels = {}
histogram = Gitlab::Metrics.histogram(
:ci_report_parser_duration_seconds,
'Duration of parsing a CI report artifact',
labels,
BUCKETS
)
histogram.observe({ parser: self.class.name }, duration)
parser_result
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Parsers::Instrumentation do
describe '#parse!' do
let(:parser_class) do
Class.new do
prepend Gitlab::Ci::Parsers::Instrumentation
def parse!(arg1, arg2)
"parse #{arg1} #{arg2}"
end
end
end
it 'sets metrics for duration of parsing' do
result = parser_class.new.parse!('hello', 'world')
expect(result).to eq('parse hello world')
metrics = Gitlab::Metrics.registry.get(:ci_report_parser_duration_seconds).get({ parser: parser_class.name })
expect(metrics.keys).to match_array(described_class::BUCKETS)
end
end
end
...@@ -54,4 +54,12 @@ RSpec.describe Gitlab::Ci::Parsers do ...@@ -54,4 +54,12 @@ RSpec.describe Gitlab::Ci::Parsers do
end end
end end
end end
describe '.instrument!' do
it 'prepends the Instrumentation module into each parser' do
expect(described_class.parsers.values).to all( receive(:prepend).with(Gitlab::Ci::Parsers::Instrumentation) )
described_class.instrument!
end
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