Commit fb2c4b8e authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'rc/rename-time-params' into 'master'

Rename time window params

Closes #196986

See merge request gitlab-org/gitlab!26333
parents 5d28c06a ea537e11
......@@ -46,8 +46,8 @@ const requestLogsUntilData = state => {
if (state.timeRange.current) {
try {
const { start, end } = convertToFixedRange(state.timeRange.current);
params.start = start;
params.end = end;
params.start_time = start;
params.end_time = end;
} catch {
flashTimeRangeWarning();
}
......
......@@ -86,8 +86,8 @@ export const fetchDashboard = ({ state, commit, dispatch }) => {
if (state.timeRange) {
const { start, end } = convertToFixedRange(state.timeRange);
params.start = start;
params.end = end;
params.start_time = start;
params.end_time = end;
}
if (state.currentDashboard) {
......@@ -139,16 +139,16 @@ function fetchPrometheusResult(prometheusEndpoint, params) {
* @param {metric} metric
*/
export const fetchPrometheusMetric = ({ commit }, { metric, params }) => {
const { start, end } = params;
const timeDiff = (new Date(end) - new Date(start)) / 1000;
const { start_time, end_time } = params;
const timeDiff = (new Date(end_time) - new Date(start_time)) / 1000;
const minStep = 60;
const queryDataPoints = 600;
const step = Math.max(minStep, Math.ceil(timeDiff / queryDataPoints));
const queryParams = {
start,
end,
start_time,
end_time,
step,
};
......
......@@ -48,7 +48,7 @@ module Projects
end
def elasticsearch_params
params.permit(:container_name, :pod_name, :search, :start, :end, :cursor)
params.permit(:container_name, :pod_name, :search, :start_time, :end_time, :cursor)
end
def environment
......
......@@ -16,7 +16,7 @@ module PodLogs
private
def valid_params
super + %w(search start end cursor)
super + %w(search start_time end_time cursor)
end
def success_return_keys
......@@ -24,8 +24,8 @@ module PodLogs
end
def check_times(result)
result[:start] = params['start'] if params.key?('start') && Time.iso8601(params['start'])
result[:end] = params['end'] if params.key?('end') && Time.iso8601(params['end'])
result[:start_time] = params['start_time'] if params.key?('start_time') && Time.iso8601(params['start_time'])
result[:end_time] = params['end_time'] if params.key?('end_time') && Time.iso8601(params['end_time'])
success(result)
rescue ArgumentError
......@@ -53,8 +53,8 @@ module PodLogs
pod_name: result[:pod_name],
container_name: result[:container_name],
search: result[:search],
start_time: result[:start],
end_time: result[:end],
start_time: result[:start_time],
end_time: result[:end_time],
cursor: result[:cursor]
)
......
......@@ -114,11 +114,23 @@ module Prometheus
end
def filter_params(params, path)
params = substitute_params(params)
params.slice(*PROXY_SUPPORT.dig(path, :params))
end
def can_proxy?
PROXY_SUPPORT.dig(@path, :method)&.include?(@method)
end
def substitute_params(params)
start_time = params[:start_time]
end_time = params[:end_time]
params['start'] = start_time if start_time
params['end'] = end_time if end_time
params
end
end
end
......@@ -6,6 +6,7 @@ module Prometheus
steps :validate_variables,
:add_params_to_result,
:substitute_params,
:substitute_ruby_variables,
:substitute_liquid_variables
......@@ -35,6 +36,16 @@ module Prometheus
success(result)
end
def substitute_params(result)
start_time = result[:params][:start_time]
end_time = result[:params][:end_time]
result[:params][:start] = start_time if start_time
result[:params][:end] = end_time if end_time
success(result)
end
def substitute_liquid_variables(result)
return success(result) unless query(result)
......
......@@ -21,7 +21,7 @@ module Gitlab
)
{
ops_rate: transform_rate_result(client_query_range(rate_query, start: from, stop: to)),
ops_rate: transform_rate_result(client_query_range(rate_query, start_time: from, end_time: to)),
ops_total: transform_sum_result(client_query(total_query, time: to))
}
end
......
......@@ -13,8 +13,8 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery do
it 'queries using specific time' do
expect(client).to receive(:query_range).with(anything,
start: (deployment.created_at - 30.minutes).to_f,
stop: (deployment.created_at + 30.minutes).to_f)
start_time: (deployment.created_at - 30.minutes).to_f,
end_time: (deployment.created_at + 30.minutes).to_f)
expect(query_result).not_to be_nil
end
......
......@@ -11,7 +11,7 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do
let(:query_params) { [environment.id] }
it 'queries using specific time' do
expect(client).to receive(:query_range).with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f)
expect(client).to receive(:query_range).with(anything, start_time: 8.hours.ago.to_f, end_time: Time.now.to_f)
expect(query_result).not_to be_nil
end
......
......@@ -20,6 +20,6 @@ describe Gitlab::Prometheus::Queries::ClusterQuery do
it 'sends queries to prometheus' do
subject.query
expect(client).to have_received(:query_range).with(anything, start: 8.hours.ago, stop: Time.now).at_least(1)
expect(client).to have_received(:query_range).with(anything, start_time: 8.hours.ago, end_time: Time.now).at_least(1)
end
end
......@@ -82,7 +82,7 @@ describe Gitlab::Prometheus::Queries::PacketFlowQuery do
context 'ops_rate query' do
it 'sets query time range' do
expect(client).to receive(:query_range).with(anything, start: from, stop: to)
expect(client).to receive(:query_range).with(anything, start_time: from, end_time: to)
subject.query(namespace, from: from, to: to)
end
end
......
......@@ -18,11 +18,11 @@ module Gitlab
timeframe_end = (deployment.created_at + 30.minutes).to_f
{
memory_values: client_query_range(memory_query, start: timeframe_start, stop: timeframe_end),
memory_values: client_query_range(memory_query, start_time: timeframe_start, end_time: timeframe_end),
memory_before: client_query(memory_avg_query, time: deployment.created_at.to_f),
memory_after: client_query(memory_avg_query, time: timeframe_end),
cpu_values: client_query_range(cpu_query, start: timeframe_start, stop: timeframe_end),
cpu_values: client_query_range(cpu_query, start_time: timeframe_start, end_time: timeframe_end),
cpu_before: client_query(cpu_avg_query, time: deployment.created_at.to_f),
cpu_after: client_query(cpu_avg_query, time: timeframe_end)
}
......
......@@ -15,9 +15,9 @@ module Gitlab
cpu_query = raw_cpu_usage_query(environment_slug)
{
memory_values: client_query_range(memory_query, start: timeframe_start, stop: timeframe_end),
memory_values: client_query_range(memory_query, start_time: timeframe_start, end_time: timeframe_end),
memory_current: client_query(memory_query, time: timeframe_end),
cpu_values: client_query_range(cpu_query, start: timeframe_start, stop: timeframe_end),
cpu_values: client_query_range(cpu_query, start_time: timeframe_start, end_time: timeframe_end),
cpu_current: client_query(cpu_query, time: timeframe_end)
}
end
......
......@@ -29,7 +29,7 @@ module Gitlab
def run_query(query, context)
query %= context
client_query_range(query, start: 8.hours.ago.to_f, stop: Time.now.to_f)
client_query_range(query, start_time: 8.hours.ago.to_f, end_time: Time.now.to_f)
end
def self.transform_reactive_result(result)
......
......@@ -43,7 +43,7 @@ module Gitlab
series = metric_groups.flat_map(&:metrics).flat_map(&:required_metrics).uniq
lookup = series.each_slice(MAX_QUERY_ITEMS).flat_map do |batched_series|
client_series(*batched_series, start: timeframe_start, stop: timeframe_end)
client_series(*batched_series, start_time: timeframe_start, end_time: timeframe_end)
.select(&method(:has_matching_label?))
.map { |series_info| [series_info['__name__'], true] }
end
......
......@@ -59,7 +59,7 @@ module Gitlab
result =
if query.key?(:query_range)
query[:query_range] %= context
client_query_range(query[:query_range], start: context[:timeframe_start], stop: context[:timeframe_end])
client_query_range(query[:query_range], start_time: context[:timeframe_start], end_time: context[:timeframe_end])
else
query[:query] %= context
client_query(query[:query], time: context[:timeframe_end])
......
......@@ -47,17 +47,17 @@ module Gitlab
end
end
def query_range(query, start: 8.hours.ago, stop: Time.now)
start = start.to_f
stop = stop.to_f
step = self.class.compute_step(start, stop)
def query_range(query, start_time: 8.hours.ago, end_time: Time.now)
start_time = start_time.to_f
end_time = end_time.to_f
step = self.class.compute_step(start_time, end_time)
get_result('matrix') do
json_api_get(
'query_range',
query: query,
start: start,
end: stop,
start: start_time,
end: end_time,
step: step
)
end
......@@ -67,12 +67,12 @@ module Gitlab
json_api_get("label/#{name}/values")
end
def series(*matches, start: 8.hours.ago, stop: Time.now)
json_api_get('series', 'match': matches, start: start.to_f, end: stop.to_f)
def series(*matches, start_time: 8.hours.ago, end_time: Time.now)
json_api_get('series', 'match': matches, start: start_time.to_f, end: end_time.to_f)
end
def self.compute_step(start, stop)
diff = stop - start
def self.compute_step(start_time, end_time)
diff = end_time - start_time
step = (diff / QUERY_RANGE_DATA_POINTS).ceil
......
......@@ -202,8 +202,8 @@ describe('Logs Store actions', () => {
return testAction(fetchLogs, null, state, expectedMutations, expectedActions, () => {
expect(latestGetParams()).toEqual({
pod_name: mockPodName,
start: mockFixedRange.start,
end: mockFixedRange.end,
start_time: mockFixedRange.start,
end_time: mockFixedRange.end,
cursor: mockCursor,
});
});
......@@ -280,8 +280,8 @@ describe('Logs Store actions', () => {
() => {
expect(latestGetParams()).toEqual({
pod_name: mockPodName,
start: mockFixedRange.start,
end: mockFixedRange.end,
start_time: mockFixedRange.start,
end_time: mockFixedRange.end,
cursor: mockCursor,
});
},
......
......@@ -509,8 +509,8 @@ describe('Monitoring store actions', () => {
});
describe('fetchPrometheusMetric', () => {
const params = {
start: '2019-08-06T12:40:02.184Z',
end: '2019-08-06T20:40:02.184Z',
start_time: '2019-08-06T12:40:02.184Z',
end_time: '2019-08-06T20:40:02.184Z',
};
let metric;
let state;
......
......@@ -14,8 +14,8 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery do
it 'queries using specific time' do
expect(client).to receive(:query_range).with(anything,
start: (deployment.created_at - 30.minutes).to_f,
stop: (deployment.created_at + 30.minutes).to_f)
start_time: (deployment.created_at - 30.minutes).to_f,
end_time: (deployment.created_at + 30.minutes).to_f)
expect(query_result).not_to be_nil
end
......
......@@ -12,7 +12,7 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do
it 'queries using specific time' do
expect(client).to receive(:query_range)
.with(anything, start: 8.hours.ago.to_f, stop: Time.now.to_f)
.with(anything, start_time: 8.hours.ago.to_f, end_time: Time.now.to_f)
expect(query_result).not_to be_nil
end
......@@ -25,7 +25,7 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do
it 'queries using the provided times' do
expect(client).to receive(:query_range)
.with(anything, start: start_time, stop: end_time)
.with(anything, start_time: start_time, end_time: end_time)
expect(query_result).not_to be_nil
end
end
......@@ -36,7 +36,7 @@ describe Gitlab::Prometheus::Queries::AdditionalMetricsEnvironmentQuery do
it 'queries using the provided times converted to unix' do
expect(client).to receive(:query_range)
.with(anything, start: start_time.to_f, stop: end_time.to_f)
.with(anything, start_time: start_time.to_f, end_time: end_time.to_f)
expect(query_result).not_to be_nil
end
end
......
......@@ -16,22 +16,22 @@ describe Gitlab::Prometheus::Queries::DeploymentQuery do
it 'sends appropriate queries to prometheus' do
start_time = (deployment.created_at - 30.minutes).to_f
stop_time = (deployment.created_at + 30.minutes).to_f
end_time = (deployment.created_at + 30.minutes).to_f
created_at = deployment.created_at.to_f
expect(client).to receive(:query_range).with('avg(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}) / 2^20',
start: start_time, stop: stop_time)
start_time: start_time, end_time: end_time)
expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))',
time: created_at)
expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))',
time: stop_time)
time: end_time)
expect(client).to receive(:query_range).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[2m])) * 100',
start: start_time, stop: stop_time)
start_time: start_time, end_time: end_time)
expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100',
time: created_at)
expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100',
time: stop_time)
time: end_time)
expect(subject.query(deployment.id)).to eq(memory_values: nil, memory_before: nil, memory_after: nil,
cpu_values: nil, cpu_before: nil, cpu_after: nil)
......
......@@ -22,7 +22,7 @@ describe Gitlab::Prometheus::Queries::KnativeInvocationQuery do
it 'has the query, but no data' do
expect(client).to receive(:query_range).with(
'sum(ceil(rate(istio_requests_total{destination_service_namespace="test-ns", destination_service=~"test-name.*"}[1m])*60))',
hash_including(:start, :stop)
hash_including(:start_time, :end_time)
)
subject.query(serverless_func.id)
......
......@@ -193,23 +193,23 @@ describe Gitlab::PrometheusClient do
let(:time_stop) { Time.now.in_time_zone("Warsaw") }
let(:time_start) { time_stop - 8.hours }
let(:query_url) { prometheus_query_range_url(prometheus_query, start: time_start.utc.to_f, stop: time_stop.utc.to_f) }
let(:query_url) { prometheus_query_range_url(prometheus_query, start_time: time_start.utc.to_f, end_time: time_stop.utc.to_f) }
it 'passed dates are properly converted to utc' do
req_stub = stub_prometheus_request(query_url, body: prometheus_values_body('vector'))
subject.query_range(prometheus_query, start: time_start, stop: time_stop)
subject.query_range(prometheus_query, start_time: time_start, end_time: time_stop)
expect(req_stub).to have_been_requested
end
end
context 'when a start time is passed' do
let(:query_url) { prometheus_query_range_url(prometheus_query, start: 2.hours.ago) }
let(:query_url) { prometheus_query_range_url(prometheus_query, start_time: 2.hours.ago) }
it 'passed it in the requested URL' do
req_stub = stub_prometheus_request(query_url, body: prometheus_values_body('vector'))
subject.query_range(prometheus_query, start: 2.hours.ago)
subject.query_range(prometheus_query, start_time: 2.hours.ago)
expect(req_stub).to have_been_requested
end
end
......
......@@ -27,8 +27,8 @@ describe ::PodLogs::ElasticsearchService do
context 'with start and end provided and valid' do
let(:params) do
{
'start' => start_time,
'end' => end_time
'start_time' => start_time,
'end_time' => end_time
}
end
......@@ -36,8 +36,8 @@ describe ::PodLogs::ElasticsearchService do
result = subject.send(:check_times, {})
expect(result[:status]).to eq(:success)
expect(result[:start]).to eq(start_time)
expect(result[:end]).to eq(end_time)
expect(result[:start_time]).to eq(start_time)
expect(result[:end_time]).to eq(end_time)
end
end
......@@ -57,8 +57,8 @@ describe ::PodLogs::ElasticsearchService do
context 'with start valid and end invalid' do
let(:params) do
{
'start' => start_time,
'end' => 'invalid date'
'start_time' => start_time,
'end_time' => 'invalid date'
}
end
......@@ -73,8 +73,8 @@ describe ::PodLogs::ElasticsearchService do
context 'with start invalid and end valid' do
let(:params) do
{
'start' => 'invalid date',
'end' => end_time
'start_time' => 'invalid date',
'end_time' => end_time
}
end
......@@ -153,8 +153,8 @@ describe ::PodLogs::ElasticsearchService do
pod_name: pod_name,
container_name: container_name,
search: search,
start: start_time,
end: end_time,
start_time: start_time,
end_time: end_time,
cursor: cursor
}
end
......
......@@ -31,15 +31,15 @@ module PrometheusHelpers
"https://prometheus.example.com/api/v1/query?#{query}"
end
def prometheus_query_range_url(prometheus_query, start: 8.hours.ago, stop: Time.now, step: nil)
start = start.to_f
stop = stop.to_f
step ||= Gitlab::PrometheusClient.compute_step(start, stop)
def prometheus_query_range_url(prometheus_query, start_time: 8.hours.ago, end_time: Time.now, step: nil)
start_time = start_time.to_f
end_time = end_time.to_f
step ||= Gitlab::PrometheusClient.compute_step(start_time, end_time)
query = {
query: prometheus_query,
start: start,
end: stop,
start: start_time,
end: end_time,
step: step
}.to_query
......@@ -50,11 +50,11 @@ module PrometheusHelpers
"https://prometheus.example.com/api/v1/label/#{name}/values"
end
def prometheus_series_url(*matches, start: 8.hours.ago, stop: Time.now)
def prometheus_series_url(*matches, start_time: 8.hours.ago, end_time: Time.now)
query = {
match: matches,
start: start.to_f,
end: stop.to_f
start: start_time.to_f,
end: end_time.to_f
}.to_query
"https://prometheus.example.com/api/v1/series?#{query}"
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