Class: Integrations::Prometheus
- Inherits:
-
BaseMonitoring
- Object
- ActiveRecord::Base
- ApplicationRecord
- Integration
- BaseMonitoring
- Integrations::Prometheus
- Includes:
- Gitlab::Utils::StrongMemoize, PrometheusAdapter
- Defined in:
- app/models/integrations/prometheus.rb
Constant Summary collapse
- MASKED_VALUE =
'*' * 8
Constants included from PrometheusAdapter
PrometheusAdapter::DEFAULT_PROMETHEUS_REQUEST_TIMEOUT_SEC
Constants inherited from Integration
Integration::BASE_CLASSES, Integration::DEV_INTEGRATION_NAMES, Integration::INTEGRATION_NAMES, Integration::PROJECT_SPECIFIC_INTEGRATION_NAMES, Integration::SECTION_TYPE_CONFIGURATION, Integration::SECTION_TYPE_CONNECTION, Integration::SECTION_TYPE_TRIGGER, Integration::SNOWPLOW_EVENT_ACTION, Integration::SNOWPLOW_EVENT_LABEL, Integration::UnknownType
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Instance Attribute Summary
Attributes included from Importable
Class Method Summary collapse
Instance Method Summary collapse
- #allow_local_api_url? ⇒ Boolean
- #configured? ⇒ Boolean
- #description ⇒ Object
- #google_iap_service_account_json ⇒ Object
- #prometheus_available? ⇒ Boolean
- #prometheus_client ⇒ Object
- #show_active_box? ⇒ Boolean
-
#test(*args) ⇒ Object
Check we can connect to the Prometheus API.
- #title ⇒ Object
Methods inherited from BaseMonitoring
#can_query?, #query, supported_events
Methods inherited from Integration
#activate_disabled_reason, #activated?, #api_field_names, #async_execute, #attributes, available_integration_names, available_integration_types, boolean_accessor, build_from_integration, #category, #chat?, #ci?, #configurable_events, create_from_active_default_integrations, default_integration, #default_test_event, default_test_event, dev_integration_names, #dup, #editable?, #event_channel_names, event_description, event_names, #event_names, #execute, field, #fields, fields, find_or_initialize_all_non_project_specific, find_or_initialize_non_project_specific_integration, #form_fields, #group_level?, #help, #inheritable?, inherited_descendants_from_self_or_ancestors_from, #initialize_properties, instance_exists_for?, #instance_level?, integration_name_to_model, integration_name_to_type, integration_names, #json_fields, #operating?, #parent, #project_level?, project_specific_integration_names, prop_accessor, #properties=, #reencrypt_properties, #reset_updated_properties, #secret_fields, #sections, supported_events, #supported_events, #supports_data_fields?, #testable?, #to_database_hash, #to_param, #updated_properties
Methods included from Gitlab::Utils::Override
#extended, extensions, #included, #method_added, #override, #prepended, #queue_verification, verify!
Methods included from ResetSecretFields
Methods included from Loggable
#build_message, #log_error, #log_exception, #log_info, #logger
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Class Method Details
.to_param ⇒ Object
62 63 64 |
# File 'app/models/integrations/prometheus.rb', line 62 def self.to_param 'prometheus' end |
Instance Method Details
#allow_local_api_url? ⇒ Boolean
99 100 101 |
# File 'app/models/integrations/prometheus.rb', line 99 def allow_local_api_url? allow_local_requests_from_web_hooks_and_services? || internal_prometheus_url? end |
#configured? ⇒ Boolean
103 104 105 |
# File 'app/models/integrations/prometheus.rb', line 103 def configured? should_return_client? end |
#description ⇒ Object
58 59 60 |
# File 'app/models/integrations/prometheus.rb', line 58 def description s_('PrometheusService|Monitor application health with Prometheus metrics and dashboards') end |
#google_iap_service_account_json ⇒ Object
112 113 114 115 116 117 118 119 120 121 |
# File 'app/models/integrations/prometheus.rb', line 112 def google_iap_service_account_json json = google_iap_service_account_json_raw return json unless json.present? Gitlab::Json.parse(json) .then { |hash| hash.transform_values { MASKED_VALUE } } .then { |hash| Gitlab::Json.generate(hash) } rescue Gitlab::Json.parser_error json end |
#prometheus_available? ⇒ Boolean
91 92 93 94 95 96 97 |
# File 'app/models/integrations/prometheus.rb', line 91 def prometheus_available? return false unless project project.all_clusters.enabled.eager_load(:integration_prometheus).any? do |cluster| cluster.integration_prometheus_available? end end |
#prometheus_client ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/integrations/prometheus.rb', line 76 def prometheus_client return unless should_return_client? = .merge( allow_local_requests: allow_local_api_url? ) if behind_iap? && iap_client # Adds the Authorization header [:headers] = iap_client.apply({}) end Gitlab::PrometheusClient.new(api_url, ) end |
#show_active_box? ⇒ Boolean
50 51 52 |
# File 'app/models/integrations/prometheus.rb', line 50 def show_active_box? false end |
#test(*args) ⇒ Object
Check we can connect to the Prometheus API
67 68 69 70 71 72 73 74 |
# File 'app/models/integrations/prometheus.rb', line 67 def test(*args) return { success: false, result: 'Prometheus configuration error' } unless prometheus_client prometheus_client.ping { success: true, result: 'Checked API endpoint' } rescue Gitlab::PrometheusClient::Error => e { success: false, result: e } end |
#title ⇒ Object
54 55 56 |
# File 'app/models/integrations/prometheus.rb', line 54 def title 'Prometheus' end |