gitlab-org--gitlab-foss/lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb
syasonik ab1e1b55a8 Specify time window for additional metrics api
Adds support for start and end parameters in the #additional_metrics
endpoint of the EnvironmentsController. start and end are meant to be
unix timestamps, per the Prometheus API (as the consumer of this
endpoint will eventually be transitioned to a prometheus endpoint).
This functionality is behind the :metrics_time_window feature flag
for development.
2019-04-03 17:21:56 +08:00

27 lines
788 B
Ruby

# frozen_string_literal: true
module Gitlab
module Prometheus
module Queries
class AdditionalMetricsEnvironmentQuery < BaseQuery
include QueryAdditionalMetrics
# rubocop: disable CodeReuse/ActiveRecord
def query(environment_id, timeframe_start = 8.hours.ago, timeframe_end = Time.now)
::Environment.find_by(id: environment_id).try do |environment|
query_metrics(
environment.project,
environment,
common_query_context(
environment,
timeframe_start: timeframe_start.to_f,
timeframe_end: timeframe_end.to_f
)
)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end