datadog_backup 3.1.1 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/validate-pr.yml +1 -1
- data/CHANGELOG.md +14 -0
- data/README.md +1 -0
- data/bin/datadog_backup +5 -1
- data/lib/datadog_backup/dashboards.rb +9 -0
- data/lib/datadog_backup/local_filesystem.rb +2 -2
- data/lib/datadog_backup/options.rb +4 -0
- data/lib/datadog_backup/resources.rb +3 -5
- data/lib/datadog_backup/version.rb +1 -1
- data/spec/datadog_backup/core_spec.rb +2 -2
- data/spec/datadog_backup/local_filesystem_spec.rb +21 -0
- data/spec/datadog_backup/synthetics_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e3e8528c064d05b09bd31080a7bcab7c77fcca8dde46949cf8c62a7702f2af1
|
4
|
+
data.tar.gz: 24c57007224fcf546b5a886e4b9f2a78f76b2a63fd2c64067ae2454192919848
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5180a6ba1f92f5db842e88d337878eacd0bafe114fbbb8752153b85f7c47f682be3bdd529b694294cc5523fe4c94274a7ee78d15fc4798b327598fb7710303b
|
7
|
+
data.tar.gz: f4ccccd735136f06f92cc71f1df0176e5fa626fd36f5e60f4bc88ef93f9fcf31f8d840c523e1e70f08195faf8d32e8522fea3665e9b6f1efe280cf8b214331a9
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## [3.2.1](https://github.com/scribd/datadog_backup/compare/v3.2.0...v3.2.1) (2023-02-11)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* update error handling for restore ([233b1b2](https://github.com/scribd/datadog_backup/commit/233b1b27d485e7502dd47ca01670cea0576e920d))
|
7
|
+
|
8
|
+
# [3.2.0](https://github.com/scribd/datadog_backup/compare/v3.1.1...v3.2.0) (2023-02-10)
|
9
|
+
|
10
|
+
|
11
|
+
### Features
|
12
|
+
|
13
|
+
* Deepsort skip sorting arrays ([d9cba97](https://github.com/scribd/datadog_backup/commit/d9cba97015d1af636ca9c03605ef14fa8dcb6d21))
|
14
|
+
|
1
15
|
## [3.1.1](https://github.com/scribd/datadog_backup/compare/v3.1.0...v3.1.1) (2022-09-01)
|
2
16
|
|
3
17
|
|
data/README.md
CHANGED
@@ -71,6 +71,7 @@ parameter | description
|
|
71
71
|
--no-color | removes colored output from diff format
|
72
72
|
--diff-format FORMAT | one of `color`, `html_simple`, `html` | `color`
|
73
73
|
--force-restore | Force restore to Datadog. Do not ask to validate. Non-interactive.
|
74
|
+
--disable-array-sort | Do not sort array elements, to preserver order of dashboard widgets.
|
74
75
|
--h, --help | help
|
75
76
|
|
76
77
|
## Environment variables
|
data/bin/datadog_backup
CHANGED
@@ -66,6 +66,9 @@ def prereqs(defaults) # rubocop:disable Metrics/AbcSize
|
|
66
66
|
opts.on('--force-restore', 'Force restore to Datadog. Do not ask to validate. Non-interactive.') do
|
67
67
|
result[:force_restore] = true
|
68
68
|
end
|
69
|
+
opts.on('--disable-array-sort', 'Do not sort array elements, to preserver order of dashboard widgets.') do
|
70
|
+
result[:disable_array_sort] = true
|
71
|
+
end
|
69
72
|
end
|
70
73
|
options.parse!
|
71
74
|
|
@@ -82,7 +85,8 @@ defaults = {
|
|
82
85
|
diff_format: :color,
|
83
86
|
resources: [DatadogBackup::Dashboards, DatadogBackup::Monitors, DatadogBackup::Synthetics],
|
84
87
|
output_format: :yaml,
|
85
|
-
force_restore: false
|
88
|
+
force_restore: false,
|
89
|
+
disable_array_sort: false
|
86
90
|
}
|
87
91
|
|
88
92
|
DatadogBackup::Cli.new(prereqs(defaults)).run!
|
@@ -22,6 +22,15 @@ module DatadogBackup
|
|
22
22
|
Concurrent::Promises.zip(*futures).value!
|
23
23
|
end
|
24
24
|
|
25
|
+
def get_by_id(id)
|
26
|
+
begin
|
27
|
+
dashboard = except(get(id))
|
28
|
+
rescue Faraday::ResourceNotFound => e
|
29
|
+
dashboard = {}
|
30
|
+
end
|
31
|
+
except(dashboard)
|
32
|
+
end
|
33
|
+
|
25
34
|
def initialize(options)
|
26
35
|
super(options)
|
27
36
|
@banlist = %w[modified_at url].freeze
|
@@ -32,9 +32,9 @@ module DatadogBackup
|
|
32
32
|
def dump(object)
|
33
33
|
case output_format
|
34
34
|
when :json
|
35
|
-
JSON.pretty_generate(object.deep_sort)
|
35
|
+
JSON.pretty_generate(object.deep_sort(array: disable_array_sort ? false : true))
|
36
36
|
when :yaml
|
37
|
-
YAML.dump(object.deep_sort)
|
37
|
+
YAML.dump(object.deep_sort(array: disable_array_sort ? false : true))
|
38
38
|
else
|
39
39
|
raise 'invalid output_format specified or not specified'
|
40
40
|
end
|
@@ -26,8 +26,8 @@ module DatadogBackup
|
|
26
26
|
# Returns the diffy diff.
|
27
27
|
# Optionally, supply an array of keys to remove from comparison
|
28
28
|
def diff(id)
|
29
|
-
current = except(get_by_id(id)).deep_sort.to_yaml
|
30
|
-
filesystem = except(load_from_file_by_id(id)).deep_sort.to_yaml
|
29
|
+
current = except(get_by_id(id)).deep_sort(array: disable_array_sort ? false : true).to_yaml
|
30
|
+
filesystem = except(load_from_file_by_id(id)).deep_sort(array: disable_array_sort ? false : true).to_yaml
|
31
31
|
result = ::Diffy::Diff.new(current, filesystem, include_plus_and_minus_in_html: true).to_s(diff_format)
|
32
32
|
LOGGER.debug("Compared ID #{id} and found filesystem: #{filesystem} <=> current: #{current} == result: #{result}")
|
33
33
|
result.chomp
|
@@ -110,9 +110,7 @@ module DatadogBackup
|
|
110
110
|
body = load_from_file_by_id(id)
|
111
111
|
begin
|
112
112
|
update(id, body)
|
113
|
-
rescue
|
114
|
-
raise e.message unless e.message.include?('update failed with error 404')
|
115
|
-
|
113
|
+
rescue Faraday::ResourceNotFound => e
|
116
114
|
create_newly(id, body)
|
117
115
|
end
|
118
116
|
end
|
@@ -103,7 +103,7 @@ describe DatadogBackup::Resources do
|
|
103
103
|
allow(resources).to receive(:api_resource_name).and_return('api-resource-name-string')
|
104
104
|
stubs.get('/api/api-version-string/api-resource-name-string/abc-123-def') { respond_with200({ 'test' => 'ok' }) }
|
105
105
|
stubs.get('/api/api-version-string/api-resource-name-string/bad-123-id') do
|
106
|
-
|
106
|
+
raise Faraday::ResourceNotFound
|
107
107
|
end
|
108
108
|
allow(resources).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
|
109
109
|
end
|
@@ -126,7 +126,7 @@ describe DatadogBackup::Resources do
|
|
126
126
|
before do
|
127
127
|
allow(resources).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
|
128
128
|
stubs.put('/api/api-version-string/api-resource-name-string/bad-123-id') do
|
129
|
-
|
129
|
+
raise Faraday::ResourceNotFound
|
130
130
|
end
|
131
131
|
stubs.post('/api/api-version-string/api-resource-name-string', { 'load' => 'ok' }) do
|
132
132
|
respond_with200({ 'id' => 'my-new-id' })
|
@@ -20,6 +20,15 @@ describe DatadogBackup::LocalFilesystem do
|
|
20
20
|
output_format: :yaml
|
21
21
|
)
|
22
22
|
end
|
23
|
+
let(:resources_disable_array_sort) do
|
24
|
+
DatadogBackup::Resources.new(
|
25
|
+
action: 'backup',
|
26
|
+
backup_dir: tempdir,
|
27
|
+
resources: [DatadogBackup::Dashboards],
|
28
|
+
output_format: :json,
|
29
|
+
disable_array_sort: true
|
30
|
+
)
|
31
|
+
end
|
23
32
|
|
24
33
|
describe '#all_files' do
|
25
34
|
subject { resources.all_files }
|
@@ -79,6 +88,18 @@ describe DatadogBackup::LocalFilesystem do
|
|
79
88
|
|
80
89
|
it { is_expected.to eq(%(---\na: b\n)) }
|
81
90
|
end
|
91
|
+
|
92
|
+
context 'when array sorting is enabled' do
|
93
|
+
subject { resources.dump({ a: [ :c, :b ] }) }
|
94
|
+
|
95
|
+
it { is_expected.to eq(%({\n \"a\": [\n \"b\",\n \"c\"\n ]\n})) }
|
96
|
+
end
|
97
|
+
|
98
|
+
context 'when array sorting is disabled' do
|
99
|
+
subject { resources_disable_array_sort.dump({ a: [ :c, :b ] }) }
|
100
|
+
|
101
|
+
it { is_expected.to eq(%({\n \"a\": [\n \"c\",\n \"b\"\n ]\n})) }
|
102
|
+
end
|
82
103
|
end
|
83
104
|
|
84
105
|
describe '#filename' do
|
@@ -231,7 +231,7 @@ describe DatadogBackup::Synthetics do
|
|
231
231
|
|
232
232
|
before do
|
233
233
|
synthetics.write_file(synthetics.dump({ 'name' => 'restore-invalid-id', 'type' => 'api' }), synthetics.filename('restore-invalid-id'))
|
234
|
-
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') {
|
234
|
+
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') { raise Faraday::ResourceNotFound }
|
235
235
|
stubs.post('/api/v1/synthetics/tests/api') { respond_with200({ 'public_id' => 'restore-valid-id' }) }
|
236
236
|
allow(synthetics).to receive(:create).and_call_original
|
237
237
|
allow(synthetics).to receive(:all).and_return([api_test, browser_test, { 'public_id' => 'restore-valid-id', 'type' => 'api' }])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datadog_backup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kamran Farhadi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-02-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: amazing_print
|