Commit ef8cfe08 authored by Catalin Irimie's avatar Catalin Irimie

Update unit to seconds in GraphQL logs

We changed the unit name but the duration conversion is happening
from seconds to nanoseconds instead of leaving as seconds as the field
is now called.
parent f0805a8b
...@@ -52,8 +52,7 @@ module Gitlab ...@@ -52,8 +52,7 @@ module Gitlab
end end
def duration(time_started) def duration(time_started)
nanoseconds = Gitlab::Metrics::System.monotonic_time - time_started Gitlab::Metrics::System.monotonic_time - time_started
nanoseconds * 1000000
end end
def default_initial_values(query) def default_initial_values(query)
......
...@@ -17,9 +17,27 @@ RSpec.describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do ...@@ -17,9 +17,27 @@ RSpec.describe Gitlab::Graphql::QueryAnalyzers::LoggerAnalyzer do
end end
context 'feature flag enabled by default' do context 'feature flag enabled by default' do
let(:monotonic_time_before) { 42 }
let(:monotonic_time_after) { 500 }
let(:monotonic_time_duration) { monotonic_time_after - monotonic_time_before }
it 'enables the analyzer' do it 'enables the analyzer' do
expect(subject.analyze?(anything)).to be_truthy expect(subject.analyze?(anything)).to be_truthy
end end
it 'returns a duration in seconds' do
allow(GraphQL::Analysis).to receive(:analyze_query).and_return([4, 2])
allow(Gitlab::Metrics::System).to receive(:monotonic_time).and_return(monotonic_time_before, monotonic_time_after)
allow(Gitlab::GraphqlLogger).to receive(:info)
expected_duration = monotonic_time_duration
memo = subject.initial_value(spy('query'))
subject.final_value(memo)
expect(memo).to have_key(:duration_s)
expect(memo[:duration_s]).to eq(expected_duration)
end
end end
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