Commit e67b03bf authored by Sincheol (David) Kim's avatar Sincheol (David) Kim

Merge branch '342694-reduce-error-rate-in-SyncDashboardsWorker' into 'master'

Prevent raising validation errors for SyncDashboardsWorker

See merge request gitlab-org/gitlab!77657
parents a0ae18a7 e7f36851
...@@ -18,7 +18,7 @@ module Metrics ...@@ -18,7 +18,7 @@ module Metrics
dashboard_paths = ::Gitlab::Metrics::Dashboard::RepoDashboardFinder.list_dashboards(project) dashboard_paths = ::Gitlab::Metrics::Dashboard::RepoDashboardFinder.list_dashboards(project)
dashboard_paths.each do |dashboard_path| dashboard_paths.each do |dashboard_path|
::Gitlab::Metrics::Dashboard::Importer.new(dashboard_path, project).execute! ::Gitlab::Metrics::Dashboard::Importer.new(dashboard_path, project).execute
end end
end end
end end
......
...@@ -10,6 +10,7 @@ RSpec.describe Metrics::Dashboard::SyncDashboardsWorker do ...@@ -10,6 +10,7 @@ RSpec.describe Metrics::Dashboard::SyncDashboardsWorker do
let(:dashboard_path) { '.gitlab/dashboards/test.yml' } let(:dashboard_path) { '.gitlab/dashboards/test.yml' }
describe ".perform" do describe ".perform" do
context 'with valid dashboard hash' do
it 'imports metrics' do it 'imports metrics' do
expect { worker.perform(project.id) }.to change(PrometheusMetric, :count).by(3) expect { worker.perform(project.id) }.to change(PrometheusMetric, :count).by(3)
end end
...@@ -22,4 +23,21 @@ RSpec.describe Metrics::Dashboard::SyncDashboardsWorker do ...@@ -22,4 +23,21 @@ RSpec.describe Metrics::Dashboard::SyncDashboardsWorker do
expect(PrometheusMetric.count).to eq(3) expect(PrometheusMetric.count).to eq(3)
end end
end end
context 'with invalid dashboard hash' do
before do
allow_next_instance_of(Gitlab::Metrics::Dashboard::Importer) do |instance|
allow(instance).to receive(:dashboard_hash).and_return({})
end
end
it 'does not import metrics' do
expect { worker.perform(project.id) }.not_to change(PrometheusMetric, :count)
end
it 'does not raise an error' do
expect { worker.perform(project.id) }.not_to raise_error
end
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