gitlab-org--gitlab-foss/spec/lib/gitlab/graphql/tracing_spec.rb
Jan Provaznik 0e66357a3e Monitor GraphQL with Prometheus
Extends graphql's platform tracing class to observe duration
of graphql methods.

In graphql 1.8.11 is added prometheus class but it's not very useful
for us because it uses prometheus_exporter to export results.
2019-04-02 10:26:53 +00:00

35 lines
986 B
Ruby

# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Graphql::Tracing do
let!(:graphql_duration_seconds) { double('Gitlab::Metrics::NullMetric') }
before do
allow(Gitlab::Metrics)
.to receive(:histogram)
.with(:graphql_duration_seconds, 'GraphQL execution time')
.and_return(graphql_duration_seconds)
end
it 'updates graphql histogram with expected labels' do
query = 'query { users { id } }'
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)
end
private
def expect_metric(platform_key, key)
expect(graphql_duration_seconds)
.to receive(:observe)
.with({ platform_key: platform_key, key: key }, be > 0.0)
end
end