datadog_backup 3.0.0.alpha.2 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec_and_release.yml +0 -2
- data/.gitignore +3 -1
- data/.rubocop.yml +36 -77
- data/CHANGELOG.md +39 -0
- data/README.md +2 -2
- data/bin/datadog_backup +7 -5
- data/datadog_backup.gemspec +3 -4
- data/lib/datadog_backup/cli.rb +47 -51
- data/lib/datadog_backup/dashboards.rb +21 -16
- data/lib/datadog_backup/deprecations.rb +4 -5
- data/lib/datadog_backup/local_filesystem.rb +4 -5
- data/lib/datadog_backup/monitors.rb +16 -13
- data/lib/datadog_backup/options.rb +1 -0
- data/lib/datadog_backup/resources.rb +176 -0
- data/lib/datadog_backup/synthetics.rb +68 -0
- data/lib/datadog_backup/thread_pool.rb +1 -0
- data/lib/datadog_backup/version.rb +1 -1
- data/lib/datadog_backup.rb +3 -3
- data/release.config.js +4 -0
- data/spec/datadog_backup/cli_spec.rb +67 -46
- data/spec/datadog_backup/core_spec.rb +72 -51
- data/spec/datadog_backup/dashboards_spec.rb +17 -32
- data/spec/datadog_backup/deprecations_spec.rb +7 -9
- data/spec/datadog_backup/local_filesystem_spec.rb +42 -42
- data/spec/datadog_backup/monitors_spec.rb +13 -29
- data/spec/datadog_backup/synthetics_spec.rb +258 -0
- data/spec/datadog_backup_bin_spec.rb +17 -15
- data/spec/spec_helper.rb +69 -5
- metadata +13 -21
- data/Gemfile.lock +0 -118
- data/lib/datadog_backup/core.rb +0 -148
- data/spec/datadog_backup_spec.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 332899376b51dd8ad98dda7a3528b7a7c80ca8cbbd2c4bbe9c2cb9976a1c7024
|
4
|
+
data.tar.gz: 68b89a77b5148006b16388c7a93241ca50fcecb6bc4edc09ab36cf34a80d92e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab35b9e6a6152cc22ff3de7714ed60f2bca54c056a510d5726e5d33921a0f54d088195bfd7b992494545ccdfa8350e99e097c19155cfde4f7396049aeaad9650
|
7
|
+
data.tar.gz: 4f2f791146658c9a9e4185ef3bda43180a5ef46938dd6b2754aa493bcac9949f19a53f70b972a125ae51ad7b71f6f8c309767d83654e40a4d7d5f4be70e6c39c
|
@@ -25,7 +25,6 @@ jobs:
|
|
25
25
|
run: |
|
26
26
|
bundle exec rspec --format documentation --require spec_helper
|
27
27
|
release:
|
28
|
-
if: github.event_name == 'push'
|
29
28
|
needs: rspec
|
30
29
|
runs-on: ubuntu-latest
|
31
30
|
env:
|
@@ -36,7 +35,6 @@ jobs:
|
|
36
35
|
uses: ruby/setup-ruby@v1
|
37
36
|
with:
|
38
37
|
ruby-version: 2.7
|
39
|
-
bundler-cache: true
|
40
38
|
- name: Zip
|
41
39
|
run : |
|
42
40
|
zip -r datadog_backup.zip ./*
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,78 +1,37 @@
|
|
1
|
-
|
1
|
+
# The behavior of RuboCop can be controlled via the .rubocop.yml
|
2
|
+
# configuration file. It makes it possible to enable/disable
|
3
|
+
# certain cops (checks) and to alter their behavior if they accept
|
4
|
+
# any parameters. The file can be placed either in your home
|
5
|
+
# directory or in some project directory.
|
6
|
+
#
|
7
|
+
# RuboCop will start looking for the configuration file in the directory
|
8
|
+
# where the inspected file is and continue its way up to the root directory.
|
9
|
+
#
|
10
|
+
# See https://docs.rubocop.org/rubocop/configuration
|
11
|
+
require:
|
12
|
+
- rubocop-rspec
|
2
13
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
Layout/
|
8
|
-
Enabled:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
Enabled:
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Enabled:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
Enabled:
|
27
|
-
Lint/NumberedParameterAssignment: # (new in 1.9)
|
28
|
-
Enabled: true
|
29
|
-
Lint/OrAssignmentToConstant: # (new in 1.9)
|
30
|
-
Enabled: true
|
31
|
-
Lint/RedundantDirGlobSort: # (new in 1.8)
|
32
|
-
Enabled: true
|
33
|
-
Lint/SymbolConversion: # (new in 1.9)
|
34
|
-
Enabled: true
|
35
|
-
Lint/ToEnumArguments: # (new in 1.1)
|
36
|
-
Enabled: true
|
37
|
-
Lint/TripleQuotes: # (new in 1.9)
|
38
|
-
Enabled: true
|
39
|
-
Lint/UnexpectedBlockArity: # (new in 1.5)
|
40
|
-
Enabled: true
|
41
|
-
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
42
|
-
Enabled: true
|
43
|
-
Naming/InclusiveLanguage: # (new in 1.18)
|
44
|
-
Enabled: true
|
45
|
-
Style/ArgumentsForwarding: # (new in 1.1)
|
46
|
-
Enabled: true
|
47
|
-
Style/CollectionCompact: # (new in 1.2)
|
48
|
-
Enabled: true
|
49
|
-
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
50
|
-
Enabled: true
|
51
|
-
Style/EndlessMethod: # (new in 1.8)
|
52
|
-
Enabled: true
|
53
|
-
Style/HashConversion: # (new in 1.10)
|
54
|
-
Enabled: true
|
55
|
-
Style/HashExcept: # (new in 1.7)
|
56
|
-
Enabled: true
|
57
|
-
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
58
|
-
Enabled: true
|
59
|
-
Style/InPatternThen: # (new in 1.16)
|
60
|
-
Enabled: true
|
61
|
-
Style/MultilineInPatternThen: # (new in 1.16)
|
62
|
-
Enabled: true
|
63
|
-
Style/NegatedIfElseCondition: # (new in 1.2)
|
64
|
-
Enabled: true
|
65
|
-
Style/NilLambda: # (new in 1.3)
|
66
|
-
Enabled: true
|
67
|
-
Style/QuotedSymbols: # (new in 1.16)
|
68
|
-
Enabled: true
|
69
|
-
Style/RedundantArgument: # (new in 1.4)
|
70
|
-
Enabled: true
|
71
|
-
Style/StringChars: # (new in 1.12)
|
72
|
-
Enabled: true
|
73
|
-
Style/SwapValues: # (new in 1.1)
|
74
|
-
Enabled: true
|
75
|
-
RSpec/IdenticalEqualityAssertion: # (new in 2.4)
|
76
|
-
Enabled: true
|
77
|
-
RSpec/Rails/AvoidSetupHook: # (new in 2.4)
|
78
|
-
Enabled: true
|
14
|
+
AllCops:
|
15
|
+
TargetRubyVersion: 2.7
|
16
|
+
NewCops: enable
|
17
|
+
|
18
|
+
Layout/LineLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/BlockLength:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Metrics/ClassLength:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Naming/AccessorMethodName:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
RSpec/MultipleMemoizedHelpers:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
RSpec/ExampleLength:
|
37
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,42 @@
|
|
1
|
+
## [3.1.1](https://github.com/scribd/datadog_backup/compare/v3.1.0...v3.1.1) (2022-09-01)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* catch SystemExit so that rspec can complete ([9eee0e5](https://github.com/scribd/datadog_backup/commit/9eee0e5c5ea857baeafcf3fbc0f1c8f3748b0ca8))
|
7
|
+
* specify minimum ruby version in Gemfile ([c7f48f9](https://github.com/scribd/datadog_backup/commit/c7f48f95269a23549e28576434292d4ba1332d59))
|
8
|
+
|
9
|
+
|
10
|
+
### Reverts
|
11
|
+
|
12
|
+
* Revert "fix: specify minimum ruby version in Gemfile" ([e934ac2](https://github.com/scribd/datadog_backup/commit/e934ac2611c9bb557a181dd2f6f6b2678287773d))
|
13
|
+
|
14
|
+
# [3.1.0](https://github.com/scribd/datadog_backup/compare/v3.0.0...v3.1.0) (2022-08-30)
|
15
|
+
|
16
|
+
|
17
|
+
### Features
|
18
|
+
|
19
|
+
* backup and restore synthetics ([#139](https://github.com/scribd/datadog_backup/issues/139)) ([a46cadc](https://github.com/scribd/datadog_backup/commit/a46cadc7d196dcb0f20bf31d06cde6a13a390835))
|
20
|
+
|
21
|
+
# [3.0.0](https://github.com/scribd/datadog_backup/compare/v2.0.2...v3.0.0) (2022-08-25)
|
22
|
+
|
23
|
+
|
24
|
+
* feat!: release 3.0 (#136) ([3d23b03](https://github.com/scribd/datadog_backup/commit/3d23b03668e888886f394de2fa4884aa1e3ca287)), closes [#136](https://github.com/scribd/datadog_backup/issues/136)
|
25
|
+
|
26
|
+
|
27
|
+
### BREAKING CHANGES
|
28
|
+
|
29
|
+
* DATADOG_API_KEY and DATADOG_APP_KEY are no longer the environment variables used to authenticate to Datadog. Instead, set the environment variables DD_API_KEY and DD_APP_KEY.
|
30
|
+
* ruby 2.6 is no longer supported. Please upgrade to ruby 2.7 or higher.
|
31
|
+
* The options `--ssh` and `--ssshh` are no longer supported. Instead, please use `--quiet` to supress logging. `--debug` remains supported.
|
32
|
+
* The environment variable `DATADOG_HOST` is no longer supported. Instead, please use `DD_SITE_URL`.
|
33
|
+
|
34
|
+
refactor: The legacy [dogapi-rb ](https://github.com/DataDog/dogapi-rb) gem is replaced with [faraday](https://lostisland.github.io/faraday/). The [official client library](https://github.com/DataDog/datadog-api-client-ruby) was considered, but was not adopted as I had a hard time grok-ing it.
|
35
|
+
|
36
|
+
* chore: permit logging from tests, but only error+
|
37
|
+
|
38
|
+
Co-authored-by: semantic-release-bot <semantic-release-bot@martynus.net>
|
39
|
+
|
1
40
|
# [3.0.0-alpha.2](https://github.com/scribd/datadog_backup/compare/v3.0.0-alpha.1...v3.0.0-alpha.2) (2022-08-25)
|
2
41
|
|
3
42
|
|
data/README.md
CHANGED
@@ -16,7 +16,7 @@ Additional features may be built out over time.
|
|
16
16
|
## Breaking Changes
|
17
17
|
v3 is a backwards incompatible change.
|
18
18
|
|
19
|
-
- [] DATADOG_API_KEY and DATADOG_APP_KEY are no longer the environment variables used to authenticate to Datadog. Instead, set the environment variables DD_API_KEY and DD_APP_KEY.
|
19
|
+
- [ ] DATADOG_API_KEY and DATADOG_APP_KEY are no longer the environment variables used to authenticate to Datadog. Instead, set the environment variables DD_API_KEY and DD_APP_KEY.
|
20
20
|
- [ ] ruby 2.6 is no longer supported. Please upgrade to ruby 2.7 or higher.
|
21
21
|
- [ ] The options `--ssh` and `--ssshh` are no longer supported. Instead, please use `--quiet` to supress logging. `--debug` remains supported.
|
22
22
|
- [ ] The environment variable `DATADOG_HOST` is no longer supported. Instead, please use `DD_SITE_URL`.
|
@@ -86,7 +86,7 @@ DD_API_KEY | The Application key for the Datadog account
|
|
86
86
|
|
87
87
|
### Usage in a Github repo
|
88
88
|
|
89
|
-
See [example/](https://github.com/scribd/datadog_backup/tree/
|
89
|
+
See [example/](https://github.com/scribd/datadog_backup/tree/main/example) for an example implementation as a repo that backs up your Datadog dashboards hourly.
|
90
90
|
|
91
91
|
# Development
|
92
92
|
|
data/bin/datadog_backup
CHANGED
@@ -11,7 +11,6 @@ LOGGER.level = Logger::INFO
|
|
11
11
|
|
12
12
|
require 'datadog_backup'
|
13
13
|
|
14
|
-
|
15
14
|
def fatal(message)
|
16
15
|
LOGGER.fatal(message)
|
17
16
|
exit 1
|
@@ -19,10 +18,10 @@ end
|
|
19
18
|
|
20
19
|
def options_valid?(options)
|
21
20
|
%w[backup diffs restore].include?(options[:action])
|
22
|
-
%w[DD_API_KEY DD_APP_KEY].all? { |key| ENV
|
21
|
+
%w[DD_API_KEY DD_APP_KEY].all? { |key| ENV.fetch(key, nil) }
|
23
22
|
end
|
24
23
|
|
25
|
-
def prereqs(defaults)
|
24
|
+
def prereqs(defaults) # rubocop:disable Metrics/AbcSize
|
26
25
|
ARGV << '--help' if ARGV.empty?
|
27
26
|
|
28
27
|
result = defaults.dup
|
@@ -49,6 +48,9 @@ def prereqs(defaults)
|
|
49
48
|
opts.on('--dashboards-only') do
|
50
49
|
result[:resources] = [DatadogBackup::Dashboards]
|
51
50
|
end
|
51
|
+
opts.on('--synthetics-only') do
|
52
|
+
result[:resources] = [DatadogBackup::Synthetics]
|
53
|
+
end
|
52
54
|
opts.on(
|
53
55
|
'--json',
|
54
56
|
'format backups as JSON instead of YAML. Does not impact `diffs` nor `restore`, but do not mix formats in the same backup-dir.'
|
@@ -78,9 +80,9 @@ defaults = {
|
|
78
80
|
action: nil,
|
79
81
|
backup_dir: File.join(ENV.fetch('PWD'), 'backup'),
|
80
82
|
diff_format: :color,
|
81
|
-
resources: [DatadogBackup::Dashboards, DatadogBackup::Monitors],
|
83
|
+
resources: [DatadogBackup::Dashboards, DatadogBackup::Monitors, DatadogBackup::Synthetics],
|
82
84
|
output_format: :yaml,
|
83
85
|
force_restore: false
|
84
86
|
}
|
85
87
|
|
86
|
-
DatadogBackup::Cli.new(prereqs(defaults)).run!
|
88
|
+
DatadogBackup::Cli.new(prereqs(defaults)).run!
|
data/datadog_backup.gemspec
CHANGED
@@ -13,13 +13,13 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.description = 'A utility to backup and restore Datadog accounts'
|
14
14
|
spec.homepage = 'https://github.com/scribd/datadog_backup'
|
15
15
|
spec.license = 'MIT'
|
16
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
16
17
|
|
17
18
|
spec.files = `git ls-files -z`.split("\x0")
|
18
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
-
spec.test_files = spec.files.grep(%r{^spec/})
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
|
-
spec.required_ruby_version =
|
22
|
+
spec.required_ruby_version = '>= 2.7'
|
23
23
|
|
24
24
|
spec.add_dependency 'amazing_print'
|
25
25
|
spec.add_dependency 'concurrent-ruby'
|
@@ -28,11 +28,10 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency 'faraday'
|
29
29
|
spec.add_dependency 'faraday-retry'
|
30
30
|
|
31
|
-
|
32
31
|
spec.add_development_dependency 'bundler'
|
32
|
+
spec.add_development_dependency 'guard-rspec'
|
33
33
|
spec.add_development_dependency 'pry'
|
34
34
|
spec.add_development_dependency 'pry-byebug'
|
35
|
-
spec.add_development_dependency 'guard-rspec'
|
36
35
|
spec.add_development_dependency 'rspec'
|
37
36
|
spec.add_development_dependency 'rubocop'
|
38
37
|
spec.add_development_dependency 'rubocop-rspec'
|
data/lib/datadog_backup/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require 'optparse'
|
|
4
4
|
require 'amazing_print'
|
5
5
|
|
6
6
|
module DatadogBackup
|
7
|
+
# CLI is the command line interface for the datadog_backup gem.
|
7
8
|
class Cli
|
8
9
|
include ::DatadogBackup::Options
|
9
10
|
|
@@ -11,9 +12,9 @@ module DatadogBackup
|
|
11
12
|
LOGGER.info("Starting diffs on #{::DatadogBackup::ThreadPool::TPOOL.max_length} threads")
|
12
13
|
any_resource_instance
|
13
14
|
.all_file_ids_for_selected_resources
|
14
|
-
.map do |
|
15
|
-
Concurrent::Promises.future_on(::DatadogBackup::ThreadPool::TPOOL,
|
16
|
-
[
|
15
|
+
.map do |file_id|
|
16
|
+
Concurrent::Promises.future_on(::DatadogBackup::ThreadPool::TPOOL, file_id) do |fid|
|
17
|
+
[fid, getdiff(fid)]
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
@@ -32,32 +33,17 @@ module DatadogBackup
|
|
32
33
|
matching_resource_instance(any_resource_instance.class_from_id(id))
|
33
34
|
end
|
34
35
|
|
35
|
-
def diffs
|
36
|
-
futures = all_diff_futures
|
37
|
-
::DatadogBackup::ThreadPool.watcher.join
|
38
|
-
|
39
|
-
format_diff_output(
|
40
|
-
Concurrent::Promises
|
41
|
-
.zip(*futures)
|
42
|
-
.value!
|
43
|
-
.compact
|
44
|
-
)
|
45
|
-
end
|
46
|
-
|
47
36
|
def getdiff(id)
|
48
37
|
result = definitive_resource_instance(id).diff(id)
|
49
38
|
case result
|
50
|
-
when ''
|
51
|
-
nil
|
52
|
-
when "\n"
|
53
|
-
nil
|
54
|
-
when '<div class="diff"></div>'
|
39
|
+
when '---' || '' || "\n" || '<div class="diff"></div>'
|
55
40
|
nil
|
56
41
|
else
|
57
42
|
result
|
58
43
|
end
|
59
44
|
end
|
60
45
|
|
46
|
+
# rubocop:disable Style/StringConcatenation
|
61
47
|
def format_diff_output(diff_output)
|
62
48
|
case diff_format
|
63
49
|
when nil, :color
|
@@ -69,58 +55,31 @@ module DatadogBackup
|
|
69
55
|
Diffy::CSS +
|
70
56
|
'</style></head><body>' +
|
71
57
|
diff_output.map do |id, diff|
|
72
|
-
"<br><br> ---<br><strong> id: #{id}</strong><br
|
58
|
+
"<br><br> ---<br><strong> id: #{id}</strong><br>#{diff}"
|
73
59
|
end.join('<br>') +
|
74
60
|
'</body></html>'
|
75
61
|
else
|
76
62
|
raise 'Unexpected diff_format.'
|
77
63
|
end
|
78
64
|
end
|
65
|
+
# rubocop:enable Style/StringConcatenation
|
79
66
|
|
80
67
|
def initialize(options)
|
81
68
|
@options = options
|
82
69
|
end
|
83
70
|
|
84
|
-
def matching_resource_instance(klass)
|
85
|
-
resource_instances.select { |resource_instance| resource_instance.instance_of?(klass) }.first
|
86
|
-
end
|
87
|
-
|
88
|
-
def resource_instances
|
89
|
-
@resource_instances ||= resources.map do |resource|
|
90
|
-
resource.new(@options)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
71
|
def restore
|
95
72
|
futures = all_diff_futures
|
96
73
|
watcher = ::DatadogBackup::ThreadPool.watcher
|
97
74
|
|
98
75
|
futures.each do |future|
|
99
76
|
id, diff = *future.value!
|
100
|
-
next
|
77
|
+
next if diff.nil? || diff.empty?
|
101
78
|
|
102
79
|
if @options[:force_restore]
|
103
80
|
definitive_resource_instance(id).restore(id)
|
104
81
|
else
|
105
|
-
|
106
|
-
puts format_diff_output([id, diff])
|
107
|
-
puts '(r)estore to Datadog, overwrite local changes and (d)ownload, (s)kip, or (q)uit?'
|
108
|
-
response = $stdin.gets.chomp
|
109
|
-
case response
|
110
|
-
when 'q'
|
111
|
-
exit
|
112
|
-
when 'r'
|
113
|
-
puts "Restoring #{id} to Datadog."
|
114
|
-
definitive_resource_instance(id).restore(id)
|
115
|
-
when 'd'
|
116
|
-
puts "Downloading #{id} from Datadog."
|
117
|
-
definitive_resource_instance(id).get_and_write_file(id)
|
118
|
-
when 's'
|
119
|
-
next
|
120
|
-
else
|
121
|
-
puts 'Invalid response, please try again.'
|
122
|
-
response = $stdin.gets.chomp
|
123
|
-
end
|
82
|
+
ask_to_restore(id, diff)
|
124
83
|
end
|
125
84
|
end
|
126
85
|
watcher.join if watcher.status
|
@@ -131,5 +90,42 @@ module DatadogBackup
|
|
131
90
|
rescue SystemExit, Interrupt
|
132
91
|
::DatadogBackup::ThreadPool.shutdown
|
133
92
|
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def ask_to_restore(id, diff)
|
97
|
+
puts '--------------------------------------------------------------------------------'
|
98
|
+
puts format_diff_output([id, diff])
|
99
|
+
puts '(r)estore to Datadog, overwrite local changes and (d)ownload, (s)kip, or (q)uit?'
|
100
|
+
loop do
|
101
|
+
response = $stdin.gets.chomp
|
102
|
+
case response
|
103
|
+
when 'q'
|
104
|
+
exit
|
105
|
+
when 'r'
|
106
|
+
puts "Restoring #{id} to Datadog."
|
107
|
+
definitive_resource_instance(id).restore(id)
|
108
|
+
break
|
109
|
+
when 'd'
|
110
|
+
puts "Downloading #{id} from Datadog."
|
111
|
+
definitive_resource_instance(id).get_and_write_file(id)
|
112
|
+
break
|
113
|
+
when 's'
|
114
|
+
break
|
115
|
+
else
|
116
|
+
puts 'Invalid response, please try again.'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def matching_resource_instance(klass)
|
122
|
+
resource_instances.select { |resource_instance| resource_instance.instance_of?(klass) }.first
|
123
|
+
end
|
124
|
+
|
125
|
+
def resource_instances
|
126
|
+
@resource_instances ||= resources.map do |resource|
|
127
|
+
resource.new(@options)
|
128
|
+
end
|
129
|
+
end
|
134
130
|
end
|
135
131
|
end
|
@@ -1,22 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DatadogBackup
|
4
|
-
|
5
|
-
|
6
|
-
def
|
7
|
-
'
|
8
|
-
end
|
9
|
-
|
10
|
-
def api_resource_name
|
11
|
-
'dashboard'
|
4
|
+
# Dashboards specific overrides for backup and restore.
|
5
|
+
class Dashboards < Resources
|
6
|
+
def all
|
7
|
+
get_all.fetch('dashboards')
|
12
8
|
end
|
13
9
|
|
14
10
|
def backup
|
15
11
|
LOGGER.info("Starting diffs on #{::DatadogBackup::ThreadPool::TPOOL.max_length} threads")
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
id = board['id']
|
12
|
+
futures = all.map do |dashboard|
|
13
|
+
Concurrent::Promises.future_on(::DatadogBackup::ThreadPool::TPOOL, dashboard) do |board|
|
14
|
+
id = board[id_keyname]
|
20
15
|
get_and_write_file(id)
|
21
16
|
end
|
22
17
|
end
|
@@ -27,13 +22,23 @@ module DatadogBackup
|
|
27
22
|
Concurrent::Promises.zip(*futures).value!
|
28
23
|
end
|
29
24
|
|
30
|
-
def all_dashboards
|
31
|
-
get_all.fetch('dashboards')
|
32
|
-
end
|
33
|
-
|
34
25
|
def initialize(options)
|
35
26
|
super(options)
|
36
27
|
@banlist = %w[modified_at url].freeze
|
37
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def api_version
|
33
|
+
'v1'
|
34
|
+
end
|
35
|
+
|
36
|
+
def api_resource_name
|
37
|
+
'dashboard'
|
38
|
+
end
|
39
|
+
|
40
|
+
def id_keyname
|
41
|
+
'id'
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DatadogBackup
|
4
|
+
# Notify the user if they are using deprecated features.
|
4
5
|
module Deprecations
|
5
6
|
def self.check
|
6
|
-
if RUBY_VERSION < '2.7'
|
7
|
-
LOGGER.warn "ruby-#{RUBY_VERSION} is deprecated. Ruby 2.7 or higher will be required to use this gem after datadog_backup@v3"
|
8
|
-
end
|
7
|
+
LOGGER.warn "ruby-#{RUBY_VERSION} is deprecated. Ruby 2.7 or higher will be required to use this gem after datadog_backup@v3" if RUBY_VERSION < '2.7'
|
9
8
|
end
|
10
9
|
end
|
11
|
-
end
|
10
|
+
end
|
@@ -6,11 +6,10 @@ require 'yaml'
|
|
6
6
|
require 'deepsort'
|
7
7
|
|
8
8
|
module DatadogBackup
|
9
|
+
##
|
10
|
+
# Meant to be mixed into DatadogBackup::Resources
|
11
|
+
# Relies on @options[:backup_dir] and @options[:output_format]
|
9
12
|
module LocalFilesystem
|
10
|
-
##
|
11
|
-
# Meant to be mixed into DatadogBackup::Core
|
12
|
-
# Relies on @options[:backup_dir] and @options[:output_format]
|
13
|
-
|
14
13
|
def all_files
|
15
14
|
::Dir.glob(::File.join(backup_dir, '**', '*')).select { |f| ::File.file?(f) }
|
16
15
|
end
|
@@ -46,7 +45,7 @@ module DatadogBackup
|
|
46
45
|
end
|
47
46
|
|
48
47
|
def file_type(filepath)
|
49
|
-
::File.extname(filepath).strip.downcase[1
|
48
|
+
::File.extname(filepath).strip.downcase[1..].to_sym
|
50
49
|
end
|
51
50
|
|
52
51
|
def find_file_by_id(id)
|
@@ -1,28 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module DatadogBackup
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def api_version
|
10
|
-
'v1'
|
11
|
-
end
|
12
|
-
|
13
|
-
def api_resource_name
|
14
|
-
'monitor'
|
4
|
+
# Monitor specific overrides for backup and restore.
|
5
|
+
class Monitors < Resources
|
6
|
+
def all
|
7
|
+
get_all
|
15
8
|
end
|
16
9
|
|
17
10
|
def backup
|
18
|
-
|
11
|
+
all.map do |monitor|
|
19
12
|
id = monitor['id']
|
20
13
|
write_file(dump(get_by_id(id)), filename(id))
|
21
14
|
end
|
22
15
|
end
|
23
16
|
|
24
17
|
def get_by_id(id)
|
25
|
-
monitor =
|
18
|
+
monitor = all.select { |m| m['id'].to_s == id.to_s }.first
|
26
19
|
monitor.nil? ? {} : except(monitor)
|
27
20
|
end
|
28
21
|
|
@@ -30,5 +23,15 @@ module DatadogBackup
|
|
30
23
|
super(options)
|
31
24
|
@banlist = %w[overall_state overall_state_modified matching_downtimes modified].freeze
|
32
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def api_version
|
30
|
+
'v1'
|
31
|
+
end
|
32
|
+
|
33
|
+
def api_resource_name
|
34
|
+
'monitor'
|
35
|
+
end
|
33
36
|
end
|
34
37
|
end
|