Commit 9bfb012a authored by Sean McGivern's avatar Sean McGivern

Add top-level warnings key to performance bar response

This key is useful to reduce the amount of logic needed on the frontend:
if `has_warnings` is true, then the frontend knows that the request in
question has warnings for some metric.
parent 23c1cfcc
require 'peek/adapters/redis' require 'peek/adapters/redis'
Peek::Adapters::Redis.prepend ::Gitlab::PerformanceBar::RedisAdapterWhenPeekEnabled Peek::Adapters::Redis.prepend ::Gitlab::PerformanceBar::RedisAdapterWhenPeekEnabled
Peek.singleton_class.prepend ::Gitlab::PerformanceBar::WithTopLevelWarnings
Rails.application.config.peek.adapter = :redis, { client: ::Redis.new(Gitlab::Redis::Cache.params) } Rails.application.config.peek.adapter = :redis, { client: ::Redis.new(Gitlab::Redis::Cache.params) }
......
# frozen_string_literal: true
module Gitlab
module PerformanceBar
module WithTopLevelWarnings
def results
results = super
results.merge(has_warnings: has_warnings?(results))
end
def has_warnings?(results)
results[:data].any? do |_, value|
value[:warnings].present?
end
end
end
end
end
# frozen_string_literal: true
require 'fast_spec_helper'
require 'rspec-parameterized'
describe Gitlab::PerformanceBar::WithTopLevelWarnings do
using RSpec::Parameterized::TableSyntax
subject { Module.new }
before do
subject.singleton_class.prepend(described_class)
end
describe '#has_warnings?' do
where(:has_warnings, :results) do
false | { data: {} }
false | { data: { gitaly: { warnings: [] } } }
true | { data: { gitaly: { warnings: [1] } } }
true | { data: { gitaly: { warnings: [] }, redis: { warnings: [1] } } }
end
with_them do
it do
expect(subject.has_warnings?(results)).to eq(has_warnings)
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