aboutsummaryrefslogtreecommitdiff
path: root/examples/test_config.rb
blob: b5a1418637881a064eb72a42b5b276022cebd79e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'yaml'

class TestConfig
  def initialize(collector, config)
    @collector = collector
    @config = config
    @config.merge!(Longboat::Config.for_raider do
      opt :test_config, "Config file for test_config", type: String
    end)

    @name = "configurable_value"
    @config_file = {}
    @config_file = YAML.load_file(@config[:test_config]) if @config[:test_config]
  end

  def raid
    # Clean up any previously reported metrics
    # to prevent stale labelsets
    @collector.redact!(@name)

    # Report new metrics
    value = @config_file["configurable_value"] || 4
    @collector.report!(
      @name,
      value,
      help: "A value specified on the command line at runtime",
      type: "gauge",
      labels: {
        given: @config[:test_config_given] ? 1 : 0
      }
    )
  end
end