summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/graphql/tracing_spec.rb
blob: 7300a9a572e5955998b313a66f2fc85c96853fc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::Graphql::Tracing do
  let(:graphql_duration_seconds_histogram) { double('Gitlab::Metrics::NullMetric') }

  it 'updates graphql histogram with expected labels' do
    query = 'query { users { id } }'
    tracer = described_class.new

    allow(tracer)
      .to receive(:graphql_duration_seconds)
      .and_return(graphql_duration_seconds_histogram)

    expect_metric('graphql.lex', 'lex')
    expect_metric('graphql.parse', 'parse')
    expect_metric('graphql.validate', 'validate')
    expect_metric('graphql.analyze', 'analyze_multiplex')
    expect_metric('graphql.execute', 'execute_query_lazy')
    expect_metric('graphql.execute', 'execute_multiplex')

    GitlabSchema.execute(query, context: { tracers: [tracer] })
  end

  private

  def expect_metric(platform_key, key)
    expect(graphql_duration_seconds_histogram)
      .to receive(:observe)
      .with({ platform_key: platform_key, key: key }, be > 0.0)
  end
end