Class: Inspec::Telemetry::Collector

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/inspec/utils/telemetry/collector.rb

Overview

A Singleton collection of data series objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCollector

Returns a new instance of Collector.



12
13
14
15
16
# File 'lib/inspec/utils/telemetry/collector.rb', line 12

def initialize
  @data_series = []
  @telemetry_toggled_off = false
  load_config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/inspec/utils/telemetry/collector.rb', line 10

def config
  @config
end

Instance Method Details

#add_data_series(data_series) ⇒ True

Add a data series to the collection.

Returns:

  • (True)


25
26
27
# File 'lib/inspec/utils/telemetry/collector.rb', line 25

def add_data_series(data_series)
  @data_series << data_series
end

#disable_telemetryObject

A way to disable the telemetry system.



41
42
43
# File 'lib/inspec/utils/telemetry/collector.rb', line 41

def disable_telemetry
  @telemetry_toggled_off = true
end

#find_or_create_data_series(name) ⇒ Inspec::Telemetry::DataSeries

Finds the data series object with the specified name and returns it. If it does not exist then creates a new data series with that name and returns it.



55
56
57
58
59
60
61
62
63
64
# File 'lib/inspec/utils/telemetry/collector.rb', line 55

def find_or_create_data_series(name)
  ds = @data_series.select { |data_series| data_series.name.eql?(name) }
  if ds.empty?
    new_data_series = Inspec::Telemetry::DataSeries.new(name)
    @data_series << new_data_series
    new_data_series
  else
    ds.first
  end
end

#list_data_seriesArray

The entire data series collection.

Returns:

  • (Array)


47
48
49
# File 'lib/inspec/utils/telemetry/collector.rb', line 47

def list_data_series
  @data_series
end

#load_config(config = Inspec::Config.cached) ⇒ Object

Allow loading a configuration, useful when testing.



19
20
21
# File 'lib/inspec/utils/telemetry/collector.rb', line 19

def load_config(config = Inspec::Config.cached)
  @config = config
end

#reset!True

Blanks the contents of the data series collection. Reset telemetry toggle

Returns:

  • (True)


69
70
71
72
# File 'lib/inspec/utils/telemetry/collector.rb', line 69

def reset!
  @data_series = []
  @telemetry_toggled_off = false
end

#telemetry_enabled?True, False

The loaded configuration should have a option to configure telemetry, if not default to false.

Returns:

  • (True, False)


32
33
34
35
36
37
38
# File 'lib/inspec/utils/telemetry/collector.rb', line 32

def telemetry_enabled?
  if @telemetry_toggled_off
    false
  else
    config_telemetry_options.fetch("enable_telemetry", false)
  end
end