Sha256: cfa5ad4d839708418511aa58fe25791c3c73b79de89450f4aaa62db51c66b0ab

Contents?: true

Size: 1.08 KB

Versions: 44

Compression:

Stored size: 1.08 KB

Contents

module GitLab
  module Exporter
    # A class to combine multiple probers into one
    class Prober
      def initialize(metrics: PrometheusMetrics.new, logger: nil, **prober_opts)
        @prober_opts = prober_opts
        @metrics     = metrics
        @logger      = logger

        resolve_prober_classes
      end

      def probe_all
        @prober_opts.each do |_probe_name, params|
          Utils.wrap_in_array(params[:opts]).each do |opts|
            prober = params[:class].new(metrics: @metrics, logger: @logger, **opts)
            params[:methods].each do |meth|
              prober.send(meth)
            end
          end
        end
      end

      def write_to(target)
        target.write(@metrics.to_s)
      end

      private

      def resolve_prober_classes
        @prober_opts.each do |probe_name, params|
          prober_class_name = params[:class_name] || Utils.camel_case_string("#{probe_name}_prober")

          klass = prober_class_name.split("::").reduce(GitLab::Exporter) { |a, e| a.const_get(e) }

          params[:class] = klass
        end
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
gitlab-exporter-15.0.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-14.5.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-14.4.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-14.3.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-14.2.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-14.1.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-14.0.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.5.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.4.1 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.4.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.3.1 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.3.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.2.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.1.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.0.3 lib/gitlab_exporter/prober.rb
gitlab-exporter-13.0.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-12.1.1 lib/gitlab_exporter/prober.rb
gitlab-exporter-12.1.0 lib/gitlab_exporter/prober.rb
gitlab-exporter-12.0.1 lib/gitlab_exporter/prober.rb
gitlab-exporter-12.0.0 lib/gitlab_exporter/prober.rb