Commit a58f6c53 authored by Mikołaj Wawrzyniak's avatar Mikołaj Wawrzyniak Committed by Peter Leitzen

Handle unknown dashboard attributes

PanelIdInserter stage in dashbaord processing should be prepared to
greacefully handle unknown, wrong dashboard panle attributes,
with out breaking whole breaking whole dashboard. In order to that
we are going to rescue error and silently pass them back to Sentry,
while skipping PanelIdInserter stage for malformed dashboard.
parent f333eb77
......@@ -4,7 +4,7 @@ module PerformanceMonitoring
class PrometheusPanel
include ActiveModel::Model
attr_accessor :type, :title, :y_label, :weight, :metrics, :y_axis
attr_accessor :type, :title, :y_label, :weight, :metrics, :y_axis, :max_value
validates :title, presence: true
validates :metrics, presence: true
......
---
title: Fix dashboard processing error which prevented dashboards with unknown attributes
inside panels from being displayed
merge_request: 29517
author:
type: fixed
......@@ -5,6 +5,7 @@ require 'spec_helper'
describe PerformanceMonitoring::PrometheusPanel do
let(:json_content) do
{
"max_value" => 1,
"type" => "area-chart",
"title" => "Chart Title",
"y_label" => "Y-Axis",
......
......@@ -15,6 +15,9 @@ module Gitlab
insert_panel_id(id, panel)
end
rescue ActiveModel::UnknownAttributeError => error
remove_panel_ids!
Gitlab::ErrorTracking.log_exception(error)
end
private
......
......@@ -8,6 +8,7 @@ panel_groups:
type: "area-chart"
y_label: "y_label"
weight: 1
max_value: 1
metrics:
- id: metric_a1
query_range: 'query'
......
......@@ -11,6 +11,7 @@
"type": { "type": "string" },
"y_label": { "type": "string" },
"y_axis": { "$ref": "axis.json" },
"max_value": { "type": "number" },
"weight": { "type": "number" },
"metrics": {
"type": "array",
......
......@@ -15,7 +15,8 @@ describe Gitlab::Metrics::Dashboard::Processor do
Gitlab::Metrics::Dashboard::Stages::CustomMetricsDetailsInserter,
Gitlab::Metrics::Dashboard::Stages::EndpointInserter,
Gitlab::Metrics::Dashboard::Stages::Sorter,
Gitlab::Metrics::Dashboard::Stages::AlertsInserter
Gitlab::Metrics::Dashboard::Stages::AlertsInserter,
Gitlab::Metrics::Dashboard::Stages::PanelIdsInserter
]
end
......@@ -28,6 +29,12 @@ describe Gitlab::Metrics::Dashboard::Processor do
end
end
it 'includes an id for each dashboard panel' do
expect(all_panels).to satisfy_all do |panel|
panel[:id].present?
end
end
it 'includes boolean to indicate if panel group has custom metrics' do
expect(dashboard[:panel_groups]).to all(include( { has_custom_metrics: boolean } ))
end
......@@ -199,9 +206,11 @@ describe Gitlab::Metrics::Dashboard::Processor do
private
def all_metrics
dashboard[:panel_groups].flat_map do |group|
group[:panels].flat_map { |panel| panel[:metrics] }
end
all_panels.flat_map { |panel| panel[:metrics] }
end
def all_panels
dashboard[:panel_groups].flat_map { |group| group[:panels] }
end
def get_metric_details(metric)
......
......@@ -63,5 +63,24 @@ describe Gitlab::Metrics::Dashboard::Stages::PanelIdsInserter do
)
end
end
context 'when dashboard panels has unknown schema attributes' do
before do
error = ActiveModel::UnknownAttributeError.new(double, 'unknown_panel_attribute')
allow(::PerformanceMonitoring::PrometheusPanel).to receive(:new).and_raise(error)
end
it 'no panel has assigned id' do
transform!
expect(fetch_panel_ids(dashboard)).to all be_nil
end
it 'logs the failure' do
expect(Gitlab::ErrorTracking).to receive(:log_exception)
transform!
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