Skip to content

Commit

Permalink
Avoid unnecessary code repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
deric committed Jul 27, 2023
1 parent e869cce commit 0b1b428
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 9 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,22 @@ include fluentbit

![fluentbit pipeline](img/pipeline.png)

Define some inputs:
```yaml
fluentbit::inputs:
'tail-syslog':
pipeline: input
plugin: tail
properties:
Path: /var/syslog
```
[outputs](https://docs.fluentbit.io/manual/pipeline/outputs):
```yaml
fluentbit::outputs:
'prometheus':
plugin: prometheus_exporter
properties:
match: nginx.metrics.*
host: 0.0.0.0
port: 2021
```
15 changes: 12 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,17 @@
-> Class['fluentbit::config']
~> Class['fluentbit::service']

create_resources(fluentbit::pipeline, $inputs, { pipeline => 'input' })
create_resources(fluentbit::pipeline, $outputs, { pipeline => 'output' })
create_resources(fluentbit::pipeline, $filters, { pipeline => 'filter' })
$inputs.each |$name, $conf| {
create_resources(fluentbit::pipeline, { $name => merge({ 'pipeline' => 'input' }, $conf) })
}

$outputs.each |$name, $conf| {
create_resources(fluentbit::pipeline, { $name => merge({ 'pipeline' => 'output' }, $conf) })
}

$filters.each |$name, $conf| {
create_resources(fluentbit::pipeline, { $name => merge({ 'pipeline' => 'filter' }, $conf) })
}

create_resources(fluentbit::upstream, $upstreams)
}
47 changes: 43 additions & 4 deletions spec/classes/fluentbit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@
let(:params) do
{
inputs: {
'tail-syslog': {
'pipeline': 'input',
'syslog': {
'plugin': 'tail',
'properties': {
'Path': '/var/log/syslog',
Expand All @@ -118,8 +117,48 @@
end

it {
is_expected.to contain_file('/etc/fluent-bit/parsers.conf')
.with_content(%r{Name\s+json\n\s+Format\s+json\n\s+Time_key\s+time})
is_expected.to contain_concat__fragment('pipeline-syslog')
.with_content(%r{Name\s+tail\n})
.with_content(%r{Path\s+/var/log/syslog\n})
}

it {
is_expected.to contain_fluentbit__pipeline('syslog')
.with({
'plugin': 'tail',
'pipeline': 'input',
})
}
end

context 'configure outputs' do
let(:params) do
{
outputs: {
'prometheus': {
'plugin': 'prometheus_exporter',
'properties': {
'match': 'nginx.metrics.*',
'host': '0.0.0.0',
'port': '2021',
}
}
},
}
end

it {
is_expected.to contain_concat__fragment('pipeline-prometheus')
.with_content(%r{Match\s+nginx.metrics.*\n})
.with_content(%r{Host\s+0.0.0.0\n})
}

it {
is_expected.to contain_fluentbit__pipeline('prometheus')
.with({
'plugin': 'prometheus_exporter',
'pipeline': 'output',
})
}
end
end
2 changes: 1 addition & 1 deletion types/pipelineplugin.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Fluentbit::PipelinePlugin = Hash[String, Struct[{
pipeline => Fluentbit::PipelineType,
plugin => String[1],
Optional[pipeline] => Fluentbit::PipelineType,
Optional[order] => Integer,
Optional[properties] => Hash,
}]]

0 comments on commit 0b1b428

Please sign in to comment.