Class: DatadogExporter::Client::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog_exporter/client/config.rb

Overview

The configuration for the DatadogExporter::Client.

Constant Summary collapse

DEFAULT_ORGANIZATIONS_CONFIGURATIONS =
{
  monitors: {
    export_tag: "",
    template_keys: [],
    placeholders: {
      base: {
      },
    },
  },
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Config

NOTE: See DatadogExporter::Configurations to see the available options



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/datadog_exporter/client/config.rb', line 22

def initialize(**options) # rubocop:disable Metrics/AbcSize
  @site = options[:site] || DatadogExporter.configuration.site
  @api_key = options[:api_key] || DatadogExporter.configuration.api_key
  @application_key =
    options[:application_key] || DatadogExporter.configuration.application_key
  @logger = options[:logger] || DatadogExporter.configuration.logger
  @base_path = options[:base_path] || DatadogExporter.configuration.base_path
  @organizations_config_filename =
    options[:org_config_filename] ||
      DatadogExporter.configuration.organizations_config_filename
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



19
20
21
# File 'lib/datadog_exporter/client/config.rb', line 19

def logger
  @logger
end

Instance Method Details

#base_pathObject



34
35
36
# File 'lib/datadog_exporter/client/config.rb', line 34

def base_path
  Pathname.new(@base_path)
end

#datadog_api_configurationObject



41
42
43
44
45
46
47
# File 'lib/datadog_exporter/client/config.rb', line 41

def datadog_api_configuration
  DatadogAPIClient::Configuration.new do |client_config|
    client_config.server_variables[:site] = @site
    client_config.api_key = @api_key
    client_config.application_key = @application_key
  end
end

#organizations_configObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog_exporter/client/config.rb', line 49

def organizations_config
  organizations_config_file = base_path.join(@organizations_config_filename)

  unless File.exist?(organizations_config_file)
    warn(
      "WARNING: Organizations configuration file not found: #{organizations_config_file}. Using default configuration.",
    )
    return DEFAULT_ORGANIZATIONS_CONFIGURATIONS
  end

  DEFAULT_ORGANIZATIONS_CONFIGURATIONS.merge(YAML.load_file(organizations_config_file))
end