Class: DatadogBackup::Dashboards

Inherits:
Resources show all
Defined in:
lib/datadog_backup/dashboards.rb

Overview

Dashboards specific overrides for backup and restore.

Constant Summary

Constants inherited from Resources

Resources::RETRY_OPTIONS

Instance Method Summary collapse

Methods inherited from Resources

#body_with_2xx, #create, #diff, #except, #get, #get_all, #get_and_write_file, #myclass, #restore, #update

Methods included from Options

#action, #backup_dir, #concurrency_limit, #diff_format, #disable_array_sort, #force_restore, #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

Returns a new instance of Dashboards.



34
35
36
37
# File 'lib/datadog_backup/dashboards.rb', line 34

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

Instance Method Details

#allObject



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

def all
  get_all.fetch('dashboards')
end

#backupObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/datadog_backup/dashboards.rb', line 10

def backup
  LOGGER.info("Starting diffs on #{::DatadogBackup::ThreadPool::TPOOL.max_length} threads")
  futures = all.map do |dashboard|
    Concurrent::Promises.future_on(::DatadogBackup::ThreadPool::TPOOL, dashboard) do |board|
      id = board[id_keyname]
      get_and_write_file(id)
    end
  end

  watcher = ::DatadogBackup::ThreadPool.watcher
  watcher.join if watcher.status

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

#get_by_id(id) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/datadog_backup/dashboards.rb', line 25

def get_by_id(id)
  begin
    dashboard = except(get(id))
  rescue Faraday::ResourceNotFound => e
    dashboard = {}
  end
  except(dashboard)
end