Commit c1b937b2 authored by Matthias Kaeppler's avatar Matthias Kaeppler

Reinstate 60s timeout in Cluster Prometheus

parent 2ca202df
...@@ -106,7 +106,9 @@ module Clusters ...@@ -106,7 +106,9 @@ module Clusters
proxy_url = kube_client.proxy_url('service', service_name, service_port, Gitlab::Kubernetes::Helm::NAMESPACE) proxy_url = kube_client.proxy_url('service', service_name, service_port, Gitlab::Kubernetes::Helm::NAMESPACE)
# ensures headers containing auth data are appended to original k8s client options # ensures headers containing auth data are appended to original k8s client options
options = kube_client.rest_client.options.merge(headers: kube_client.headers) options = kube_client.rest_client.options
.merge(prometheus_client_default_options)
.merge(headers: kube_client.headers)
Gitlab::PrometheusClient.new(proxy_url, options) Gitlab::PrometheusClient.new(proxy_url, options)
rescue Kubeclient::HttpError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENETUNREACH rescue Kubeclient::HttpError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::ENETUNREACH
# If users have mistakenly set parameters or removed the depended clusters, # If users have mistakenly set parameters or removed the depended clusters,
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
module PrometheusAdapter module PrometheusAdapter
extend ActiveSupport::Concern extend ActiveSupport::Concern
# We should choose more conservative timeouts, but some queries we run are now busting our
# default timeouts, which are stricter. We should make those queries faster instead.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/232786
DEFAULT_PROMETHEUS_REQUEST_TIMEOUT_SEC = 60.seconds
included do included do
include ReactiveCaching include ReactiveCaching
...@@ -15,6 +20,12 @@ module PrometheusAdapter ...@@ -15,6 +20,12 @@ module PrometheusAdapter
raise NotImplementedError raise NotImplementedError
end end
def prometheus_client_default_options
{
timeout: DEFAULT_PROMETHEUS_REQUEST_TIMEOUT_SEC
}
end
# This is a light-weight check if a prometheus client is properly configured. # This is a light-weight check if a prometheus client is properly configured.
def configured? def configured?
raise NotImplemented raise NotImplemented
......
...@@ -97,13 +97,9 @@ class PrometheusService < MonitoringService ...@@ -97,13 +97,9 @@ class PrometheusService < MonitoringService
def prometheus_client def prometheus_client
return unless should_return_client? return unless should_return_client?
options = { options = prometheus_client_default_options.merge(
allow_local_requests: allow_local_api_url?, allow_local_requests: allow_local_api_url?
# We should choose more conservative timeouts, but some queries we run are now busting our )
# default timeouts, which are stricter. We should make those queries faster instead.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/233109
timeout: 60
}
if behind_iap? if behind_iap?
# Adds the Authorization header # Adds the Authorization header
......
---
title: Reinstate 60s timeout in Cluster Prometheus
merge_request: 39595
author:
type: other
...@@ -109,10 +109,13 @@ RSpec.describe Clusters::Applications::Prometheus do ...@@ -109,10 +109,13 @@ RSpec.describe Clusters::Applications::Prometheus do
expect(subject.prometheus_client).to be_instance_of(Gitlab::PrometheusClient) expect(subject.prometheus_client).to be_instance_of(Gitlab::PrometheusClient)
end end
it 'copies proxy_url, options and headers from kube client to prometheus_client' do it 'merges proxy_url, options and headers from kube client with prometheus_client options' do
expect(Gitlab::PrometheusClient) expect(Gitlab::PrometheusClient)
.to(receive(:new)) .to(receive(:new))
.with(a_valid_url, kube_client.rest_client.options.merge(headers: kube_client.headers)) .with(a_valid_url, kube_client.rest_client.options.merge({
headers: kube_client.headers,
timeout: PrometheusAdapter::DEFAULT_PROMETHEUS_REQUEST_TIMEOUT_SEC
}))
subject.prometheus_client subject.prometheus_client
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