Skip to content

Commit 9993886

Browse files
committed
allow managing /etc/alloy/config.alloy
1 parent 849be19 commit 9993886

File tree

4 files changed

+71
-3
lines changed

4 files changed

+71
-3
lines changed

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
fixtures:
33
repositories:
44
apt: 'https://github.com/puppetlabs/puppetlabs-apt'
5+
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib'
56
yumrepo_core: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core'

manifests/init.pp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
# @summary Install and configure Grafana Alloy
2+
#
3+
# @param config
4+
# The contents of the configuration file, if any
25
class grafana_alloy (
6+
Optional[String[1]] $config = undef,
37
) {
48
require grafana_alloy::repo
59
package { 'alloy': }
6-
-> service { 'alloy':
7-
ensure => 'running',
8-
enable => true,
10+
11+
if $config {
12+
file { '/etc/alloy/config.alloy':
13+
content => $config,
14+
mode => '0640',
15+
owner => 'root',
16+
group => 'alloy',
17+
require => Package['alloy'],
18+
notify => Service['alloy'],
19+
}
20+
}
21+
22+
service { 'alloy':
23+
ensure => 'running',
24+
enable => true,
25+
require => Package['alloy'],
926
}
1027
}

spec/acceptance/init_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,30 @@
1212
end
1313
end
1414
end
15+
16+
describe 'with config' do
17+
it_behaves_like 'an idempotent resource' do
18+
let(:config) do
19+
<<-CONFIG
20+
prometheus.exporter.unix "default" {
21+
include_exporter_metrics = true
22+
}
23+
24+
prometheus.scrape "default" {
25+
targets = concat(
26+
prometheus.exporter.unix.default.targets,
27+
)
28+
forward_to = []
29+
}
30+
CONFIG
31+
end
32+
let(:manifest) do
33+
<<-PUPPET
34+
class { 'grafana_alloy':
35+
config => '#{config}'
36+
}
37+
PUPPET
38+
end
39+
end
40+
end
1541
end

spec/classes/grafana_alloy_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'grafana_alloy' do
6+
on_supported_os.each do |os, os_facts|
7+
context "on #{os}" do
8+
let(:facts) { os_facts }
9+
let(:params) { {} }
10+
11+
context 'with default params' do
12+
it { is_expected.to compile.with_all_deps }
13+
it { is_expected.not_to contain_file('/etc/alloy/config.alloy') }
14+
end
15+
16+
context 'with all params' do
17+
let(:params) { super().merge(config: 'my config') }
18+
19+
it { is_expected.to compile.with_all_deps }
20+
it { is_expected.to contain_file('/etc/alloy/config.alloy').with_content('my config') }
21+
end
22+
end
23+
end
24+
end

0 commit comments

Comments
 (0)