Commit 45d212da authored by Etienne Baqué's avatar Etienne Baqué

Added configured? method to PrometheusAdapter

parent 3cb5e9e0
......@@ -91,6 +91,10 @@ module Clusters
# we need to silence the exceptions
end
def configured?
kube_client.present? && available?
end
private
def disable_prometheus_integration
......
......@@ -16,6 +16,14 @@ module PrometheusAdapter
raise NotImplementedError
end
# This is a light-weight check if a prometheus client is properly configured.
def configured?
raise NotImplemented
end
# This is a heavy-weight check if a prometheus is properly configured and accesible from GitLab.
# This actually sends a request to an external service and often it could take a long time,
# Please consider using `configured?` instead if the process is running on unicorn/puma threads.
def can_query?
prometheus_client.present?
end
......
......@@ -193,11 +193,11 @@ class Environment < ApplicationRecord
end
def has_metrics?
available? && prometheus_adapter&.can_query?
available? && prometheus_adapter&.configured?
end
def metrics
prometheus_adapter.query(:environment, self) if has_metrics?
prometheus_adapter.query(:environment, self) if has_metrics? && prometheus_adapter.can_query?
end
def prometheus_status
......
......@@ -95,6 +95,10 @@ class PrometheusService < MonitoringService
self_monitoring_project? && internal_prometheus_url?
end
def configured?
should_return_client?
end
private
def self_monitoring_project?
......
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