|
55 | 55 | it { should contain_file(conf_file).with_content(%r{username: monitoring}) } |
56 | 56 | it { should contain_file(conf_file).with_content(%r{^[^#]*tags:\s+- foo\s+- bar\s+- baz}) } |
57 | 57 | it { should contain_file(conf_file).with_content(%r{^[^#]*relations:\s+- furry\s+- fuzzy\s+- funky}) } |
| 58 | + |
| 59 | + context 'with custom metric query missing %s' do |
| 60 | + let(:params) {{ |
| 61 | + host: 'postgres1', |
| 62 | + dbname: 'cats', |
| 63 | + port: 4142, |
| 64 | + username: 'monitoring', |
| 65 | + password: 'abc123', |
| 66 | + custom_metrics: { |
| 67 | + 'query_is_missing_%s' => { |
| 68 | + 'query' => 'select * from fuzz', |
| 69 | + 'metrics' => { }, |
| 70 | + } |
| 71 | + } |
| 72 | + }} |
| 73 | + it do |
| 74 | + expect { |
| 75 | + is_expected.to compile |
| 76 | + }.to raise_error(/custom_metrics require %s for metric substitution/) |
| 77 | + end |
| 78 | + end |
| 79 | + |
| 80 | + context 'with custom metric query' do |
| 81 | + let(:params) {{ |
| 82 | + host: 'postgres1', |
| 83 | + dbname: 'cats', |
| 84 | + port: 4142, |
| 85 | + username: 'monitoring', |
| 86 | + password: 'abc123', |
| 87 | + custom_metrics: { |
| 88 | + 'foo_gooo_bar_query' => { |
| 89 | + 'query' => 'select foo, %s from bar', |
| 90 | + 'metrics' => { |
| 91 | + "gooo" => ["custom_metric.tag.gooo", "GAUGE"] |
| 92 | + }, |
| 93 | + 'descriptors' => [["foo", "custom_metric.tag.foo"]] |
| 94 | + } |
| 95 | + } |
| 96 | + }} |
| 97 | + it { is_expected.to compile } |
| 98 | + it { should contain_file(conf_file).with_content(%r{^[^#]*custom_metrics:}) } |
| 99 | + it { should contain_file(conf_file).with_content(%r{\s+query:\s*['"]?select foo, %s from bar['"]?}) } |
| 100 | + it { should contain_file(conf_file).with_content(%r{\s+metrics:}) } |
| 101 | + it { should contain_file(conf_file).with_content(%r{\s+"gooo":\s+\[custom_metric.tag.gooo, GAUGE\]}) } |
| 102 | + it { should contain_file(conf_file).with_content(%r{\s+query.*\n\s+relation:\s*false}) } |
| 103 | + it { should contain_file(conf_file).with_content(%r{\s+descriptors.*\n\s+-\s+\[foo, custom_metric.tag.foo\]}) } |
| 104 | + end |
58 | 105 | end |
59 | 106 | end |
60 | 107 |
|
|
0 commit comments