Class: DatadogBackup::Dashboards

Inherits:
Core
  • Object
show all
Defined in:
lib/datadog_backup/dashboards.rb

Instance Method Summary collapse

Methods inherited from Core

#create, #diff, #except, #get, #get_all, #get_and_write_file, #get_by_id, #myclass, #restore, #update, #with_200

Methods included from Options

#action, #backup_dir, #client, #concurrency_limit, #datadog_api_key, #datadog_app_key, #diff_format, #force_restore, #logger, #output_format, #resources

Methods included from LocalFilesystem

#all_file_ids, #all_file_ids_for_selected_resources, #all_files, #class_from_id, #dump, #file_type, #filename, #find_file_by_id, #load_from_file, #load_from_file_by_id, #mydir, #purge, #write_file

Constructor Details

#initialize(options) ⇒ Dashboards



38
39
40
41
# File 'lib/datadog_backup/dashboards.rb', line 38

def initialize(options)
  super(options)
  @banlist = %w[modified_at url].freeze
end

Instance Method Details

#all_boardsObject



5
6
7
# File 'lib/datadog_backup/dashboards.rb', line 5

def all_boards
  get_all.fetch('dashboards')
end

#api_resource_nameObject



18
19
20
# File 'lib/datadog_backup/dashboards.rb', line 18

def api_resource_name
  'dashboard'
end

#api_serviceObject



9
10
11
12
# File 'lib/datadog_backup/dashboards.rb', line 9

def api_service
  # The underlying class from Dogapi that talks to datadog
  client.instance_variable_get(:@dashboard_service)
end

#api_versionObject



14
15
16
# File 'lib/datadog_backup/dashboards.rb', line 14

def api_version
  'v1'
end

#backupObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/datadog_backup/dashboards.rb', line 22

def backup
  logger.info("Starting diffs on #{::DatadogBackup::ThreadPool::TPOOL.max_length} threads")

  futures = all_boards.map do |board|
    Concurrent::Promises.future_on(::DatadogBackup::ThreadPool::TPOOL, board) do |board|
      id = board['id']
      get_and_write_file(id)
    end
  end

  watcher = ::DatadogBackup::ThreadPool.watcher(logger)
  watcher.join if watcher.status

  Concurrent::Promises.zip(*futures).value!
end