Skip to content

Commit feb94e8

Browse files
committed
Move timeframe_start and timeframe_end to common query context
1 parent b243c3e commit feb94e8

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

lib/gitlab/prometheus/queries/additional_metrics_deployment_query.rb

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ class AdditionalMetricsDeploymentQuery < BaseQuery
66

77
def query(deployment_id)
88
Deployment.find_by(id: deployment_id).try do |deployment|
9-
query_context = common_query_context(deployment.environment).merge(
10-
{
9+
query_metrics(
10+
common_query_context(
11+
deployment.environment,
1112
timeframe_start: (deployment.created_at - 30.minutes).to_f,
1213
timeframe_end: (deployment.created_at + 30.minutes).to_f
13-
}
14+
)
1415
)
15-
16-
query_metrics(query_context)
1716
end
1817
end
1918
end

lib/gitlab/prometheus/queries/additional_metrics_environment_query.rb

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ class AdditionalMetricsEnvironmentQuery < BaseQuery
66

77
def query(environment_id)
88
Environment.find_by(id: environment_id).try do |environment|
9-
query_context = common_query_context(environment).merge(
10-
{
11-
timeframe_start: 8.hours.ago.to_f,
12-
timeframe_end: Time.now.to_f
13-
}
14-
)
15-
16-
query_metrics(query_context)
9+
query_metrics(common_query_context(environment))
1710
end
1811
end
1912
end

lib/gitlab/prometheus/queries/query_additional_metrics.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ def matched_metrics
7171
result.select { |group| group.metrics.any? }
7272
end
7373

74-
def common_query_context(environment)
74+
def common_query_context(environment, timeframe_start: 8.hours.ago.to_f, timeframe_end: Time.now.to_f)
7575
{
76+
timeframe_start: timeframe_start,
77+
timeframe_end: timeframe_end,
7678
ci_environment_slug: environment.slug,
7779
kube_namespace: environment.project.kubernetes_service&.actual_namespace || '',
7880
environment_filter: %{container_name!="POD",environment="#{environment.slug}"}

0 commit comments

Comments
 (0)