From db1a2af25fe97ab50bf335f5dc3b25d89378645b Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Wed, 22 Nov 2023 16:12:38 +0100 Subject: [PATCH 01/39] Refactor Module to allow definition of types and have a more flexible way of configuring otelcol --- .fixtures.yml | 1 + REFERENCE.md | 262 +++++++++++++++++++++-- examples/basic_installation.pp | 62 +++--- examples/basic_installation_oldstyle.pp | 33 +++ examples/complex_order.pp | 46 +++++ manifests/component.pp | 57 +++++ manifests/config.pp | 96 +++++++-- manifests/exporter.pp | 28 +++ manifests/extension.pp | 30 +++ manifests/init.pp | 14 +- manifests/pipeline.pp | 32 +++ manifests/processor.pp | 27 +++ manifests/receiver.pp | 26 +++ manifests/service.pp | 2 +- metadata.json | 4 + spec/classes/otelcol_spec.rb | 264 ++++++++++-------------- spec/defines/component_spec.rb | 108 ++++++++++ spec/defines/exporter_spec.rb | 56 +++++ spec/defines/extension_spec.rb | 52 +++++ spec/defines/pipeline_spec.rb | 51 +++++ spec/defines/processor_spec.rb | 56 +++++ spec/defines/receiver_spec.rb | 56 +++++ templates/component.yml.erb | 1 + templates/config-footer.yml.erb | 0 templates/config-header.yml.erb | 1 + 25 files changed, 1146 insertions(+), 219 deletions(-) create mode 100644 examples/basic_installation_oldstyle.pp create mode 100644 examples/complex_order.pp create mode 100644 manifests/component.pp create mode 100644 manifests/exporter.pp create mode 100644 manifests/extension.pp create mode 100644 manifests/pipeline.pp create mode 100644 manifests/processor.pp create mode 100644 manifests/receiver.pp create mode 100644 spec/defines/component_spec.rb create mode 100644 spec/defines/exporter_spec.rb create mode 100644 spec/defines/extension_spec.rb create mode 100644 spec/defines/pipeline_spec.rb create mode 100644 spec/defines/processor_spec.rb create mode 100644 spec/defines/receiver_spec.rb create mode 100644 templates/component.yml.erb create mode 100644 templates/config-footer.yml.erb create mode 100644 templates/config-header.yml.erb diff --git a/.fixtures.yml b/.fixtures.yml index 6470f44..d50c51e 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -4,3 +4,4 @@ fixtures: forge_modules: stdlib: "puppetlabs/stdlib" + concat: "puppetlabs-concat" diff --git a/REFERENCE.md b/REFERENCE.md index cf083f9..0a290ce 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -16,6 +16,20 @@ * `otelcol::service`: Manages the Otelcol service +### Defined types + +#### Public Defined types + +* [`otelcol::exporter`](#otelcol--exporter): Define a OpenTelemetry Collector exporter +* [`otelcol::extension`](#otelcol--extension): Add an extension to the OpenTelemetry Collector configuration +* [`otelcol::pipeline`](#otelcol--pipeline): Add a pipeline to the OpenTelemetry Collector configuration +* [`otelcol::processor`](#otelcol--processor): Add a processor to the OpenTelemetry Collector configuration +* [`otelcol::receiver`](#otelcol--receiver): Add a receiver to the OpenTelemetry Collector configuration + +#### Private Defined types + +* `otelcol::component`: Define a component for the OpenTelemetry Collector Configuration + ## Classes ### `otelcol` @@ -125,22 +139,11 @@ Default value: `'0644'` ##### `receivers` -Data type: `Hash` +Data type: `Optional[Hash]` Hash for receivers config -Default value: - -```puppet -{ - 'otlp' => { - 'protocols' => { - 'http' => {}, - 'grpc' => {}, - }, - }, - } -``` +Default value: `undef` ##### `processors` @@ -236,7 +239,7 @@ Data type: `String[1]` Version of otelcol that will be used, param is not used if archive_location is set -Default value: `'0.79.0'` +Default value: `'0.89.0'` ##### `archive_location` @@ -267,3 +270,234 @@ Templated generation of otelcol.conf Conditionally handle repos or package paths and install the necessary otelcol package. +## Defined types + +### `otelcol::exporter` + +Create a OpenTelemetry Collector exporter in the configuration file. + +#### Examples + +##### + +```puppet +otelcol::exporter { 'namevar': } +``` + +#### Parameters + +The following parameters are available in the `otelcol::exporter` defined type: + +* [`name`](#-otelcol--exporter--name) +* [`config`](#-otelcol--exporter--config) +* [`order`](#-otelcol--exporter--order) +* [`pipelines`](#-otelcol--exporter--pipelines) + +##### `name` + +The name of the exporter. + +##### `config` + +Data type: `Hash` + +The configuration of the exporter. + +Default value: `{}` + +##### `order` + +Data type: `Integer[0,999]` + +The order of the exporter. + +Default value: `0` + +##### `pipelines` + +Data type: `Array[String[1]]` + +The pipelines to attach the exporter to. + +Default value: `[]` + +### `otelcol::extension` + +Add an extension to the OpenTelemetry Collector configuration + +#### Examples + +##### + +```puppet +otelcol::extension { 'namevar': } +``` + +#### Parameters + +The following parameters are available in the `otelcol::extension` defined type: + +* [`name`](#-otelcol--extension--name) +* [`config`](#-otelcol--extension--config) +* [`order`](#-otelcol--extension--order) + +##### `name` + +The name of the extension + +##### `config` + +Data type: `Hash` + +The configuration for the extension + +Default value: `{}` + +##### `order` + +Data type: `Integer[0,999]` + +The order in which the extension should be loaded + +Default value: `0` + +### `otelcol::pipeline` + +Used for explicitly configuring a pipeline in the OpenTelemetry Collector. +This is useful for configuring a pipeline that is not automatically +configured by its Components. + +#### Examples + +##### + +```puppet +otelcol::pipeline { 'namevar': } +``` + +#### Parameters + +The following parameters are available in the `otelcol::pipeline` defined type: + +* [`name`](#-otelcol--pipeline--name) +* [`config`](#-otelcol--pipeline--config) +* [`order`](#-otelcol--pipeline--order) + +##### `name` + +The name of the pipeline to configure. + +##### `config` + +Data type: `Hash` + +The configuration for the pipeline. + +Default value: `{}` + +##### `order` + +Data type: `Integer[0,999]` + +The order in which the pipeline should be configured. + +Default value: `0` + +### `otelcol::processor` + +Add a processor to the OpenTelemetry Collector configuration + +#### Examples + +##### + +```puppet +otelcol::processor { 'namevar': } +``` + +#### Parameters + +The following parameters are available in the `otelcol::processor` defined type: + +* [`name`](#-otelcol--processor--name) +* [`config`](#-otelcol--processor--config) +* [`order`](#-otelcol--processor--order) +* [`pipelines`](#-otelcol--processor--pipelines) + +##### `name` + +The name of the processor + +##### `config` + +Data type: `Hash` + +The configuration of the processor + +Default value: `{}` + +##### `order` + +Data type: `Integer[0,999]` + +The order of the processor + +Default value: `0` + +##### `pipelines` + +Data type: `Array[String[1]]` + +The pipelines to attach the processor to + +Default value: `[]` + +### `otelcol::receiver` + +Add a receiver to the OpenTelemetry Collector configuration + +#### Examples + +##### + +```puppet +otelcol::receiver { 'namevar': } +``` + +#### Parameters + +The following parameters are available in the `otelcol::receiver` defined type: + +* [`name`](#-otelcol--receiver--name) +* [`config`](#-otelcol--receiver--config) +* [`order`](#-otelcol--receiver--order) +* [`pipelines`](#-otelcol--receiver--pipelines) + +##### `name` + +The name of the receiver + +##### `config` + +Data type: `Hash` + +The configuration of the receiver + +Default value: `{}` + +##### `order` + +Data type: `Integer[0,999]` + +The order of the receiver + +Default value: `0` + +##### `pipelines` + +Data type: `Array[String[1]]` + +The pipelines the receiver is part of + +Default value: `[]` + diff --git a/examples/basic_installation.pp b/examples/basic_installation.pp index c1832e0..00cc906 100644 --- a/examples/basic_installation.pp +++ b/examples/basic_installation.pp @@ -1,32 +1,40 @@ -class { 'otelcol': - manage_archive => true, - receivers => { - 'otlp' => { - 'protocols' => { - 'grpc' => { 'endpoint' => 'localhost:4317' }, - 'http' => { 'endpoint' => 'localhost:4318' }, - }, - }, - 'prometheus' => { - 'config' => { - 'scrape_configs' => [ - { - 'job_name' => 'otel-collector', - 'scrape_interval' => '10s', - 'static_configs' => [ - { 'targets' => ['localhost:8888'] } - ], - }, - ], - }, +Otelcol::Receiver { 'otlp' : + config => { + 'protocols' => { + 'grpc' => { 'endpoint' => 'localhost:4317' }, + 'http' => { 'endpoint' => 'localhost:4318' }, }, }, - exporters => { 'logging' => { 'verbosity' => 'detailed' } }, - pipelines => { - 'metrics' => { - 'receivers' => ['otlp', 'prometheus'], - 'exporters' => ['logging'], + pipelines => ['metrics'], +} + +Otelcol::Receiver { 'prometheus' : + config => { + 'config' => { + 'scrape_configs' => [ + { + 'job_name' => 'otel-collector', + 'scrape_interval' => '10s', + 'static_configs' => [ + { 'targets' => ['localhost:8888'] } + ], + }, + ], }, }, - processors => { 'batch' => {} }, + pipelines => ['metrics'], +} + +Otelcol::Exporter { 'logging': + config => { 'verbosity' => 'detailed' }, + pipelines => ['metrics'], +} + +Otelcol::Processor { 'batch': + config => {}, + pipelines => ['metrics'], +} + +class { 'otelcol': + manage_archive => true, } diff --git a/examples/basic_installation_oldstyle.pp b/examples/basic_installation_oldstyle.pp new file mode 100644 index 0000000..93fb7b6 --- /dev/null +++ b/examples/basic_installation_oldstyle.pp @@ -0,0 +1,33 @@ +class { 'otelcol': + manage_archive => true, + receivers => { + 'otlp' => { + 'protocols' => { + 'grpc' => { 'endpoint' => 'localhost:4317' }, + 'http' => { 'endpoint' => 'localhost:4318' }, + }, + }, + 'prometheus' => { + 'config' => { + 'scrape_configs' => [ + { + 'job_name' => 'otel-collector', + 'scrape_interval' => '10s', + 'static_configs' => [ + { 'targets' => ['localhost:8888'] } + ], + }, + ], + }, + }, + }, + exporters => { 'logging' => { 'verbosity' => 'detailed' } }, + pipelines => { + 'metrics' => { + 'receivers' => ['otlp', 'prometheus'], + 'processors' => ['batch'], + 'exporters' => ['logging'], + }, + }, + processors => { 'batch' => {} }, +} diff --git a/examples/complex_order.pp b/examples/complex_order.pp new file mode 100644 index 0000000..64a2e64 --- /dev/null +++ b/examples/complex_order.pp @@ -0,0 +1,46 @@ +Otelcol::Receiver { 'otlp' : + config => { + 'protocols' => { + 'grpc' => { 'endpoint' => 'localhost:4317' }, + 'http' => { 'endpoint' => 'localhost:4318' }, + }, + }, + pipelines => ['metrics','logs'], +} + +Otelcol::Receiver { 'prometheus' : + config => { + 'config' => { + 'scrape_configs' => [ + { + 'job_name' => 'otel-collector', + 'scrape_interval' => '10s', + 'static_configs' => [ + { 'targets' => ['localhost:8888'] } + ], + }, + ], + }, + }, + pipelines => ['metrics'], +} + +Otelcol::Exporter { 'logging': + config => { 'verbosity' => 'detailed' }, + pipelines => ['metrics','logs'], +} + +Otelcol::Processor { 'batch/1': + config => {}, + pipelines => ['metrics','logs'], + order => 1, +} +Otelcol::Processor { 'memory_limiter/2': + config => { 'check_interval' => '5s', 'limit_mib' => 512 }, + pipelines => ['metrics','logs'], + order => 2, +} + +class { 'otelcol': + manage_archive => true, +} diff --git a/manifests/component.pp b/manifests/component.pp new file mode 100644 index 0000000..b7bd8b8 --- /dev/null +++ b/manifests/component.pp @@ -0,0 +1,57 @@ +# @summary Define a component for the OpenTelemetry Collector Configuration +# +# Generic Type for defining a component for the OpenTelemetry Collector Configuration +# +# @param component_name +# The name of the component +# @param type +# The type of the component +# @param config +# The configuration for the component +# @param order +# The order of the component +# @param pipelines +# The pipelines to add the component to +# +# @example +# otelcol::component { 'receiver_name-receiver':': +# component_name => 'receiver_name', +# type => 'receiver', +# } +# @api private +define otelcol::component ( + String $component_name, + String $type, + Hash $config = {}, + Integer[0,10999] $order = 0, + Array[String[1]] $pipelines = [], +) { + # assert_private() + $component = { + $type => { + $component_name => $config, + }, + } + concat::fragment { "otelcol-config-${type}-${component_name}" : + target => 'otelcol-config', + order => $order, + content => template('otelcol/component.yml.erb'), + } + + $pipelines.each |String $pipeline| { + $component = { + 'service' => { + 'pipelines' => { + $pipeline => { + $type => [$component_name], + }, + }, + }, + } + concat::fragment { "otelcol-config-${type}-${component_name}-${pipeline}" : + target => 'otelcol-config', + order => $order, + content => template('otelcol/component.yml.erb'), + } + } +} diff --git a/manifests/config.pp b/manifests/config.pp index f5044a8..cfc836e 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,15 +4,8 @@ # class otelcol::config inherits otelcol { assert_private() - - $settings = { - 'receivers' => $otelcol::receivers, - 'processors' => $otelcol::processors, - 'exporters' => $otelcol::exporters, - 'extensions' => $otelcol::extensions, + $component = { 'service' => { - 'extensions' => $otelcol::extensions.keys(), - 'pipelines' => $otelcol::pipelines, 'telemetry' => { 'logs' => $otelcol::log_options, 'metrics' => { @@ -23,13 +16,31 @@ }, } - file { 'otelcol-config' : - ensure => 'file', - path => $otelcol::config_file, - content => template('otelcol/config.yml.erb'), - owner => $otelcol::config_file_owner, - group => $otelcol::config_file_group, - mode => $otelcol::config_file_mode, + concat { 'otelcol-config' : + ensure => present, + path => $otelcol::config_file, + format => 'yaml', + # content => template('otelcol/config.yml.erb'), + owner => $otelcol::config_file_owner, + group => $otelcol::config_file_group, + mode => $otelcol::config_file_mode, + } + concat::fragment { 'otelcol-config-header' : + target => 'otelcol-config', + order => 0, + content => template('otelcol/config-header.yml.erb'), + } + + concat::fragment { 'otelcol-config-baseconfig' : + target => 'otelcol-config', + order => 10000, + content => template('otelcol/component.yml.erb'), + } + + concat::fragment { 'otelcol-config-footer' : + target => 'otelcol-config', + order => 10001, + content => template('otelcol/config-footer.yml.erb'), } file { 'otelcol-environment' : ensure => 'file', @@ -39,4 +50,59 @@ group => $otelcol::config_file_group, mode => $otelcol::config_file_mode, } + + if($otelcol::receivers) { + $otelcol::receivers.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('Otelcol::Receiver', $rname, $rvalue) + } + else { + ensure_resource('Otelcol::Receiver', $rname, { 'config' => $rvalue }) + } + } + } + + if($otelcol::processors) { + $otelcol::processors.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('Otelcol::Processor', $rname, $rvalue) + } + else { + ensure_resource('Otelcol::Processor', $rname, { 'config' => $rvalue }) + } + } + } + + if($otelcol::exporters) { + $otelcol::exporters.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('Otelcol::Exporter', $rname, $rvalue) + } + else { + ensure_resource('Otelcol::Exporter', $rname, { 'config' => $rvalue }) + } + } + } + + if($otelcol::pipelines) { + $otelcol::pipelines.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('Otelcol::Pipeline', $rname, $rvalue) + } + else { + ensure_resource('Otelcol::Pipeline', $rname, { 'config' => $rvalue }) + } + } + } + + if($otelcol::extensions) { + $otelcol::extensions.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('Otelcol::Extension', $rname, $rvalue) + } + else { + ensure_resource('Otelcol::Extension', $rname, { 'config' => $rvalue }) + } + } + } } diff --git a/manifests/exporter.pp b/manifests/exporter.pp new file mode 100644 index 0000000..4a22734 --- /dev/null +++ b/manifests/exporter.pp @@ -0,0 +1,28 @@ +# @summary Define a OpenTelemetry Collector exporter +# +# Create a OpenTelemetry Collector exporter in the configuration file. +# +# @param name +# The name of the exporter. +# @param config +# The configuration of the exporter. +# @param order +# The order of the exporter. +# @param pipelines +# The pipelines to attach the exporter to. +# @example +# otelcol::exporter { 'namevar': } +define otelcol::exporter ( + Hash $config = {}, + Integer[0,999] $order = 0, + Array[String[1]] $pipelines = [], +) { + $real_order = 3000+$order + Otelcol::Component { "${name}-exporter": + order => $real_order, + config => $config, + pipelines => $pipelines, + component_name => $name, + type => 'exporters', + } +} diff --git a/manifests/extension.pp b/manifests/extension.pp new file mode 100644 index 0000000..661c111 --- /dev/null +++ b/manifests/extension.pp @@ -0,0 +1,30 @@ +# @summary Add an extension to the OpenTelemetry Collector configuration +# +# @param name +# The name of the extension +# @param config +# The configuration for the extension +# @param order +# The order in which the extension should be loaded +# +# @example +# otelcol::extension { 'namevar': } +define otelcol::extension ( + Hash $config = {}, + Integer[0,999] $order = 0, +) { + $component = { + 'extensions' => { + $name => $config, + }, + 'service' => { + 'extensions' => [$name], + }, + } + $real_order = 4000+$order + concat::fragment { "otelcol-config-extension-${name}" : + target => 'otelcol-config', + order => $real_order, + content => template('otelcol/component.yml.erb'), + } +} diff --git a/manifests/init.pp b/manifests/init.pp index dc584b0..999e049 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -56,14 +56,7 @@ String $config_file_owner = 'root', String $config_file_group = 'root', Stdlib::Filemode $config_file_mode = '0644', - Hash $receivers = { - 'otlp' => { - 'protocols' => { - 'http' => {}, - 'grpc' => {}, - }, - }, - }, + Optional[Hash] $receivers = undef, Variant[Hash,String[1]] $processors = {}, Variant[Hash,String[1]] $exporters = {}, Variant[Hash,String[1]] $pipelines = {}, @@ -72,16 +65,17 @@ Enum['none','basic','normal','detailed'] $metrics_level = 'basic', Optional[Stdlib::Host] $metrics_address_host = undef, Stdlib::Port $metrics_address_port = 8888, - Stdlib::Ensure::Service $service_ensure = 'running', + Stdlib::Ensure::Service $service_ensure = 'running', Boolean $manage_service = true, Boolean $manage_archive = false, String[1] $localpath_archive = '/tmp', # Boolean $manage_user = false, - String[1] $archive_version = '0.79.0', + String[1] $archive_version = '0.89.0', String[1] $archive_location = "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${archive_version}/${package_name}_${archive_version}_linux_amd64", ) { contain otelcol::install contain otelcol::config + if($manage_service) { contain otelcol::service Class['otelcol::config'] ~> Class['otelcol::service'] diff --git a/manifests/pipeline.pp b/manifests/pipeline.pp new file mode 100644 index 0000000..d71a25c --- /dev/null +++ b/manifests/pipeline.pp @@ -0,0 +1,32 @@ +# @summary Add a pipeline to the OpenTelemetry Collector configuration +# +# Used for explicitly configuring a pipeline in the OpenTelemetry Collector. +# This is useful for configuring a pipeline that is not automatically +# configured by its Components. +# +# @param name +# The name of the pipeline to configure. +# @param config +# The configuration for the pipeline. +# @param order +# The order in which the pipeline should be configured. +# @example +# otelcol::pipeline { 'namevar': } +define otelcol::pipeline ( + Hash $config = {}, + Integer[0,999] $order = 0, +) { + $component = { + 'service' => { + 'pipelines' => { + $name => $config, + }, + }, + } + $real_order = 5000+$order + concat::fragment { "otelcol-config-pipeline-${name}" : + target => 'otelcol-config', + order => $real_order, + content => template('otelcol/component.yml.erb'), + } +} diff --git a/manifests/processor.pp b/manifests/processor.pp new file mode 100644 index 0000000..cb2088f --- /dev/null +++ b/manifests/processor.pp @@ -0,0 +1,27 @@ +# @summary Add a processor to the OpenTelemetry Collector configuration +# +# @param name +# The name of the processor +# @param config +# The configuration of the processor +# @param order +# The order of the processor +# @param pipelines +# The pipelines to attach the processor to +# +# @example +# otelcol::processor { 'namevar': } +define otelcol::processor ( + Hash $config = {}, + Integer[0,999] $order = 0, + Array[String[1]] $pipelines = [], +) { + $real_order = 2000+$order + Otelcol::Component { "${name}-processors": + order => $real_order, + config => $config, + pipelines => $pipelines, + component_name => $name, + type => 'processors', + } +} diff --git a/manifests/receiver.pp b/manifests/receiver.pp new file mode 100644 index 0000000..3a96f74 --- /dev/null +++ b/manifests/receiver.pp @@ -0,0 +1,26 @@ +# @summary Add a receiver to the OpenTelemetry Collector configuration +# +# @param name +# The name of the receiver +# @param config +# The configuration of the receiver +# @param order +# The order of the receiver +# @param pipelines +# The pipelines the receiver is part of +# @example +# otelcol::receiver { 'namevar': } +define otelcol::receiver ( + Hash $config = {}, + Integer[0,999] $order = 0, + Array[String[1]] $pipelines = [], +) { + $real_order = 1000+$order + Otelcol::Component { "${name}-receivers": + order => $real_order, + config => $config, + pipelines => $pipelines, + component_name => $name, + type => 'receivers', + } +} diff --git a/manifests/service.pp b/manifests/service.pp index 4747116..5747823 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -28,6 +28,6 @@ ensure => $ensure, name => $otelcol::service_name, require => Package['otelcol'], - subscribe => [File['otelcol-config'], File['otelcol-environment']], + subscribe => [Concat['otelcol-config'], File['otelcol-environment']], } } diff --git a/metadata.json b/metadata.json index 5f4ad47..cf7acc5 100644 --- a/metadata.json +++ b/metadata.json @@ -11,6 +11,10 @@ { "name": "puppetlabs/stdlib", "version_requirement": ">= 8.0.0 < 9.0.0" + }, + { + "name": "puppetlabs/concat", + "version_requirement": ">= 9.0.0 < 10.0.0" } ], "operatingsystem_support": [ diff --git a/spec/classes/otelcol_spec.rb b/spec/classes/otelcol_spec.rb index 5f6a43f..ef1e132 100644 --- a/spec/classes/otelcol_spec.rb +++ b/spec/classes/otelcol_spec.rb @@ -8,41 +8,19 @@ let(:facts) do facts end - - let(:configcontent) do - { - 'receivers' => { - 'otlp' => { - 'protocols' => { - 'http' => {}, - 'grpc' => {}, - }, - }, - }, - 'processors' => {}, - 'exporters' => {}, - 'extensions' => {}, - 'service' => { - 'extensions' => [], - 'pipelines' => {}, - 'telemetry' => { - 'logs' => {}, - 'metrics' => { - 'level' => 'basic', - 'address' => ':8888', - }, - }, - }, - - } - end - + context 'default include' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('otelcol::config') - is_expected.to contain_file('otelcol-config').with_path('/etc/otelcol/config.yaml') + is_expected.to contain_concat('otelcol-config').with({ + 'path' => '/etc/otelcol/config.yaml', + 'format' => 'yaml', + }) + is_expected.to contain_concat__fragment('otelcol-config-header') + is_expected.to contain_concat__fragment('otelcol-config-baseconfig') + is_expected.to contain_concat__fragment('otelcol-config-footer') is_expected.to contain_file('otelcol-environment').with_path('/etc/otelcol/otelcol.conf') is_expected.to contain_file('otelcol-environment').with_content(%r{--config=/etc/otelcol/config.yaml"}) } @@ -72,7 +50,7 @@ it { is_expected.to contain_class('otelcol::config') - is_expected.to contain_file('otelcol-config').with_path('/etc/otelcol-contrib/config.yaml') + is_expected.to contain_concat('otelcol-config').with_path('/etc/otelcol-contrib/config.yaml') # is_expected.to contain_file('otelcol-config').with_content(%r{"otlp":\s\{\s"protocols":\s\{\s"http":}) is_expected.to contain_file('otelcol-environment').with_path('/etc/otelcol-contrib/otelcol-contrib.conf') @@ -80,7 +58,7 @@ } it { # Validate vaild YAML for config - is_expected.to contain_file('otelcol-config').with_content(configcontent.to_yaml) + is_expected.to contain_concat('otelcol-config')# .with_content(configcontent.to_yaml) # yaml_object = YAML.load(catalogue.resource('file', 'otelcol-config').send(:parameters)[:content]) # expect(yaml_object.length).to be > 0 } @@ -105,9 +83,9 @@ let(:package_source) do case facts[:osfamily] when 'Debian' - 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.79.0/otelcol-contrib_0.79.0_linux_amd64.deb' + 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.89.0/otelcol-contrib_0.89.0_linux_amd64.deb' when 'RedHat' - 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.79.0/otelcol-contrib_0.79.0_linux_amd64.rpm' + 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.89.0/otelcol-contrib_0.89.0_linux_amd64.rpm' end end let(:package_localpath) do @@ -163,7 +141,7 @@ it { is_expected.to compile.with_all_deps } it { - is_expected.to contain_file('otelcol-config').with_path('/etc/otelcol/test.conf') + is_expected.to contain_concat('otelcol-config').with_path('/etc/otelcol/test.conf') is_expected.to contain_file('otelcol-environment').with_content(%r{--config=/etc/otelcol/test.conf"}) } end @@ -180,7 +158,7 @@ it { is_expected.to compile.with_all_deps } it { - is_expected.to contain_file('otelcol-config').with( + is_expected.to contain_concat('otelcol-config').with( 'owner' => 'root', 'group' => 'root', 'mode' => '0600' @@ -196,12 +174,17 @@ }, } end - let(:configcontent_ext) do - configcontent.merge({ 'receivers' => { 'test' => {} } }) - end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_otelcol__receiver('test').with({ + 'config' => {}, + 'pipelines' => [], + 'order' => 0, + 'name' => 'test', + }) + is_expected.to contain_otelcol__component('test-receivers') + is_expected.to contain_concat__fragment('otelcol-config-receivers-test') + } end context 'with processors' do @@ -212,12 +195,17 @@ }, } end - let(:configcontent_ext) do - configcontent.merge({ 'processors' => { 'test' => {} } }) - end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_otelcol__processor('test').with({ + 'config' => {}, + 'pipelines' => [], + 'order' => 0, + 'name' => 'test', + }) + is_expected.to contain_otelcol__component('test-processors') + is_expected.to contain_concat__fragment('otelcol-config-processors-test') + } end context 'with exporters' do @@ -228,12 +216,17 @@ }, } end - let(:configcontent_ext) do - configcontent.merge({ 'exporters' => { 'test' => {} } }) - end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_otelcol__exporter('test').with({ + 'config' => {}, + 'pipelines' => [], + 'order' => 0, + 'name' => 'test', + }) + is_expected.to contain_otelcol__component('test-exporter') + is_expected.to contain_concat__fragment('otelcol-config-exporters-test') + } end context 'with pipelines' do @@ -244,26 +237,15 @@ }, } end - let(:configcontent_ext) do - configcontent.merge( - { - 'service' => { - 'extensions' => [], - 'pipelines' => { 'test' => {} }, - 'telemetry' => { - 'logs' => {}, - 'metrics' => { - 'level' => 'basic', - 'address' => ':8888', - }, - }, - }, - } - ) - end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_otelcol__pipeline('test').with({ + 'config' => {}, + 'order' => 0, + 'name' => 'test', + }) + is_expected.to contain_concat__fragment('otelcol-config-pipeline-test') + } end context 'with extensions' do @@ -274,60 +256,48 @@ }, } end - let(:configcontent_ext) do - configcontent.merge( - { - 'extensions' => { 'test' => {} }, - 'service' => { - 'extensions' => ['test'], - 'pipelines' => {}, - 'telemetry' => { - 'logs' => {}, - 'metrics' => { - 'level' => 'basic', - 'address' => ':8888', - }, - }, - } - } - ) - end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_otelcol__extension('test').with({ + 'config' => {}, + 'order' => 0, + 'name' => 'test', + }) + is_expected.to contain_concat__fragment('otelcol-config-extension-test') + } end - context 'with include files' do - let :params do - { - processors: '${file:processors.yaml}', - exporters: '${file:exporters.yaml}', - pipelines: '${file:pipelines.yaml}', - } - end - let(:configcontent_ext) do - configcontent.merge( - { - 'processors' => '${file:processors.yaml}', - 'exporters' => '${file:exporters.yaml}', - 'service' => { - 'extensions' => [], - 'pipelines' => '${file:pipelines.yaml}', - 'telemetry' => { - 'logs' => {}, - 'metrics' => { - 'level' => 'basic', - 'address' => ':8888', - }, - }, - } - } - ) - end - - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } - end + # context 'with include files' do + # let :params do + # { + # processors: '${file:processors.yaml}', + # exporters: '${file:exporters.yaml}', + # pipelines: '${file:pipelines.yaml}', + # } + # end + # let(:configcontent_ext) do + # configcontent.merge( + # { + # 'processors' => '${file:processors.yaml}', + # 'exporters' => '${file:exporters.yaml}', + # 'service' => { + # 'extensions' => [], + # 'pipelines' => '${file:pipelines.yaml}', + # 'telemetry' => { + # 'logs' => {}, + # 'metrics' => { + # 'level' => 'basic', + # 'address' => ':8888', + # }, + # }, + # } + # } + # ) + # end + + # it { is_expected.to compile.with_all_deps } + # # it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + # end context 'with logoptions' do let :params do @@ -337,29 +307,24 @@ }, } end - let(:configcontent_ext) do - configcontent.merge( - { - 'extensions' => {}, - 'service' => { - 'extensions' => [], - 'pipelines' => {}, - 'telemetry' => { - 'logs' => { - 'level' => 'debug' - }, - 'metrics' => { - 'level' => 'basic', - 'address' => ':8888', - }, + let(:configcontent) do + { + 'service' => { + 'telemetry' => { + 'logs' => { + 'level' => 'debug' }, - } + 'metrics' => { + 'level' => 'basic', + 'address' => ':8888', + }, + }, } - ) + } end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_concat__fragment('otelcol-config-baseconfig').with_content(configcontent.to_yaml) } end context 'with metrics config' do @@ -370,27 +335,22 @@ metrics_address_port: 1234, } end - let(:configcontent_ext) do - configcontent.merge( - { - 'extensions' => {}, - 'service' => { - 'extensions' => [], - 'pipelines' => {}, - 'telemetry' => { - 'logs' => {}, - 'metrics' => { - 'level' => 'detailed', - 'address' => '127.0.0.1:1234', - }, + let(:configcontent) do + { + 'service' => { + 'telemetry' => { + 'logs' => {}, + 'metrics' => { + 'level' => 'detailed', + 'address' => '127.0.0.1:1234', }, - } + }, } - ) + } end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } + it { is_expected.to contain_concat__fragment('otelcol-config-baseconfig').with_content(configcontent.to_yaml) } end context 'with service_ensure' do @@ -425,9 +385,9 @@ let(:package_source) do case facts[:osfamily] when 'Debian' - 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.79.0/otelcol_0.79.0_linux_amd64.deb' + 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.89.0/otelcol_0.89.0_linux_amd64.deb' when 'RedHat' - 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.79.0/otelcol_0.79.0_linux_amd64.rpm' + 'https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.89.0/otelcol_0.89.0_linux_amd64.rpm' end end let(:package_localpath) do diff --git a/spec/defines/component_spec.rb b/spec/defines/component_spec.rb new file mode 100644 index 0000000..8cf58f7 --- /dev/null +++ b/spec/defines/component_spec.rb @@ -0,0 +1,108 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'otelcol::component' do + let(:title) { 'otlp-receivers' } + let(:params) do + { + 'config' => { + 'key' => 'value', + }, + 'type' => 'receivers', + 'component_name' => 'otlp' + } + end + + let(:configcontent) do + { + 'receivers' => { + 'otlp' => { + 'key' => 'value', + }, + }, + } + end + + + let(:configcontentpipeline) do + { + 'service' => { + 'pipelines' => { + 'test' => { + 'receivers' => ['otlp'], + } + }, + }, + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp') } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_content(configcontent.to_yaml) } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_order(0) } + + # Create Checks for importer with extended parameters with order + context 'with order' do + let :params do + super().merge({'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_order(1) } + end + + # Create Check for importer with extended parameters with pipelines array + context 'with pipelines array' do + let :params do + super().merge({'pipelines' => ['test']}) + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test') } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test').with_content(configcontentpipeline.to_yaml) } + end + + # Create Check for importer with extended parameters with pipelines array + context 'with pipelines array' do + let(:params) do + super().merge({'pipelines' => ['test', 'test2']}) + end + + let(:configcontentpipeline2) do + { + 'service' => { + 'pipelines' => { + 'test2' => { + 'receivers' => ['otlp'], + } + }, + }, + } + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test') } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test').with_content(configcontentpipeline.to_yaml) } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test2') } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test2').with_content(configcontentpipeline2.to_yaml) } + end + + # Create Check for importer with extended parameters with pipelines array and order + context 'with pipelines array and order' do + let(:params) do + super().merge({'pipelines' => ['test'], 'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test') } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test').with_content(configcontentpipeline.to_yaml) } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test').with_order(1) } + end + end + end +end diff --git a/spec/defines/exporter_spec.rb b/spec/defines/exporter_spec.rb new file mode 100644 index 0000000..872cd6e --- /dev/null +++ b/spec/defines/exporter_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'otelcol::exporter' do + let(:title) { 'otlp' } + let(:params) do + { + 'config' => { + 'key' => 'value', + } + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + it { is_expected.to contain_otelcol__component('otlp-exporter').with({ + 'order' => 3000, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'exporters', + 'component_name' => 'otlp', + }) } + it { + is_expected.to contain_concat__fragment('otelcol-config-exporters-otlp').with({ + 'order' => 3000, + 'target' => 'otelcol-config', + }) + } + + + context 'with order' do + let :params do + super().merge({'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_otelcol__component('otlp-exporter').with({ + 'order' => 3001, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'exporters', + 'component_name' => 'otlp', + }) } + end + + end + end +end diff --git a/spec/defines/extension_spec.rb b/spec/defines/extension_spec.rb new file mode 100644 index 0000000..c315e61 --- /dev/null +++ b/spec/defines/extension_spec.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'otelcol::extension' do + let(:title) { 'health_check' } + let(:params) do + { + 'config' => {}, + } + end + + let(:configcontent) do + { + 'extensions' => { + 'health_check' => {}, + }, + 'service' => { + 'extensions' => ['health_check'], + }, + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-extension-health_check').with({ + 'order' => 4000, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) + } + + + context 'with order' do + let :params do + super().merge({'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-extension-health_check').with({ + 'order' => 4001, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) + } + end + end + end +end diff --git a/spec/defines/pipeline_spec.rb b/spec/defines/pipeline_spec.rb new file mode 100644 index 0000000..65b8b2d --- /dev/null +++ b/spec/defines/pipeline_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'otelcol::pipeline' do + let(:title) { 'mypipeline' } + let(:params) do + { + 'config' => {}, + } + end + + let(:configcontent) do + { + 'service' => { + 'pipelines' => { + 'mypipeline' => {}, + }, + }, + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-pipeline-mypipeline').with({ + 'order' => 5000, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) + } + + + context 'with order' do + let :params do + super().merge({'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-pipeline-mypipeline').with({ + 'order' => 5001, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) + } + end + end + end +end diff --git a/spec/defines/processor_spec.rb b/spec/defines/processor_spec.rb new file mode 100644 index 0000000..9a3e3ab --- /dev/null +++ b/spec/defines/processor_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'otelcol::processor' do + let(:title) { 'batch' } + let(:params) do + { + 'config' => { + 'key' => 'value', + } + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + it { is_expected.to contain_otelcol__component('batch-processors').with({ + 'order' => 2000, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'processors', + 'component_name' => 'batch', + }) } + it { + is_expected.to contain_concat__fragment('otelcol-config-processors-batch').with({ + 'order' => 2000, + 'target' => 'otelcol-config', + }) + } + + + context 'with order' do + let :params do + super().merge({'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_otelcol__component('batch-processors').with({ + 'order' => 2001, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'processors', + 'component_name' => 'batch', + }) } + end + + end + end +end diff --git a/spec/defines/receiver_spec.rb b/spec/defines/receiver_spec.rb new file mode 100644 index 0000000..82a12c6 --- /dev/null +++ b/spec/defines/receiver_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'otelcol::receiver' do + let(:title) { 'otlp' } + let(:params) do + { + 'config' => { + 'key' => 'value', + } + } + end + + on_supported_os.each do |os, os_facts| + context "on #{os}" do + let(:facts) { os_facts } + + it { is_expected.to compile } + it { is_expected.to contain_otelcol__component('otlp-receivers').with({ + 'order' => 1000, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'receivers', + 'component_name' => 'otlp', + }) } + it { + is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with({ + 'order' => 1000, + 'target' => 'otelcol-config', + }) + } + + + context 'with order' do + let :params do + super().merge({'order' => 1}) + end + + it { is_expected.to compile } + it { is_expected.to contain_otelcol__component('otlp-receivers').with({ + 'order' => 1001, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'receivers', + 'component_name' => 'otlp', + }) } + end + + end + end +end diff --git a/templates/component.yml.erb b/templates/component.yml.erb new file mode 100644 index 0000000..7d961a8 --- /dev/null +++ b/templates/component.yml.erb @@ -0,0 +1 @@ +<%= @component.to_yaml %> \ No newline at end of file diff --git a/templates/config-footer.yml.erb b/templates/config-footer.yml.erb new file mode 100644 index 0000000..e69de29 diff --git a/templates/config-header.yml.erb b/templates/config-header.yml.erb new file mode 100644 index 0000000..04f8fdc --- /dev/null +++ b/templates/config-header.yml.erb @@ -0,0 +1 @@ +# File Managed by Puppet \ No newline at end of file From a4e1dd69da90b5fd424f3f35401a2161d0e35a7d Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Wed, 22 Nov 2023 16:32:14 +0100 Subject: [PATCH 02/39] Fix static tests --- spec/classes/otelcol_spec.rb | 76 +++++++++++++++++++--------------- spec/defines/component_spec.rb | 52 ++++++++++++----------- spec/defines/exporter_spec.rb | 53 +++++++++++++----------- spec/defines/extension_spec.rb | 41 +++++++++--------- spec/defines/pipeline_spec.rb | 27 ++++++------ spec/defines/processor_spec.rb | 53 +++++++++++++----------- spec/defines/receiver_spec.rb | 53 +++++++++++++----------- 7 files changed, 195 insertions(+), 160 deletions(-) diff --git a/spec/classes/otelcol_spec.rb b/spec/classes/otelcol_spec.rb index ef1e132..0abf452 100644 --- a/spec/classes/otelcol_spec.rb +++ b/spec/classes/otelcol_spec.rb @@ -8,16 +8,16 @@ let(:facts) do facts end - + context 'default include' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('otelcol::config') is_expected.to contain_concat('otelcol-config').with({ - 'path' => '/etc/otelcol/config.yaml', - 'format' => 'yaml', - }) + 'path' => '/etc/otelcol/config.yaml', + 'format' => 'yaml', + }) is_expected.to contain_concat__fragment('otelcol-config-header') is_expected.to contain_concat__fragment('otelcol-config-baseconfig') is_expected.to contain_concat__fragment('otelcol-config-footer') @@ -58,7 +58,7 @@ } it { # Validate vaild YAML for config - is_expected.to contain_concat('otelcol-config')# .with_content(configcontent.to_yaml) + is_expected.to contain_concat('otelcol-config') # .with_content(configcontent.to_yaml) # yaml_object = YAML.load(catalogue.resource('file', 'otelcol-config').send(:parameters)[:content]) # expect(yaml_object.length).to be > 0 } @@ -176,12 +176,14 @@ end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_otelcol__receiver('test').with({ - 'config' => {}, - 'pipelines' => [], - 'order' => 0, - 'name' => 'test', - }) + + it { + is_expected.to contain_otelcol__receiver('test').with({ + 'config' => {}, + 'pipelines' => [], + 'order' => 0, + 'name' => 'test', + }) is_expected.to contain_otelcol__component('test-receivers') is_expected.to contain_concat__fragment('otelcol-config-receivers-test') } @@ -197,12 +199,14 @@ end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_otelcol__processor('test').with({ - 'config' => {}, - 'pipelines' => [], - 'order' => 0, - 'name' => 'test', - }) + + it { + is_expected.to contain_otelcol__processor('test').with({ + 'config' => {}, + 'pipelines' => [], + 'order' => 0, + 'name' => 'test', + }) is_expected.to contain_otelcol__component('test-processors') is_expected.to contain_concat__fragment('otelcol-config-processors-test') } @@ -218,12 +222,14 @@ end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_otelcol__exporter('test').with({ - 'config' => {}, - 'pipelines' => [], - 'order' => 0, - 'name' => 'test', - }) + + it { + is_expected.to contain_otelcol__exporter('test').with({ + 'config' => {}, + 'pipelines' => [], + 'order' => 0, + 'name' => 'test', + }) is_expected.to contain_otelcol__component('test-exporter') is_expected.to contain_concat__fragment('otelcol-config-exporters-test') } @@ -239,11 +245,13 @@ end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_otelcol__pipeline('test').with({ - 'config' => {}, - 'order' => 0, - 'name' => 'test', - }) + + it { + is_expected.to contain_otelcol__pipeline('test').with({ + 'config' => {}, + 'order' => 0, + 'name' => 'test', + }) is_expected.to contain_concat__fragment('otelcol-config-pipeline-test') } end @@ -258,11 +266,13 @@ end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_otelcol__extension('test').with({ - 'config' => {}, - 'order' => 0, - 'name' => 'test', - }) + + it { + is_expected.to contain_otelcol__extension('test').with({ + 'config' => {}, + 'order' => 0, + 'name' => 'test', + }) is_expected.to contain_concat__fragment('otelcol-config-extension-test') } end diff --git a/spec/defines/component_spec.rb b/spec/defines/component_spec.rb index 8cf58f7..61a3df0 100644 --- a/spec/defines/component_spec.rb +++ b/spec/defines/component_spec.rb @@ -9,22 +9,11 @@ 'config' => { 'key' => 'value', }, - 'type' => 'receivers', + 'type' => 'receivers', 'component_name' => 'otlp' } end - let(:configcontent) do - { - 'receivers' => { - 'otlp' => { - 'key' => 'value', - }, - }, - } - end - - let(:configcontentpipeline) do { 'service' => { @@ -41,15 +30,27 @@ context "on #{os}" do let(:facts) { os_facts } - it { is_expected.to compile } - it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp') } - it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_content(configcontent.to_yaml) } - it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_order(0) } + context 'Base test' do + let(:configcontent) do + { + 'receivers' => { + 'otlp' => { + 'key' => 'value', + }, + }, + } + end + + it { is_expected.to compile } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp') } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_content(configcontent.to_yaml) } + it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with_order(0) } + end # Create Checks for importer with extended parameters with order context 'with order' do let :params do - super().merge({'order' => 1}) + super().merge({ 'order' => 1 }) end it { is_expected.to compile } @@ -59,7 +60,7 @@ # Create Check for importer with extended parameters with pipelines array context 'with pipelines array' do let :params do - super().merge({'pipelines' => ['test']}) + super().merge({ 'pipelines' => ['test'] }) end it { is_expected.to compile } @@ -68,12 +69,12 @@ end # Create Check for importer with extended parameters with pipelines array - context 'with pipelines array' do + context 'with multiple pipeline entries' do let(:params) do - super().merge({'pipelines' => ['test', 'test2']}) + super().merge({ 'pipelines' => %w[test test2] }) end - let(:configcontentpipeline2) do + let(:configcontentpipelinetest2) do { 'service' => { 'pipelines' => { @@ -88,14 +89,17 @@ it { is_expected.to compile } it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test') } it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test').with_content(configcontentpipeline.to_yaml) } - it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test2') } - it { is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test2').with_content(configcontentpipeline2.to_yaml) } + + it { + is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test2') + is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp-test2').with_content(configcontentpipelinetest2.to_yaml) + } end # Create Check for importer with extended parameters with pipelines array and order context 'with pipelines array and order' do let(:params) do - super().merge({'pipelines' => ['test'], 'order' => 1}) + super().merge({ 'pipelines' => ['test'], 'order' => 1 }) end it { is_expected.to compile } diff --git a/spec/defines/exporter_spec.rb b/spec/defines/exporter_spec.rb index 872cd6e..31e2c55 100644 --- a/spec/defines/exporter_spec.rb +++ b/spec/defines/exporter_spec.rb @@ -17,40 +17,45 @@ let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_otelcol__component('otlp-exporter').with({ - 'order' => 3000, - 'config' => { - 'key' => 'value', - }, - 'pipelines' => [], - 'type' => 'exporters', - 'component_name' => 'otlp', - }) } + it { - is_expected.to contain_concat__fragment('otelcol-config-exporters-otlp').with({ - 'order' => 3000, - 'target' => 'otelcol-config', - }) + is_expected.to contain_otelcol__component('otlp-exporter').with({ + 'order' => 3000, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'exporters', + 'component_name' => 'otlp', + }) } + it { + is_expected.to contain_concat__fragment('otelcol-config-exporters-otlp').with({ + 'order' => 3000, + 'target' => 'otelcol-config', + }) + } context 'with order' do let :params do - super().merge({'order' => 1}) + super().merge({ 'order' => 1 }) end it { is_expected.to compile } - it { is_expected.to contain_otelcol__component('otlp-exporter').with({ - 'order' => 3001, - 'config' => { - 'key' => 'value', - }, - 'pipelines' => [], - 'type' => 'exporters', - 'component_name' => 'otlp', - }) } - end + it { + is_expected.to contain_otelcol__component('otlp-exporter').with({ + 'order' => 3001, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'exporters', + 'component_name' => 'otlp', + }) + } + end end end end diff --git a/spec/defines/extension_spec.rb b/spec/defines/extension_spec.rb index c315e61..5a13cbd 100644 --- a/spec/defines/extension_spec.rb +++ b/spec/defines/extension_spec.rb @@ -12,13 +12,13 @@ let(:configcontent) do { - 'extensions' => { - 'health_check' => {}, - }, - 'service' => { - 'extensions' => ['health_check'], - }, - } + 'extensions' => { + 'health_check' => {}, + }, + 'service' => { + 'extensions' => ['health_check'], + }, + } end on_supported_os.each do |os, os_facts| @@ -26,25 +26,28 @@ let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_concat__fragment('otelcol-config-extension-health_check').with({ - 'order' => 4000, - 'target' => 'otelcol-config', - 'content' => configcontent.to_yaml, - }) - } + it { + is_expected.to contain_concat__fragment('otelcol-config-extension-health_check').with({ + 'order' => 4000, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) + } context 'with order' do let :params do - super().merge({'order' => 1}) + super().merge({ 'order' => 1 }) end it { is_expected.to compile } - it { is_expected.to contain_concat__fragment('otelcol-config-extension-health_check').with({ - 'order' => 4001, - 'target' => 'otelcol-config', - 'content' => configcontent.to_yaml, - }) + + it { + is_expected.to contain_concat__fragment('otelcol-config-extension-health_check').with({ + 'order' => 4001, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) } end end diff --git a/spec/defines/pipeline_spec.rb b/spec/defines/pipeline_spec.rb index 65b8b2d..5932ce6 100644 --- a/spec/defines/pipeline_spec.rb +++ b/spec/defines/pipeline_spec.rb @@ -25,25 +25,28 @@ let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_concat__fragment('otelcol-config-pipeline-mypipeline').with({ - 'order' => 5000, - 'target' => 'otelcol-config', - 'content' => configcontent.to_yaml, - }) - } + it { + is_expected.to contain_concat__fragment('otelcol-config-pipeline-mypipeline').with({ + 'order' => 5000, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) + } context 'with order' do let :params do - super().merge({'order' => 1}) + super().merge({ 'order' => 1 }) end it { is_expected.to compile } - it { is_expected.to contain_concat__fragment('otelcol-config-pipeline-mypipeline').with({ - 'order' => 5001, - 'target' => 'otelcol-config', - 'content' => configcontent.to_yaml, - }) + + it { + is_expected.to contain_concat__fragment('otelcol-config-pipeline-mypipeline').with({ + 'order' => 5001, + 'target' => 'otelcol-config', + 'content' => configcontent.to_yaml, + }) } end end diff --git a/spec/defines/processor_spec.rb b/spec/defines/processor_spec.rb index 9a3e3ab..5e8e156 100644 --- a/spec/defines/processor_spec.rb +++ b/spec/defines/processor_spec.rb @@ -17,40 +17,45 @@ let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_otelcol__component('batch-processors').with({ - 'order' => 2000, - 'config' => { - 'key' => 'value', - }, - 'pipelines' => [], - 'type' => 'processors', - 'component_name' => 'batch', - }) } + it { - is_expected.to contain_concat__fragment('otelcol-config-processors-batch').with({ - 'order' => 2000, - 'target' => 'otelcol-config', - }) + is_expected.to contain_otelcol__component('batch-processors').with({ + 'order' => 2000, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'processors', + 'component_name' => 'batch', + }) } + it { + is_expected.to contain_concat__fragment('otelcol-config-processors-batch').with({ + 'order' => 2000, + 'target' => 'otelcol-config', + }) + } context 'with order' do let :params do - super().merge({'order' => 1}) + super().merge({ 'order' => 1 }) end it { is_expected.to compile } - it { is_expected.to contain_otelcol__component('batch-processors').with({ - 'order' => 2001, - 'config' => { - 'key' => 'value', - }, - 'pipelines' => [], - 'type' => 'processors', - 'component_name' => 'batch', - }) } - end + it { + is_expected.to contain_otelcol__component('batch-processors').with({ + 'order' => 2001, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'processors', + 'component_name' => 'batch', + }) + } + end end end end diff --git a/spec/defines/receiver_spec.rb b/spec/defines/receiver_spec.rb index 82a12c6..dc7b07c 100644 --- a/spec/defines/receiver_spec.rb +++ b/spec/defines/receiver_spec.rb @@ -17,40 +17,45 @@ let(:facts) { os_facts } it { is_expected.to compile } - it { is_expected.to contain_otelcol__component('otlp-receivers').with({ - 'order' => 1000, - 'config' => { - 'key' => 'value', - }, - 'pipelines' => [], - 'type' => 'receivers', - 'component_name' => 'otlp', - }) } + it { - is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with({ - 'order' => 1000, - 'target' => 'otelcol-config', - }) + is_expected.to contain_otelcol__component('otlp-receivers').with({ + 'order' => 1000, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'receivers', + 'component_name' => 'otlp', + }) } + it { + is_expected.to contain_concat__fragment('otelcol-config-receivers-otlp').with({ + 'order' => 1000, + 'target' => 'otelcol-config', + }) + } context 'with order' do let :params do - super().merge({'order' => 1}) + super().merge({ 'order' => 1 }) end it { is_expected.to compile } - it { is_expected.to contain_otelcol__component('otlp-receivers').with({ - 'order' => 1001, - 'config' => { - 'key' => 'value', - }, - 'pipelines' => [], - 'type' => 'receivers', - 'component_name' => 'otlp', - }) } - end + it { + is_expected.to contain_otelcol__component('otlp-receivers').with({ + 'order' => 1001, + 'config' => { + 'key' => 'value', + }, + 'pipelines' => [], + 'type' => 'receivers', + 'component_name' => 'otlp', + }) + } + end end end end From 63216c006749632adc3023dfc55da8b769d015b0 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Wed, 22 Nov 2023 17:05:11 +0100 Subject: [PATCH 03/39] Fix stdlib/concat requirement --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index cf7acc5..293842d 100644 --- a/metadata.json +++ b/metadata.json @@ -10,7 +10,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">= 8.0.0 < 9.0.0" + "version_requirement": ">= 9.0.0 < 10.0.0" }, { "name": "puppetlabs/concat", From 17fe1f98e516f9c691cbd9eb3614ce469990d962 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:04:20 +0100 Subject: [PATCH 04/39] Update examples/basic_installation.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- examples/basic_installation.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic_installation.pp b/examples/basic_installation.pp index 00cc906..9007b41 100644 --- a/examples/basic_installation.pp +++ b/examples/basic_installation.pp @@ -1,4 +1,4 @@ -Otelcol::Receiver { 'otlp' : +otelcol::receiver { 'otlp' : config => { 'protocols' => { 'grpc' => { 'endpoint' => 'localhost:4317' }, From fb92a02d319674f9d4c7f44f369d6f9b57c1082f Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:05:03 +0100 Subject: [PATCH 05/39] Update manifests/config.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/config.pp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index cfc836e..818ebb5 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -55,8 +55,7 @@ $otelcol::receivers.each|String $rname, Hash $rvalue| { if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { ensure_resource('Otelcol::Receiver', $rname, $rvalue) - } - else { + } else { ensure_resource('Otelcol::Receiver', $rname, { 'config' => $rvalue }) } } From 3115907f0f3494d59c7761e2206d8ecc7b4f3c48 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:05:24 +0100 Subject: [PATCH 06/39] Update manifests/receiver.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/receiver.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/receiver.pp b/manifests/receiver.pp index 3a96f74..93ab6aa 100644 --- a/manifests/receiver.pp +++ b/manifests/receiver.pp @@ -16,7 +16,7 @@ Array[String[1]] $pipelines = [], ) { $real_order = 1000+$order - Otelcol::Component { "${name}-receivers": + otelcol::component { "${name}-receivers": order => $real_order, config => $config, pipelines => $pipelines, From 19cdbacbfc2c249f8bb11aba9ef14430bc1537e2 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:05:47 +0100 Subject: [PATCH 07/39] Update manifests/config.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 818ebb5..bd5cc5f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -53,7 +53,7 @@ if($otelcol::receivers) { $otelcol::receivers.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + if $rvalue['config'] =~ Hash { ensure_resource('Otelcol::Receiver', $rname, $rvalue) } else { ensure_resource('Otelcol::Receiver', $rname, { 'config' => $rvalue }) From 464545567b20abf8cdeb078dd6325deec441d3ab Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:06:07 +0100 Subject: [PATCH 08/39] Update manifests/init.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 999e049..25c3041 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -56,7 +56,7 @@ String $config_file_owner = 'root', String $config_file_group = 'root', Stdlib::Filemode $config_file_mode = '0644', - Optional[Hash] $receivers = undef, + Hash[String, Hash] $receivers = {}, Variant[Hash,String[1]] $processors = {}, Variant[Hash,String[1]] $exporters = {}, Variant[Hash,String[1]] $pipelines = {}, From 5d1f44aa6fb71cabc1377d74956b157cb9c24a58 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:06:23 +0100 Subject: [PATCH 09/39] Update manifests/config.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/config.pp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index bd5cc5f..ce6b818 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -51,8 +51,7 @@ mode => $otelcol::config_file_mode, } - if($otelcol::receivers) { - $otelcol::receivers.each|String $rname, Hash $rvalue| { + $otelcol::receivers.each|String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { ensure_resource('Otelcol::Receiver', $rname, $rvalue) } else { From dbafc49e270b038bf0bb5ea4df0b0422b49b6506 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:09:26 +0100 Subject: [PATCH 10/39] Fix Syntax --- manifests/config.pp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index ce6b818..56855a1 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -52,11 +52,10 @@ } $otelcol::receivers.each|String $rname, Hash $rvalue| { - if $rvalue['config'] =~ Hash { - ensure_resource('Otelcol::Receiver', $rname, $rvalue) - } else { - ensure_resource('Otelcol::Receiver', $rname, { 'config' => $rvalue }) - } + if $rvalue['config'] =~ Hash { + ensure_resource('Otelcol::Receiver', $rname, $rvalue) + } else { + ensure_resource('Otelcol::Receiver', $rname, { 'config' => $rvalue }) } } From ce3465ba9fda7e44f99487234f5335130521d3f4 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:15:25 +0100 Subject: [PATCH 11/39] Update Reference --- REFERENCE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 0a290ce..09d2d02 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -139,11 +139,11 @@ Default value: `'0644'` ##### `receivers` -Data type: `Optional[Hash]` +Data type: `Hash[String, Hash]` Hash for receivers config -Default value: `undef` +Default value: `{}` ##### `processors` From 839efadfc76517b7dd8e1580a08cfdc4b994fd75 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 10:16:03 +0100 Subject: [PATCH 12/39] Remove templates and replace with stdlib::to_yaml($component) in puppet code --- manifests/component.pp | 4 ++-- manifests/config.pp | 3 +-- manifests/extension.pp | 2 +- manifests/pipeline.pp | 2 +- manifests/receiver.pp | 8 ++++---- templates/component.yml.erb | 1 - templates/config.yml.erb | 1 - 7 files changed, 9 insertions(+), 12 deletions(-) delete mode 100644 templates/component.yml.erb delete mode 100644 templates/config.yml.erb diff --git a/manifests/component.pp b/manifests/component.pp index b7bd8b8..177c4fd 100644 --- a/manifests/component.pp +++ b/manifests/component.pp @@ -35,7 +35,7 @@ concat::fragment { "otelcol-config-${type}-${component_name}" : target => 'otelcol-config', order => $order, - content => template('otelcol/component.yml.erb'), + content => stdlib::to_yaml($component), } $pipelines.each |String $pipeline| { @@ -51,7 +51,7 @@ concat::fragment { "otelcol-config-${type}-${component_name}-${pipeline}" : target => 'otelcol-config', order => $order, - content => template('otelcol/component.yml.erb'), + content => stdlib::to_yaml($component), } } } diff --git a/manifests/config.pp b/manifests/config.pp index 56855a1..1c3b863 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -20,7 +20,6 @@ ensure => present, path => $otelcol::config_file, format => 'yaml', - # content => template('otelcol/config.yml.erb'), owner => $otelcol::config_file_owner, group => $otelcol::config_file_group, mode => $otelcol::config_file_mode, @@ -34,7 +33,7 @@ concat::fragment { 'otelcol-config-baseconfig' : target => 'otelcol-config', order => 10000, - content => template('otelcol/component.yml.erb'), + content => stdlib::to_yaml($component), } concat::fragment { 'otelcol-config-footer' : diff --git a/manifests/extension.pp b/manifests/extension.pp index 661c111..9b3e91a 100644 --- a/manifests/extension.pp +++ b/manifests/extension.pp @@ -25,6 +25,6 @@ concat::fragment { "otelcol-config-extension-${name}" : target => 'otelcol-config', order => $real_order, - content => template('otelcol/component.yml.erb'), + content => stdlib::to_yaml($component), } } diff --git a/manifests/pipeline.pp b/manifests/pipeline.pp index d71a25c..7c72f74 100644 --- a/manifests/pipeline.pp +++ b/manifests/pipeline.pp @@ -27,6 +27,6 @@ concat::fragment { "otelcol-config-pipeline-${name}" : target => 'otelcol-config', order => $real_order, - content => template('otelcol/component.yml.erb'), + content => stdlib::to_yaml($component), } } diff --git a/manifests/receiver.pp b/manifests/receiver.pp index 93ab6aa..d8b0b06 100644 --- a/manifests/receiver.pp +++ b/manifests/receiver.pp @@ -17,10 +17,10 @@ ) { $real_order = 1000+$order otelcol::component { "${name}-receivers": - order => $real_order, - config => $config, - pipelines => $pipelines, + order => $real_order, + config => $config, + pipelines => $pipelines, component_name => $name, - type => 'receivers', + type => 'receivers', } } diff --git a/templates/component.yml.erb b/templates/component.yml.erb deleted file mode 100644 index 7d961a8..0000000 --- a/templates/component.yml.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @component.to_yaml %> \ No newline at end of file diff --git a/templates/config.yml.erb b/templates/config.yml.erb deleted file mode 100644 index ab38c5d..0000000 --- a/templates/config.yml.erb +++ /dev/null @@ -1 +0,0 @@ -<%= @settings.to_yaml%> \ No newline at end of file From cab00918c5358c7a34fb29d73735f231608abe0b Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:38:33 +0100 Subject: [PATCH 13/39] Update contib example --- examples/contrib_installation.pp | 66 ++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/examples/contrib_installation.pp b/examples/contrib_installation.pp index 38febd4..1bcfa52 100644 --- a/examples/contrib_installation.pp +++ b/examples/contrib_installation.pp @@ -1,34 +1,42 @@ -class { 'otelcol': - manage_archive => true, - package_name => 'otelcol-contrib', - metrics_address_port => 8889, - receivers => { - 'otlp' => { - 'protocols' => { - 'grpc' => { 'endpoint' => 'localhost:4319' }, - 'http' => { 'endpoint' => 'localhost:4320' }, - }, - }, - 'prometheus' => { - 'config' => { - 'scrape_configs' => [ - { - 'job_name' => 'otel-collector', - 'scrape_interval' => '10s', - 'static_configs' => [ - { 'targets' => ['localhost:8889'] } - ], - }, - ], - }, +otelcol::receiver { 'otlp' : + config => { + 'protocols' => { + 'grpc' => { 'endpoint' => 'localhost:4319' }, + 'http' => { 'endpoint' => 'localhost:4320' }, }, }, - exporters => { 'logging' => { 'verbosity' => 'detailed' } }, - pipelines => { - 'metrics' => { - 'receivers' => ['otlp', 'prometheus'], - 'exporters' => ['logging'], + pipelines => ['metrics'], +} + +Otelcol::Receiver { 'prometheus' : + config => { + 'config' => { + 'scrape_configs' => [ + { + 'job_name' => 'otel-collector', + 'scrape_interval' => '10s', + 'static_configs' => [ + { 'targets' => ['localhost:8889'] } + ], + }, + ], }, }, - processors => { 'batch' => {} }, + pipelines => ['metrics'], +} + +Otelcol::Exporter { 'logging': + config => { 'verbosity' => 'detailed' }, + pipelines => ['metrics'], +} + +Otelcol::Processor { 'batch': + config => {}, + pipelines => ['metrics'], +} + +class { 'otelcol': + manage_archive => true, + package_name => 'otelcol-contrib', + metrics_address_port => 8889, } From 0c14901be50bc77dfab916c13ca9708a2d5fff70 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:44:23 +0100 Subject: [PATCH 14/39] Update manifests/config.pp Remove Template need Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index 1c3b863..b82917c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -27,7 +27,7 @@ concat::fragment { 'otelcol-config-header' : target => 'otelcol-config', order => 0, - content => template('otelcol/config-header.yml.erb'), + content => '# File Managed by Puppet', } concat::fragment { 'otelcol-config-baseconfig' : From 30281af6fdaa669cf19bef7f64b1dda0d5441474 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:43:13 +0100 Subject: [PATCH 15/39] Fix Fixtures --- .fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index d50c51e..456cc54 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -4,4 +4,4 @@ fixtures: forge_modules: stdlib: "puppetlabs/stdlib" - concat: "puppetlabs-concat" + concat: "puppetlabs/concat" From 58422bac05fee907de2874b499ce2fee66aca261 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:45:27 +0100 Subject: [PATCH 16/39] Remove Footer as it is not needed --- manifests/config.pp | 5 ----- templates/config-footer.yml.erb | 0 2 files changed, 5 deletions(-) delete mode 100644 templates/config-footer.yml.erb diff --git a/manifests/config.pp b/manifests/config.pp index b82917c..63cee93 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -36,11 +36,6 @@ content => stdlib::to_yaml($component), } - concat::fragment { 'otelcol-config-footer' : - target => 'otelcol-config', - order => 10001, - content => template('otelcol/config-footer.yml.erb'), - } file { 'otelcol-environment' : ensure => 'file', path => $otelcol::environment_file, diff --git a/templates/config-footer.yml.erb b/templates/config-footer.yml.erb deleted file mode 100644 index e69de29..0000000 From 0a5d88642edaf70835be4fd1c63d045d71ebef44 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:45:41 +0100 Subject: [PATCH 17/39] Remove template --- templates/config-header.yml.erb | 1 - 1 file changed, 1 deletion(-) delete mode 100644 templates/config-header.yml.erb diff --git a/templates/config-header.yml.erb b/templates/config-header.yml.erb deleted file mode 100644 index 04f8fdc..0000000 --- a/templates/config-header.yml.erb +++ /dev/null @@ -1 +0,0 @@ -# File Managed by Puppet \ No newline at end of file From ead9e7ca0844182045f290fc7ac44eca47d469ff Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:46:59 +0100 Subject: [PATCH 18/39] Update manifests/receiver.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/receiver.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/receiver.pp b/manifests/receiver.pp index d8b0b06..f50a5d8 100644 --- a/manifests/receiver.pp +++ b/manifests/receiver.pp @@ -8,7 +8,7 @@ # The order of the receiver # @param pipelines # The pipelines the receiver is part of -# @example +# @example basic receiver # otelcol::receiver { 'namevar': } define otelcol::receiver ( Hash $config = {}, From c77a7771ebff6276e4a72010a2e5551d6fba095e Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:50:21 +0100 Subject: [PATCH 19/39] Update examples/basic_installation.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- examples/basic_installation.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/basic_installation.pp b/examples/basic_installation.pp index 9007b41..29ad723 100644 --- a/examples/basic_installation.pp +++ b/examples/basic_installation.pp @@ -8,7 +8,7 @@ pipelines => ['metrics'], } -Otelcol::Receiver { 'prometheus' : +otelcol::receiver { 'prometheus' : config => { 'config' => { 'scrape_configs' => [ From 577d54246c47004c7ccbbe54a87105b73357a8d5 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:51:30 +0100 Subject: [PATCH 20/39] to lowercase --- examples/basic_installation.pp | 4 ++-- examples/contrib_installation.pp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/basic_installation.pp b/examples/basic_installation.pp index 29ad723..82cef72 100644 --- a/examples/basic_installation.pp +++ b/examples/basic_installation.pp @@ -25,12 +25,12 @@ pipelines => ['metrics'], } -Otelcol::Exporter { 'logging': +otelcol::exporter { 'logging': config => { 'verbosity' => 'detailed' }, pipelines => ['metrics'], } -Otelcol::Processor { 'batch': +otelcol::processor { 'batch': config => {}, pipelines => ['metrics'], } diff --git a/examples/contrib_installation.pp b/examples/contrib_installation.pp index 1bcfa52..7fb6ce9 100644 --- a/examples/contrib_installation.pp +++ b/examples/contrib_installation.pp @@ -8,7 +8,7 @@ pipelines => ['metrics'], } -Otelcol::Receiver { 'prometheus' : +otelcol::receiver { 'prometheus' : config => { 'config' => { 'scrape_configs' => [ @@ -25,12 +25,12 @@ pipelines => ['metrics'], } -Otelcol::Exporter { 'logging': +otelcol::exporter { 'logging': config => { 'verbosity' => 'detailed' }, pipelines => ['metrics'], } -Otelcol::Processor { 'batch': +otelcol::processor { 'batch': config => {}, pipelines => ['metrics'], } From 69d0cc722f7b4a010e635ce8b124e4b5fec1377b Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:52:51 +0100 Subject: [PATCH 21/39] to lowercase --- manifests/config.pp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 63cee93..4905d4e 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -47,19 +47,19 @@ $otelcol::receivers.each|String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { - ensure_resource('Otelcol::Receiver', $rname, $rvalue) + ensure_resource('otelcol::receiver', $rname, $rvalue) } else { - ensure_resource('Otelcol::Receiver', $rname, { 'config' => $rvalue }) + ensure_resource('otelcol::receiver', $rname, { 'config' => $rvalue }) } } if($otelcol::processors) { $otelcol::processors.each|String $rname, Hash $rvalue| { if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('Otelcol::Processor', $rname, $rvalue) + ensure_resource('otelcol::processor', $rname, $rvalue) } else { - ensure_resource('Otelcol::Processor', $rname, { 'config' => $rvalue }) + ensure_resource('otelcol::processor', $rname, { 'config' => $rvalue }) } } } @@ -67,10 +67,10 @@ if($otelcol::exporters) { $otelcol::exporters.each|String $rname, Hash $rvalue| { if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('Otelcol::Exporter', $rname, $rvalue) + ensure_resource('otelcol::exporter', $rname, $rvalue) } else { - ensure_resource('Otelcol::Exporter', $rname, { 'config' => $rvalue }) + ensure_resource('otelcol::exporter', $rname, { 'config' => $rvalue }) } } } @@ -78,10 +78,10 @@ if($otelcol::pipelines) { $otelcol::pipelines.each|String $rname, Hash $rvalue| { if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('Otelcol::Pipeline', $rname, $rvalue) + ensure_resource('otelcol::pipeline', $rname, $rvalue) } else { - ensure_resource('Otelcol::Pipeline', $rname, { 'config' => $rvalue }) + ensure_resource('otelcol::pipeline', $rname, { 'config' => $rvalue }) } } } @@ -89,10 +89,10 @@ if($otelcol::extensions) { $otelcol::extensions.each|String $rname, Hash $rvalue| { if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('Otelcol::Extension', $rname, $rvalue) + ensure_resource('otelcol::extension', $rname, $rvalue) } else { - ensure_resource('Otelcol::Extension', $rname, { 'config' => $rvalue }) + ensure_resource('otelcol::extension', $rname, { 'config' => $rvalue }) } } } From 0ec31d7c92329813d639c9f59b3251de63e16021 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 21:53:41 +0100 Subject: [PATCH 22/39] to lowercase --- manifests/exporter.pp | 2 +- manifests/processor.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/exporter.pp b/manifests/exporter.pp index 4a22734..07c0bfa 100644 --- a/manifests/exporter.pp +++ b/manifests/exporter.pp @@ -18,7 +18,7 @@ Array[String[1]] $pipelines = [], ) { $real_order = 3000+$order - Otelcol::Component { "${name}-exporter": + otelcol::component { "${name}-exporter": order => $real_order, config => $config, pipelines => $pipelines, diff --git a/manifests/processor.pp b/manifests/processor.pp index cb2088f..b178376 100644 --- a/manifests/processor.pp +++ b/manifests/processor.pp @@ -17,7 +17,7 @@ Array[String[1]] $pipelines = [], ) { $real_order = 2000+$order - Otelcol::Component { "${name}-processors": + otelcol::component { "${name}-processors": order => $real_order, config => $config, pipelines => $pipelines, From 5ad37c7958f2ca4b81a040172b0b8a3aa92e12ab Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 22:00:42 +0100 Subject: [PATCH 23/39] Fix Test after removal of footer --- spec/classes/otelcol_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/classes/otelcol_spec.rb b/spec/classes/otelcol_spec.rb index 0abf452..7ae161f 100644 --- a/spec/classes/otelcol_spec.rb +++ b/spec/classes/otelcol_spec.rb @@ -20,7 +20,6 @@ }) is_expected.to contain_concat__fragment('otelcol-config-header') is_expected.to contain_concat__fragment('otelcol-config-baseconfig') - is_expected.to contain_concat__fragment('otelcol-config-footer') is_expected.to contain_file('otelcol-environment').with_path('/etc/otelcol/otelcol.conf') is_expected.to contain_file('otelcol-environment').with_content(%r{--config=/etc/otelcol/config.yaml"}) } From 5a0d6a0434a84b553aac953d567b805bd048e49c Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 22:00:56 +0100 Subject: [PATCH 24/39] Simplify config --- manifests/config.pp | 56 +++++++++++++++++++-------------------------- manifests/init.pp | 8 +++---- 2 files changed, 28 insertions(+), 36 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 4905d4e..b5264c6 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -53,47 +53,39 @@ } } - if($otelcol::processors) { - $otelcol::processors.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('otelcol::processor', $rname, $rvalue) - } - else { - ensure_resource('otelcol::processor', $rname, { 'config' => $rvalue }) - } + $otelcol::processors.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('otelcol::processor', $rname, $rvalue) + } + else { + ensure_resource('otelcol::processor', $rname, { 'config' => $rvalue }) } } - if($otelcol::exporters) { - $otelcol::exporters.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('otelcol::exporter', $rname, $rvalue) - } - else { - ensure_resource('otelcol::exporter', $rname, { 'config' => $rvalue }) - } + $otelcol::exporters.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('otelcol::exporter', $rname, $rvalue) + } + else { + ensure_resource('otelcol::exporter', $rname, { 'config' => $rvalue }) } } - if($otelcol::pipelines) { - $otelcol::pipelines.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('otelcol::pipeline', $rname, $rvalue) - } - else { - ensure_resource('otelcol::pipeline', $rname, { 'config' => $rvalue }) - } + $otelcol::pipelines.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('otelcol::pipeline', $rname, $rvalue) + } + else { + ensure_resource('otelcol::pipeline', $rname, { 'config' => $rvalue }) } } - if($otelcol::extensions) { - $otelcol::extensions.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { - ensure_resource('otelcol::extension', $rname, $rvalue) - } - else { - ensure_resource('otelcol::extension', $rname, { 'config' => $rvalue }) - } + $otelcol::extensions.each|String $rname, Hash $rvalue| { + if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + ensure_resource('otelcol::extension', $rname, $rvalue) + } + else { + ensure_resource('otelcol::extension', $rname, { 'config' => $rvalue }) } } } diff --git a/manifests/init.pp b/manifests/init.pp index 25c3041..80d1ee9 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -57,10 +57,10 @@ String $config_file_group = 'root', Stdlib::Filemode $config_file_mode = '0644', Hash[String, Hash] $receivers = {}, - Variant[Hash,String[1]] $processors = {}, - Variant[Hash,String[1]] $exporters = {}, - Variant[Hash,String[1]] $pipelines = {}, - Hash $extensions = {}, + Hash[String, Hash] $processors = {}, + Hash[String, Hash] $exporters = {}, + Hash[String, Hash] $pipelines = {}, + Hash[String, Hash] $extensions = {}, Variant[Hash,String[1]] $log_options = {}, Enum['none','basic','normal','detailed'] $metrics_level = 'basic', Optional[Stdlib::Host] $metrics_address_host = undef, From 5217fdf20d3b80ffbe4e210c768a2eed1fcec73b Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 22:01:09 +0100 Subject: [PATCH 25/39] Update reference --- REFERENCE.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 09d2d02..6fb4dc9 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -147,7 +147,7 @@ Default value: `{}` ##### `processors` -Data type: `Variant[Hash,String[1]]` +Data type: `Hash[String, Hash]` Hash for processors config @@ -155,7 +155,7 @@ Default value: `{}` ##### `exporters` -Data type: `Variant[Hash,String[1]]` +Data type: `Hash[String, Hash]` Hash for exporters config @@ -163,7 +163,7 @@ Default value: `{}` ##### `pipelines` -Data type: `Variant[Hash,String[1]]` +Data type: `Hash[String, Hash]` Hash for pipelines config @@ -171,7 +171,7 @@ Default value: `{}` ##### `extensions` -Data type: `Hash` +Data type: `Hash[String, Hash]` Hash for extensions config @@ -458,7 +458,7 @@ Add a receiver to the OpenTelemetry Collector configuration #### Examples -##### +##### basic receiver ```puppet otelcol::receiver { 'namevar': } From 8f416d303fd596d2fa13c6dc5ea970418862f016 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Thu, 23 Nov 2023 22:04:02 +0100 Subject: [PATCH 26/39] Fix lint --- examples/contrib_installation.pp | 2 +- manifests/exporter.pp | 8 ++++---- manifests/processor.pp | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/contrib_installation.pp b/examples/contrib_installation.pp index 7fb6ce9..ba8c9a9 100644 --- a/examples/contrib_installation.pp +++ b/examples/contrib_installation.pp @@ -36,7 +36,7 @@ } class { 'otelcol': - manage_archive => true, + manage_archive => true, package_name => 'otelcol-contrib', metrics_address_port => 8889, } diff --git a/manifests/exporter.pp b/manifests/exporter.pp index 07c0bfa..bb509a6 100644 --- a/manifests/exporter.pp +++ b/manifests/exporter.pp @@ -19,10 +19,10 @@ ) { $real_order = 3000+$order otelcol::component { "${name}-exporter": - order => $real_order, - config => $config, - pipelines => $pipelines, + order => $real_order, + config => $config, + pipelines => $pipelines, component_name => $name, - type => 'exporters', + type => 'exporters', } } diff --git a/manifests/processor.pp b/manifests/processor.pp index b178376..d3b9f69 100644 --- a/manifests/processor.pp +++ b/manifests/processor.pp @@ -18,10 +18,10 @@ ) { $real_order = 2000+$order otelcol::component { "${name}-processors": - order => $real_order, - config => $config, - pipelines => $pipelines, + order => $real_order, + config => $config, + pipelines => $pipelines, component_name => $name, - type => 'processors', + type => 'processors', } } From 49b304ece5363f21d48906db8f86018e0031260c Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:26:09 +0100 Subject: [PATCH 27/39] Add Check for listening port --- spec/acceptance/otelcol_contrib_spec.rb | 3 +++ spec/acceptance/otelcol_spec.rb | 3 +++ 2 files changed, 6 insertions(+) diff --git a/spec/acceptance/otelcol_contrib_spec.rb b/spec/acceptance/otelcol_contrib_spec.rb index 57a86e9..ae0f334 100644 --- a/spec/acceptance/otelcol_contrib_spec.rb +++ b/spec/acceptance/otelcol_contrib_spec.rb @@ -8,5 +8,8 @@ it { is_expected.to be_enabled } it { is_expected.to be_running } end + describe port(8889) do + it { should be_listening } + end end end diff --git a/spec/acceptance/otelcol_spec.rb b/spec/acceptance/otelcol_spec.rb index cca804b..8492b82 100644 --- a/spec/acceptance/otelcol_spec.rb +++ b/spec/acceptance/otelcol_spec.rb @@ -8,5 +8,8 @@ it { is_expected.to be_enabled } it { is_expected.to be_running } end + describe port(8888) do + it { should be_listening } + end end end From f0125102e7fa876e6f3bb4fe4721e464f86da636 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:27:02 +0100 Subject: [PATCH 28/39] Add Check for listening port --- spec/acceptance/otelcol_contrib_spec.rb | 3 ++- spec/acceptance/otelcol_spec.rb | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/otelcol_contrib_spec.rb b/spec/acceptance/otelcol_contrib_spec.rb index ae0f334..4bd1146 100644 --- a/spec/acceptance/otelcol_contrib_spec.rb +++ b/spec/acceptance/otelcol_contrib_spec.rb @@ -8,8 +8,9 @@ it { is_expected.to be_enabled } it { is_expected.to be_running } end + describe port(8889) do - it { should be_listening } + it { is_expected.to be_listening } end end end diff --git a/spec/acceptance/otelcol_spec.rb b/spec/acceptance/otelcol_spec.rb index 8492b82..6c88530 100644 --- a/spec/acceptance/otelcol_spec.rb +++ b/spec/acceptance/otelcol_spec.rb @@ -8,8 +8,9 @@ it { is_expected.to be_enabled } it { is_expected.to be_running } end + describe port(8888) do - it { should be_listening } + it { is_expected.to be_listening } end end end From a0685d95ba7687a7a5fdaa7cdb67afcd55305868 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:47:46 +0100 Subject: [PATCH 29/39] Update manifests/config.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/config.pp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index b5264c6..d09e890 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -54,10 +54,9 @@ } $otelcol::processors.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + if $rvalue['config'] =~ Hash { ensure_resource('otelcol::processor', $rname, $rvalue) - } - else { + } else { ensure_resource('otelcol::processor', $rname, { 'config' => $rvalue }) } } From a0c9e46353c8e9dd6f23e7e5592ca45e09ec040c Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:47:56 +0100 Subject: [PATCH 30/39] Update manifests/config.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/config.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/config.pp b/manifests/config.pp index d09e890..0da6194 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -45,7 +45,7 @@ mode => $otelcol::config_file_mode, } - $otelcol::receivers.each|String $rname, Hash $rvalue| { + $otelcol::receivers.each |String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { ensure_resource('otelcol::receiver', $rname, $rvalue) } else { From 69afc395b6322d613f9c69e5982906bdc278c433 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:50:35 +0100 Subject: [PATCH 31/39] Update manifests/init.pp Co-authored-by: Ewoud Kohl van Wijngaarden --- manifests/init.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 80d1ee9..81b420d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -57,10 +57,10 @@ String $config_file_group = 'root', Stdlib::Filemode $config_file_mode = '0644', Hash[String, Hash] $receivers = {}, - Hash[String, Hash] $processors = {}, - Hash[String, Hash] $exporters = {}, - Hash[String, Hash] $pipelines = {}, - Hash[String, Hash] $extensions = {}, + Hash[String, Hash] $processors = {}, + Hash[String, Hash] $exporters = {}, + Hash[String, Hash] $pipelines = {}, + Hash[String, Hash] $extensions = {}, Variant[Hash,String[1]] $log_options = {}, Enum['none','basic','normal','detailed'] $metrics_level = 'basic', Optional[Stdlib::Host] $metrics_address_host = undef, From b3398b06d2aef17aeb28a0866833175061b70bfa Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:52:48 +0100 Subject: [PATCH 32/39] Use Repos instead of forge_modules --- .fixtures.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index 19fb962..1049270 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,5 @@ --- fixtures: - forge_modules: - stdlib: "puppetlabs/stdlib" - concat: "puppetlabs/concat" + repositories: + stdlib: https://github.com/puppetlabs/puppetlabs-stdlib.git + concat: https://github.com/puppetlabs/puppetlabs-concat.git From 242d444a08b3faaa193c0d2483872c71f3801f9d Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:54:13 +0100 Subject: [PATCH 33/39] Removed old testcode --- spec/classes/otelcol_spec.rb | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/spec/classes/otelcol_spec.rb b/spec/classes/otelcol_spec.rb index 7ae161f..56cb090 100644 --- a/spec/classes/otelcol_spec.rb +++ b/spec/classes/otelcol_spec.rb @@ -276,38 +276,6 @@ } end - # context 'with include files' do - # let :params do - # { - # processors: '${file:processors.yaml}', - # exporters: '${file:exporters.yaml}', - # pipelines: '${file:pipelines.yaml}', - # } - # end - # let(:configcontent_ext) do - # configcontent.merge( - # { - # 'processors' => '${file:processors.yaml}', - # 'exporters' => '${file:exporters.yaml}', - # 'service' => { - # 'extensions' => [], - # 'pipelines' => '${file:pipelines.yaml}', - # 'telemetry' => { - # 'logs' => {}, - # 'metrics' => { - # 'level' => 'basic', - # 'address' => ':8888', - # }, - # }, - # } - # } - # ) - # end - - # it { is_expected.to compile.with_all_deps } - # # it { is_expected.to contain_file('otelcol-config').with_content(configcontent_ext.to_yaml) } - # end - context 'with logoptions' do let :params do { From de965560307faab9bdae0fc45c9efa8046df8b1b Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 12:56:07 +0100 Subject: [PATCH 34/39] Fix check for Hash in all cases --- manifests/config.pp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 0da6194..9677fd4 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -62,7 +62,7 @@ } $otelcol::exporters.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + if $rvalue['config'] =~ Hash { ensure_resource('otelcol::exporter', $rname, $rvalue) } else { @@ -71,7 +71,7 @@ } $otelcol::pipelines.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + if $rvalue['config'] =~ Hash { ensure_resource('otelcol::pipeline', $rname, $rvalue) } else { @@ -80,7 +80,7 @@ } $otelcol::extensions.each|String $rname, Hash $rvalue| { - if($rvalue['config'] and $rvalue['config'].is_a(Hash)) { + if $rvalue['config'] =~ Hash { ensure_resource('otelcol::extension', $rname, $rvalue) } else { From 49e7ee541dfe4137c4476b138b821e9588d523c0 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 13:02:36 +0100 Subject: [PATCH 35/39] Add some doku, examples and example names --- REFERENCE.md | 32 ++++++++++++++++++++++++++++---- manifests/component.pp | 2 +- manifests/exporter.pp | 6 +++++- manifests/extension.pp | 2 +- manifests/pipeline.pp | 2 +- manifests/processor.pp | 6 +++++- manifests/receiver.pp | 4 ++++ 7 files changed, 45 insertions(+), 9 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 6fb4dc9..4b4dd4b 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -278,12 +278,20 @@ Create a OpenTelemetry Collector exporter in the configuration file. #### Examples -##### +##### Basic usage ```puppet otelcol::exporter { 'namevar': } ``` +##### Define a exporter and attach it to a pipeline + +```puppet +otelcol::exporter { 'prometheus': + pipelines => ['metrics'], +} +``` + #### Parameters The following parameters are available in the `otelcol::exporter` defined type: @@ -327,7 +335,7 @@ Add an extension to the OpenTelemetry Collector configuration #### Examples -##### +##### Basic usage ```puppet otelcol::extension { 'namevar': } @@ -369,7 +377,7 @@ configured by its Components. #### Examples -##### +##### Configure a pipeline ```puppet otelcol::pipeline { 'namevar': } @@ -409,12 +417,20 @@ Add a processor to the OpenTelemetry Collector configuration #### Examples -##### +##### Basic usage ```puppet otelcol::processor { 'namevar': } ``` +##### Define a processor and attach it to a pipeline + +```puppet +otelcol::processor { 'batch': + pipelines => ['metrics'], +} +``` + #### Parameters The following parameters are available in the `otelcol::processor` defined type: @@ -464,6 +480,14 @@ Add a receiver to the OpenTelemetry Collector configuration otelcol::receiver { 'namevar': } ``` +##### Define a receiver and attach it to a pipeline + +```puppet +otelcol::receiver { 'otlp': + pipelines => ['metrics'], +} +``` + #### Parameters The following parameters are available in the `otelcol::receiver` defined type: diff --git a/manifests/component.pp b/manifests/component.pp index 177c4fd..c9d5bf7 100644 --- a/manifests/component.pp +++ b/manifests/component.pp @@ -13,7 +13,7 @@ # @param pipelines # The pipelines to add the component to # -# @example +# @example Basic Usage # otelcol::component { 'receiver_name-receiver':': # component_name => 'receiver_name', # type => 'receiver', diff --git a/manifests/exporter.pp b/manifests/exporter.pp index bb509a6..23edc16 100644 --- a/manifests/exporter.pp +++ b/manifests/exporter.pp @@ -10,8 +10,12 @@ # The order of the exporter. # @param pipelines # The pipelines to attach the exporter to. -# @example +# @example Basic usage # otelcol::exporter { 'namevar': } +# @example Define a exporter and attach it to a pipeline +# otelcol::exporter { 'prometheus': +# pipelines => ['metrics'], +# } define otelcol::exporter ( Hash $config = {}, Integer[0,999] $order = 0, diff --git a/manifests/extension.pp b/manifests/extension.pp index 9b3e91a..55de0ba 100644 --- a/manifests/extension.pp +++ b/manifests/extension.pp @@ -7,7 +7,7 @@ # @param order # The order in which the extension should be loaded # -# @example +# @example Basic usage # otelcol::extension { 'namevar': } define otelcol::extension ( Hash $config = {}, diff --git a/manifests/pipeline.pp b/manifests/pipeline.pp index 7c72f74..b6efca6 100644 --- a/manifests/pipeline.pp +++ b/manifests/pipeline.pp @@ -10,7 +10,7 @@ # The configuration for the pipeline. # @param order # The order in which the pipeline should be configured. -# @example +# @example Configure a pipeline # otelcol::pipeline { 'namevar': } define otelcol::pipeline ( Hash $config = {}, diff --git a/manifests/processor.pp b/manifests/processor.pp index d3b9f69..edac984 100644 --- a/manifests/processor.pp +++ b/manifests/processor.pp @@ -9,8 +9,12 @@ # @param pipelines # The pipelines to attach the processor to # -# @example +# @example Basic usage # otelcol::processor { 'namevar': } +# @example Define a processor and attach it to a pipeline +# otelcol::processor { 'batch': +# pipelines => ['metrics'], +# } define otelcol::processor ( Hash $config = {}, Integer[0,999] $order = 0, diff --git a/manifests/receiver.pp b/manifests/receiver.pp index f50a5d8..e88d2bc 100644 --- a/manifests/receiver.pp +++ b/manifests/receiver.pp @@ -10,6 +10,10 @@ # The pipelines the receiver is part of # @example basic receiver # otelcol::receiver { 'namevar': } +# @example Define a receiver and attach it to a pipeline +# otelcol::receiver { 'otlp': +# pipelines => ['metrics'], +# } define otelcol::receiver ( Hash $config = {}, Integer[0,999] $order = 0, From afa3f4fb03135b157de9c404926b0fb7c8ced60f Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 13:04:44 +0100 Subject: [PATCH 36/39] Add spaces --- manifests/config.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/config.pp b/manifests/config.pp index 9677fd4..c9818a5 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -53,7 +53,7 @@ } } - $otelcol::processors.each|String $rname, Hash $rvalue| { + $otelcol::processors.each |String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { ensure_resource('otelcol::processor', $rname, $rvalue) } else { @@ -61,7 +61,7 @@ } } - $otelcol::exporters.each|String $rname, Hash $rvalue| { + $otelcol::exporters.each |String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { ensure_resource('otelcol::exporter', $rname, $rvalue) } @@ -70,7 +70,7 @@ } } - $otelcol::pipelines.each|String $rname, Hash $rvalue| { + $otelcol::pipelines.each |String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { ensure_resource('otelcol::pipeline', $rname, $rvalue) } @@ -79,7 +79,7 @@ } } - $otelcol::extensions.each|String $rname, Hash $rvalue| { + $otelcol::extensions.each |String $rname, Hash $rvalue| { if $rvalue['config'] =~ Hash { ensure_resource('otelcol::extension', $rname, $rvalue) } From ef958ff3d349a4023e766734d97f76e35e88e658 Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 13:06:18 +0100 Subject: [PATCH 37/39] Add missing documentation for param --- REFERENCE.md | 18 +++++++++--------- manifests/init.pp | 2 ++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 4b4dd4b..f8f77ca 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -58,12 +58,12 @@ The following parameters are available in the `otelcol` class: * [`metrics_level`](#-otelcol--metrics_level) * [`metrics_address_host`](#-otelcol--metrics_address_host) * [`metrics_address_port`](#-otelcol--metrics_address_port) +* [`service_ensure`](#-otelcol--service_ensure) * [`manage_service`](#-otelcol--manage_service) * [`manage_archive`](#-otelcol--manage_archive) * [`localpath_archive`](#-otelcol--localpath_archive) * [`archive_version`](#-otelcol--archive_version) * [`archive_location`](#-otelcol--archive_location) -* [`service_ensure`](#-otelcol--service_ensure) ##### `package_name` @@ -209,6 +209,14 @@ Port metrics are listening to Default value: `8888` +##### `service_ensure` + +Data type: `Stdlib::Ensure::Service` + +Ensure for service + +Default value: `'running'` + ##### `manage_service` Data type: `Boolean` @@ -249,14 +257,6 @@ Path to archive without filetype extension Default value: `"https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v${archive_version}/${package_name}_${archive_version}_linux_amd64"` -##### `service_ensure` - -Data type: `Stdlib::Ensure::Service` - - - -Default value: `'running'` - ### `otelcol::config` == Class: otelcol::config diff --git a/manifests/init.pp b/manifests/init.pp index 81b420d..f0656ba 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -36,6 +36,8 @@ # Host metrics are listening to # @param metrics_address_port # Port metrics are listening to +# @param service_ensure +# Ensure for service # @param manage_service # If service is managed by module # @param manage_archive From 5d573d95de82e44e87df4ab0c0df9a035b097fef Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 13:33:23 +0100 Subject: [PATCH 38/39] Add custom type for component naming --- manifests/component.pp | 2 +- .../otelcol_component_name_spec.rb | 40 +++++++++++++++++++ types/component/name.pp | 2 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 spec/type_aliases/otelcol_component_name_spec.rb create mode 100644 types/component/name.pp diff --git a/manifests/component.pp b/manifests/component.pp index c9d5bf7..3143090 100644 --- a/manifests/component.pp +++ b/manifests/component.pp @@ -20,7 +20,7 @@ # } # @api private define otelcol::component ( - String $component_name, + Otelcol::Component::Name $component_name, String $type, Hash $config = {}, Integer[0,10999] $order = 0, diff --git a/spec/type_aliases/otelcol_component_name_spec.rb b/spec/type_aliases/otelcol_component_name_spec.rb new file mode 100644 index 0000000..947d17d --- /dev/null +++ b/spec/type_aliases/otelcol_component_name_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'Otelcol::Component::Name' do + describe 'valid handling' do + %w[ + foo01 + foo-10 + batch + memory_limiter + memory_limiter/1 + memory_limiter/foo + 123 + foo + ].each do |value| + describe value.inspect do + it { is_expected.to allow_value(value) } + end + end + end + + describe 'invalid handling' do + context 'garbage inputs' do + [ + [nil], + [nil, nil], + { 'foo' => 'bar' }, + {}, + '', + 'memory_limiter/', + '/asd' + ].each do |value| + describe value.inspect do + it { is_expected.not_to allow_value(value) } + end + end + end + end +end diff --git a/types/component/name.pp b/types/component/name.pp new file mode 100644 index 0000000..25c99f6 --- /dev/null +++ b/types/component/name.pp @@ -0,0 +1,2 @@ +#Type for name of Otel Collector Ressources +type Otelcol::Component::Name = Pattern[/\A[a-z0-9_-]+(\/[a-z0-9]+)?\z/] From 888740d40899af11bb3f12d8a330c45cc66fc80c Mon Sep 17 00:00:00 2001 From: Lukas Plattner Date: Fri, 24 Nov 2023 13:34:42 +0100 Subject: [PATCH 39/39] Update reference --- REFERENCE.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index f8f77ca..54d3a7a 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -30,6 +30,10 @@ * `otelcol::component`: Define a component for the OpenTelemetry Collector Configuration +### Data types + +* [`Otelcol::Component::Name`](#Otelcol--Component--Name): Type for name of Otel Collector Ressources + ## Classes ### `otelcol` @@ -525,3 +529,11 @@ The pipelines the receiver is part of Default value: `[]` +## Data types + +### `Otelcol::Component::Name` + +Type for name of Otel Collector Ressources + +Alias of `Pattern[/\A[a-z0-9_-]+(\/[a-z0-9]+)?\z/]` +