Class: GitLab::Exporter::ElasticsearchProber

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/elasticsearch.rb

Overview

Exports GitLab specific Elasticsearch metrics.

For generic operational metrics, see elasticsearch_exporter. github.com/prometheus-community/elasticsearch_exporter

Constant Summary collapse

MIGRATION_STATE_MAP =
{
  unknown: -9,
  # TODO: failed: -1
  pending: 0,
  running: 1,
  halted: 2,
  completed: 3
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(metrics: PrometheusMetrics.new, logger: nil, **opts) ⇒ ElasticsearchProber

Returns a new instance of ElasticsearchProber.



22
23
24
25
26
# File 'lib/gitlab_exporter/elasticsearch.rb', line 22

def initialize(metrics: PrometheusMetrics.new, logger: nil, **opts)
  @metrics = metrics
  @logger  = logger
  @opts    = opts
end

Instance Method Details

#probe_migrationsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gitlab_exporter/elasticsearch.rb', line 30

def probe_migrations
  elastic_probe do |conn|
    resp = conn.get "/gitlab-*-migrations/_search"
    return unless resp.status == 200

    JSON.parse(resp.body).dig("hits", "hits").each do |hit|
      @metrics.add(
        "elasticsearch_migrations_info", 1, # 1 is a noop.
        state: inferred_migration_state(hit.fetch("_source")),
        name: hit.fetch("_id")
      )
    end
  end
rescue StandardError => e
  @logger&.error "ElasticsearchProper encountered an error: #{e}"
end