• Bob Van Landuyt's avatar
    Add request urgency to logs and metrics · 17ec208c
    Bob Van Landuyt authored
    This adds the request urgency to logs by adding a `request_urgency`
    and a `request_urgency_s` fields. The duration in seconds will make it
    easier to build dashboards showing SLIs that don't meet SLO without
    having to copy the information in the runbooks.
    
    The way fields are added to logs is slighty refacotred and tests
    added extended.
    
    The `rails_request_apdex` metrics get initialized and emitted with an
    `urgency` label.
    17ec208c
urgency_logger_spec.rb 1.34 KB
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::GrapeLogging::Loggers::UrgencyLogger do
  def endpoint(options, namespace: '')
    Struct.new(:options, :namespace).new(options, namespace)
  end

  let(:api_class) do
    Class.new(API::Base) do
      namespace 'testing' do
        # rubocop:disable Rails/HttpPositionalArguments
        # This is not the get that performs a request, but the one from Grape
        get 'test', urgency: :high do
          {}
        end
        # rubocop:enable Rails/HttpPositionalArguments
      end
    end
  end

  describe ".parameters" do
    where(:request_env, :expected_parameters) do
      [
        [{}, {}],
        [{ 'api.endpoint' => endpoint({}) }, {}],
        [{ 'api.endpoint' => endpoint({ for: 'something weird' }) }, {}],
        [
          { 'api.endpoint' => endpoint({ for: api_class, path: [] }) },
          { request_urgency: :default, target_duration_s: 1 }
        ],
        [
          { 'api.endpoint' => endpoint({ for: api_class, path: ['test'] }, namespace: '/testing') },
          { request_urgency: :high, target_duration_s: 0.25 }
        ]
      ]
    end

    with_them do
      let(:request) { double('request', env: request_env) }

      subject { described_class.new.parameters(request, nil) }

      it { is_expected.to eq(expected_parameters) }
    end
  end
end