Commit c3a09f0c authored by rpereira2's avatar rpereira2

Set dashboard_version string to be SHA256 hash of dashboard content

Set the dashboard_version string to be a SHA256 hash of the dashboard
content. This also allows us to create a spec that checks that
dashboard_version is updated when the dashboard content is updated.
parent 3d0eb50a
......@@ -8,9 +8,8 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/cluster_metrics.yml'
DASHBOARD_NAME = 'Cluster'
# Update this value when the dashboard content is updated. This will force
# the cache to be regenerated.
DASHBOARD_VERSION = 1
# SHA256 hash of dashboard content
DASHBOARD_VERSION = '9349afc1d96329c08ab478ea0b77db94ee5cc2549b8c754fba67a7f424666b22'
SEQUENCE = [
STAGES::ClusterEndpointInserter,
......
......@@ -6,9 +6,8 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/pod_metrics.yml'
DASHBOARD_NAME = 'Pod Health'
# Update this value when the dashboard content is updated. This will force
# the cache to be regenerated.
DASHBOARD_VERSION = 1
# SHA256 hash of dashboard content
DASHBOARD_VERSION = 'f12f641d2575d5dcb69e2c633ff5231dbd879ad35020567d8fc4e1090bfdb4b4'
private
......
......@@ -8,9 +8,8 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/self_monitoring_default.yml'
DASHBOARD_NAME = N_('Default dashboard')
# Update this value when the dashboard content is updated. This will force
# the cache to be regenerated.
DASHBOARD_VERSION = 1
# SHA256 hash of dashboard content
DASHBOARD_VERSION = '1dff3e3cb76e73c8e368823c98b34c61aec0d141978450dea195a3b3dc2415d6'
SEQUENCE = [
STAGES::CustomMetricsInserter,
......
......@@ -8,9 +8,8 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/common_metrics.yml'
DASHBOARD_NAME = N_('Default dashboard')
# Update this value when the dashboard content is updated. This will force
# the cache to be regenerated.
DASHBOARD_VERSION = 1
# SHA256 hash of dashboard content
DASHBOARD_VERSION = '4685fe386c25b1a786b3be18f79bb2ee9828019003e003816284cdb634fa3e13'
SEQUENCE = [
STAGES::CommonMetricsInserter,
......
......@@ -36,12 +36,19 @@ RSpec.describe Metrics::Dashboard::ClusterDashboardService, :use_clean_rails_mem
describe '#get_dashboard' do
let(:service_params) { [project, user, { cluster: cluster, cluster_type: :project }] }
let(:service_call) { described_class.new(*service_params).get_dashboard }
let(:service_call) { subject.get_dashboard }
subject { described_class.new(*service_params) }
it_behaves_like 'valid dashboard service response'
it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
it_behaves_like 'refreshes cache when dashboard_version is changed'
it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do
let(:dashboard_path) { described_class::DASHBOARD_PATH }
let(:dashboard_version) { subject.send(:dashboard_version) }
end
context 'when called with a non-system dashboard' do
let(:dashboard_path) { 'garbage/dashboard/path' }
......
......@@ -49,5 +49,9 @@ RSpec.describe Metrics::Dashboard::PodDashboardService, :use_clean_rails_memory_
it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
it_behaves_like 'refreshes cache when dashboard_version is changed'
it_behaves_like 'updates gitlab_metrics_dashboard_processing_time_ms metric'
it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do
let(:dashboard_version) { subject.send(:dashboard_version) }
end
end
end
......@@ -34,6 +34,11 @@ RSpec.describe Metrics::Dashboard::SelfMonitoringDashboardService, :use_clean_ra
it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
it_behaves_like 'refreshes cache when dashboard_version is changed'
it_behaves_like 'updates gitlab_metrics_dashboard_processing_time_ms metric'
it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do
let(:dashboard_path) { described_class::DASHBOARD_PATH }
let(:dashboard_version) { subject.send(:dashboard_version) }
end
end
describe '.all_dashboard_paths' do
......
......@@ -31,6 +31,10 @@ RSpec.describe Metrics::Dashboard::SystemDashboardService, :use_clean_rails_memo
it_behaves_like 'refreshes cache when dashboard_version is changed'
it_behaves_like 'updates gitlab_metrics_dashboard_processing_time_ms metric'
it_behaves_like 'dashboard_version contains SHA256 hash of dashboard file content' do
let(:dashboard_version) { subject.send(:dashboard_version) }
end
context 'when called with a non-system dashboard' do
let(:dashboard_path) { 'garbage/dashboard/path' }
......
......@@ -43,7 +43,7 @@ end
RSpec.shared_examples 'refreshes cache when dashboard_version is changed' do
specify do
allow_next_instance_of(described_class) do |service|
allow(service).to receive(:dashboard_version).and_return(1, 2)
allow(service).to receive(:dashboard_version).and_return('1', '2')
end
expect(File).to receive(:read).twice.and_call_original
......@@ -55,6 +55,17 @@ RSpec.shared_examples 'refreshes cache when dashboard_version is changed' do
end
end
# This spec is applicable for predefined/out-of-the-box dashboard services.
# This shared_example requires the following variables to be defined:
# dashboard_path: Relative path to the dashboard, ex: 'config/prometheus/common_metrics.yml'
# dashboard_version: The version string used in the cache_key.
RSpec.shared_examples 'dashboard_version contains SHA256 hash of dashboard file content' do
specify do
dashboard = File.read(Rails.root.join(dashboard_path))
expect(Digest::SHA256.hexdigest(dashboard)).to eq(dashboard_version)
end
end
RSpec.shared_examples 'valid embedded dashboard service response' do
let(:dashboard_schema) { Gitlab::Json.parse(fixture_file('lib/gitlab/metrics/dashboard/schemas/embedded_dashboard.json')) }
......
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