Commit 3d0eb50a authored by rpereira2's avatar rpereira2

Add a version number to dashboard cache key

This version number can be incremented when we update the dashboard
so that a new cache key is used. A new cache key ensures that the cache
is regenerated. The old cache key will expire automatically after 2
weeks, since that is the value of the global expires_in configuration.
parent 5221f81a
...@@ -8,6 +8,10 @@ module Metrics ...@@ -8,6 +8,10 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/cluster_metrics.yml' DASHBOARD_PATH = 'config/prometheus/cluster_metrics.yml'
DASHBOARD_NAME = 'Cluster' DASHBOARD_NAME = 'Cluster'
# Update this value when the dashboard content is updated. This will force
# the cache to be regenerated.
DASHBOARD_VERSION = 1
SEQUENCE = [ SEQUENCE = [
STAGES::ClusterEndpointInserter, STAGES::ClusterEndpointInserter,
STAGES::PanelIdsInserter, STAGES::PanelIdsInserter,
...@@ -26,6 +30,12 @@ module Metrics ...@@ -26,6 +30,12 @@ module Metrics
def allowed? def allowed?
true true
end end
private
def dashboard_version
DASHBOARD_VERSION
end
end end
end end
end end
...@@ -5,6 +5,16 @@ module Metrics ...@@ -5,6 +5,16 @@ module Metrics
class PodDashboardService < ::Metrics::Dashboard::PredefinedDashboardService class PodDashboardService < ::Metrics::Dashboard::PredefinedDashboardService
DASHBOARD_PATH = 'config/prometheus/pod_metrics.yml' DASHBOARD_PATH = 'config/prometheus/pod_metrics.yml'
DASHBOARD_NAME = 'Pod Health' DASHBOARD_NAME = 'Pod Health'
# Update this value when the dashboard content is updated. This will force
# the cache to be regenerated.
DASHBOARD_VERSION = 1
private
def dashboard_version
DASHBOARD_VERSION
end
end end
end end
end end
...@@ -32,8 +32,12 @@ module Metrics ...@@ -32,8 +32,12 @@ module Metrics
private private
def dashboard_version
raise NotImplementedError
end
def cache_key def cache_key
"metrics_dashboard_#{dashboard_path}" "metrics_dashboard_#{dashboard_path}_#{dashboard_version}"
end end
def dashboard_path def dashboard_path
......
...@@ -8,6 +8,10 @@ module Metrics ...@@ -8,6 +8,10 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/self_monitoring_default.yml' DASHBOARD_PATH = 'config/prometheus/self_monitoring_default.yml'
DASHBOARD_NAME = N_('Default dashboard') 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
SEQUENCE = [ SEQUENCE = [
STAGES::CustomMetricsInserter, STAGES::CustomMetricsInserter,
STAGES::MetricEndpointInserter, STAGES::MetricEndpointInserter,
...@@ -35,6 +39,12 @@ module Metrics ...@@ -35,6 +39,12 @@ module Metrics
params[:dashboard_path].nil? && params[:environment]&.project&.self_monitoring? params[:dashboard_path].nil? && params[:environment]&.project&.self_monitoring?
end end
end end
private
def dashboard_version
DASHBOARD_VERSION
end
end end
end end
end end
...@@ -8,6 +8,10 @@ module Metrics ...@@ -8,6 +8,10 @@ module Metrics
DASHBOARD_PATH = 'config/prometheus/common_metrics.yml' DASHBOARD_PATH = 'config/prometheus/common_metrics.yml'
DASHBOARD_NAME = N_('Default dashboard') 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
SEQUENCE = [ SEQUENCE = [
STAGES::CommonMetricsInserter, STAGES::CommonMetricsInserter,
STAGES::CustomMetricsInserter, STAGES::CustomMetricsInserter,
...@@ -30,6 +34,12 @@ module Metrics ...@@ -30,6 +34,12 @@ module Metrics
}] }]
end end
end end
private
def dashboard_version
DASHBOARD_VERSION
end
end end
end end
end end
...@@ -40,6 +40,7 @@ RSpec.describe Metrics::Dashboard::ClusterDashboardService, :use_clean_rails_mem ...@@ -40,6 +40,7 @@ RSpec.describe Metrics::Dashboard::ClusterDashboardService, :use_clean_rails_mem
it_behaves_like 'valid dashboard service response' it_behaves_like 'valid dashboard service response'
it_behaves_like 'caches the unprocessed dashboard for subsequent calls' it_behaves_like 'caches the unprocessed dashboard for subsequent calls'
it_behaves_like 'refreshes cache when dashboard_version is changed'
context 'when called with a non-system dashboard' do context 'when called with a non-system dashboard' do
let(:dashboard_path) { 'garbage/dashboard/path' } let(:dashboard_path) { 'garbage/dashboard/path' }
......
...@@ -47,6 +47,7 @@ RSpec.describe Metrics::Dashboard::PodDashboardService, :use_clean_rails_memory_ ...@@ -47,6 +47,7 @@ RSpec.describe Metrics::Dashboard::PodDashboardService, :use_clean_rails_memory_
it_behaves_like 'valid dashboard service response' it_behaves_like 'valid dashboard service response'
it_behaves_like 'caches the unprocessed dashboard for subsequent calls' 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 'updates gitlab_metrics_dashboard_processing_time_ms metric'
end end
end end
...@@ -32,6 +32,7 @@ RSpec.describe Metrics::Dashboard::SelfMonitoringDashboardService, :use_clean_ra ...@@ -32,6 +32,7 @@ RSpec.describe Metrics::Dashboard::SelfMonitoringDashboardService, :use_clean_ra
it_behaves_like 'valid dashboard service response' it_behaves_like 'valid dashboard service response'
it_behaves_like 'raises error for users with insufficient permissions' it_behaves_like 'raises error for users with insufficient permissions'
it_behaves_like 'caches the unprocessed dashboard for subsequent calls' 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 'updates gitlab_metrics_dashboard_processing_time_ms metric'
end end
......
...@@ -28,6 +28,7 @@ RSpec.describe Metrics::Dashboard::SystemDashboardService, :use_clean_rails_memo ...@@ -28,6 +28,7 @@ RSpec.describe Metrics::Dashboard::SystemDashboardService, :use_clean_rails_memo
it_behaves_like 'valid dashboard service response' it_behaves_like 'valid dashboard service response'
it_behaves_like 'raises error for users with insufficient permissions' it_behaves_like 'raises error for users with insufficient permissions'
it_behaves_like 'caches the unprocessed dashboard for subsequent calls' 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 'updates gitlab_metrics_dashboard_processing_time_ms metric'
context 'when called with a non-system dashboard' do context 'when called with a non-system dashboard' do
......
...@@ -39,6 +39,22 @@ RSpec.shared_examples 'caches the unprocessed dashboard for subsequent calls' do ...@@ -39,6 +39,22 @@ RSpec.shared_examples 'caches the unprocessed dashboard for subsequent calls' do
end end
end end
# This spec is applicable for predefined/out-of-the-box dashboard services.
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)
end
expect(File).to receive(:read).twice.and_call_original
service = described_class.new(*service_params)
service.get_dashboard
service.get_dashboard
end
end
RSpec.shared_examples 'valid embedded dashboard service response' do 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')) } 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