2018-11-16 09:02:43 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Prometheus
|
|
|
|
module QueryVariables
|
2020-06-04 02:08:42 -04:00
|
|
|
# start_time and end_time should be Time objects.
|
|
|
|
def self.call(environment, start_time: nil, end_time: nil)
|
2018-11-16 09:02:43 -05:00
|
|
|
{
|
2020-06-04 02:08:42 -04:00
|
|
|
__range: range(start_time, end_time),
|
2018-11-16 09:02:43 -05:00
|
|
|
ci_environment_slug: environment.slug,
|
2019-08-07 00:40:29 -04:00
|
|
|
kube_namespace: environment.deployment_namespace || '',
|
2020-03-09 05:07:45 -04:00
|
|
|
environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
|
|
|
|
ci_project_name: environment.project.name,
|
|
|
|
ci_project_namespace: environment.project.namespace.name,
|
|
|
|
ci_project_path: environment.project.full_path,
|
|
|
|
ci_environment_name: environment.name
|
2018-11-16 09:02:43 -05:00
|
|
|
}
|
|
|
|
end
|
2020-06-04 02:08:42 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def self.range(start_time, end_time)
|
|
|
|
if start_time && end_time
|
|
|
|
range_seconds = (end_time - start_time).to_i
|
|
|
|
"#{range_seconds}s"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
private_class_method :range
|
2018-11-16 09:02:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|