Commit 4419cbca authored by Pawel Chojnacki's avatar Pawel Chojnacki

Convert repository update mirror and stuck import jobs metrics to prometheus

- Fix Geo tests accessing private methods to test if metrics were collected

- Readd add_event_with_values method in influx metrics

- Fix metrics_update_service_spec by allowing access to private method

- stop using .send to access private method in tests
parent dfabadf1
......@@ -48,6 +48,8 @@ class RepositoryUpdateMirrorWorker
def start_mirror(project)
if start(project)
Rails.logger.info("Mirror update for #{project.full_path} started. Waiting duration: #{project.mirror_waiting_duration}")
metric_mirror_waiting_duration_seconds.observe({}, project.mirror_waiting_duration)
Gitlab::Metrics.add_event_with_values(
:mirrors_running,
{ duration: project.mirror_waiting_duration },
......@@ -76,5 +78,25 @@ class RepositoryUpdateMirrorWorker
:mirrors_finished,
{ duration: project.mirror_update_duration },
{ path: project.full_path })
metric_mirror_update_duration_seconds.observe({}, project.mirror_update_duration)
end
def metric_mirror_update_duration_seconds
@metric_mirror_update_duration_seconds ||= Gitlab::Metrics.histogram(
:gitlab_repository_mirror_update_duration_seconds,
'Mirror update duration',
{},
[0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0, 50.0, 100.0]
)
end
def metric_mirror_waiting_duration_seconds
@metric_mirror_waiting_duration_seconds ||= Gitlab::Metrics.histogram(
:gitlab_repository_mirror_waiting_duration_seconds,
'Waiting length for repository mirror',
{},
[0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.500, 2.0, 10.0]
)
end
end
......@@ -5,12 +5,19 @@ class StuckImportJobsWorker
IMPORT_JOBS_EXPIRATION = 15.hours.to_i
def perform
projects_without_jid_count = mark_projects_without_jid_as_failed!
projects_with_jid_count = mark_projects_with_jid_as_failed!
values = {
projects_without_jid_count: mark_projects_without_jid_as_failed!,
projects_with_jid_count: mark_projects_with_jid_as_failed!
projects_without_jid_count: projects_without_jid_count,
projects_with_jid_count: projects_with_jid_count
}
Gitlab::Metrics.add_event_with_values(:stuck_import_jobs, values)
stuck_import_jobs_worker_runs_counter.increment
projects_without_jid_metric.set({}, projects_without_jid_count)
projects_with_jid_metric.set({}, projects_with_jid_count)
end
private
......@@ -58,4 +65,17 @@ class StuckImportJobsWorker
def error_message
"Import timed out. Import took longer than #{IMPORT_JOBS_EXPIRATION} seconds"
end
def stuck_import_jobs_worker_runs_counter
@stuck_import_jobs_worker_runs_counter ||= Gitlab::Metrics.counter(:gitlab_stuck_import_jobs_worker_runs_total,
'Stuck import jobs worker runs count')
end
def projects_without_jid_metric
@projects_without_jid_metric ||= Gitlab::Metrics.gauge(:gitlab_projects_without_jid, 'Projects without Job ids')
end
def projects_with_jid_metric
@projects_with_jid_metric ||= Gitlab::Metrics.gauge(:gitlab_projects_with_jid, 'Projects with Job ids')
end
end
......@@ -72,6 +72,8 @@ module Gitlab
@metrics << Metric.new(EVENT_SERIES, { count: 1 }, tags.merge(event: event_name), :event)
end
#
# Deprecated
def add_event_with_values(event_name, values, tags = {})
@metrics << Metric.new(EVENT_SERIES,
{ count: 1 }.merge(values),
......
......@@ -46,10 +46,10 @@ describe Geo::MetricsUpdateService, :geo do
it 'attempts to retrieve metrics from all nodes' do
subject.execute
expect(Gitlab::Metrics.provide_metric(:geo_db_replication_lag_seconds).values.count).to eq(2)
expect(Gitlab::Metrics.provide_metric(:geo_repositories).values.count).to eq(2)
expect(Gitlab::Metrics.provide_metric(:geo_repositories).get({ url: secondary.url })).to eq(10)
expect(Gitlab::Metrics.provide_metric(:geo_repositories).get({ url: secondary.url })).to eq(10)
expect(Gitlab::Metrics.registry.get(:geo_db_replication_lag_seconds).values.count).to eq(2)
expect(Gitlab::Metrics.registry.get(:geo_repositories).values.count).to eq(2)
expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: secondary.url })).to eq(10)
expect(Gitlab::Metrics.registry.get(:geo_repositories).get({ url: secondary.url })).to eq(10)
end
end
......@@ -92,7 +92,7 @@ describe Geo::MetricsUpdateService, :geo do
end
def metric_value(metric_name)
Gitlab::Metrics.provide_metric(metric_name).get({ url: secondary.url })
Gitlab::Metrics.registry.get(metric_name).get({ url: secondary.url })
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