From 712c5baf93c1d30eaf632e51345f089231d638be Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Thu, 5 Dec 2024 14:04:43 +0100 Subject: [PATCH] ci(otelcol): Add molecule tests --- .../opentelemetry-collector-molecule.yml | 48 ++++++++++++++++++ .../molecule/default/converge.yml | 27 ++++++++++ .../molecule/default/molecule.yml | 50 +++++++++++++++++++ .../molecule/default/tests/test_default.py | 35 +++++++++++++ .../molecule/latest/converge.yml | 28 +++++++++++ .../molecule/latest/molecule.yml | 50 +++++++++++++++++++ .../molecule/latest/tests/test_default.py | 35 +++++++++++++ .../molecule/non-contrib/converge.yml | 27 ++++++++++ .../molecule/non-contrib/molecule.yml | 50 +++++++++++++++++++ .../non-contrib/tests/test_default.py | 31 ++++++++++++ 10 files changed, 381 insertions(+) create mode 100644 .github/workflows/opentelemetry-collector-molecule.yml create mode 100644 roles/opentelemetry_collector/molecule/default/converge.yml create mode 100644 roles/opentelemetry_collector/molecule/default/molecule.yml create mode 100644 roles/opentelemetry_collector/molecule/default/tests/test_default.py create mode 100644 roles/opentelemetry_collector/molecule/latest/converge.yml create mode 100644 roles/opentelemetry_collector/molecule/latest/molecule.yml create mode 100644 roles/opentelemetry_collector/molecule/latest/tests/test_default.py create mode 100644 roles/opentelemetry_collector/molecule/non-contrib/converge.yml create mode 100644 roles/opentelemetry_collector/molecule/non-contrib/molecule.yml create mode 100644 roles/opentelemetry_collector/molecule/non-contrib/tests/test_default.py diff --git a/.github/workflows/opentelemetry-collector-molecule.yml b/.github/workflows/opentelemetry-collector-molecule.yml new file mode 100644 index 00000000..8498524e --- /dev/null +++ b/.github/workflows/opentelemetry-collector-molecule.yml @@ -0,0 +1,48 @@ +--- +name: OpenTelemetry Collector Molecule + +on: + push: + branches: + - main + pull_request: + branches: + - main + +defaults: + run: + working-directory: roles/opentelemetry_collector + +jobs: + molecule: + name: Molecule + runs-on: ubuntu-latest + strategy: + matrix: + distro: + - rockylinux9 + - ubuntu2204 + - debian12 + scenario: + - default + - latest + - non-contrib + + steps: + - name: Check out the codebase. + uses: actions/checkout@v4 + + - name: Set up Python 3. + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install ansible molecule molecule-plugins[docker] docker pytest-testinfra + + - name: Run Molecule tests. + run: molecule test -s ${{ matrix.scenario }} + env: + PY_COLORS: '1' + ANSIBLE_FORCE_COLOR: '1' + MOLECULE_DISTRO: ${{ matrix.distro }} diff --git a/roles/opentelemetry_collector/molecule/default/converge.yml b/roles/opentelemetry_collector/molecule/default/converge.yml new file mode 100644 index 00000000..7d0801e5 --- /dev/null +++ b/roles/opentelemetry_collector/molecule/default/converge.yml @@ -0,0 +1,27 @@ +--- +- name: "Run role" + hosts: all + any_errors_fatal: true + roles: + - grafana.grafana.opentelemetry_collector + vars: + otel_collector_receivers: + hostmetrics: + scrapers: + cpu: + memory: + otel_collector_processors: + memory_limiter: + check_interval: 2s + limit_percentage: 80 + spike_limit_percentage: 25 + batch: + otel_collector_exporters: + prometheus: + endpoint: '127.0.0.1:9999' + otel_collector_service: + pipelines: + metrics: + receivers: '{{ otel_collector_receivers.keys() }}' + processors: '{{ otel_collector_processors.keys() }}' + exporters: '{{ otel_collector_exporters.keys() }}' diff --git a/roles/opentelemetry_collector/molecule/default/molecule.yml b/roles/opentelemetry_collector/molecule/default/molecule.yml new file mode 100644 index 00000000..8e6493a2 --- /dev/null +++ b/roles/opentelemetry_collector/molecule/default/molecule.yml @@ -0,0 +1,50 @@ +--- +platforms: + - name: almalinux-9 + image: dokken/almalinux-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: centos-stream-9 + image: dokken/centos-stream-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-10 + image: dokken/debian-10 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-11 + image: dokken/debian-11 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-36 + image: dokken/fedora-36 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-37 + image: dokken/fedora-37 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-20.04 + image: dokken/ubuntu-20.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-22.04 + image: dokken/ubuntu-22.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd diff --git a/roles/opentelemetry_collector/molecule/default/tests/test_default.py b/roles/opentelemetry_collector/molecule/default/tests/test_default.py new file mode 100644 index 00000000..f773241b --- /dev/null +++ b/roles/opentelemetry_collector/molecule/default/tests/test_default.py @@ -0,0 +1,35 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import os +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("all") + + +def test_directories(host): + dirs = [ + "/etc/otel-collector", + ] + files = ["/etc/otel-collector/config.yaml"] + for directory in dirs: + d = host.file(directory) + assert d.is_directory + assert d.exists + for file in files: + f = host.file(file) + assert f.exists + assert f.is_file + + +def test_service(host): + s = host.service("otel-collector") + # assert s.is_enabled + assert s.is_running + + +def test_socket(host): + assert host.socket("tcp://127.0.0.1:9999").is_listening diff --git a/roles/opentelemetry_collector/molecule/latest/converge.yml b/roles/opentelemetry_collector/molecule/latest/converge.yml new file mode 100644 index 00000000..9d62bd90 --- /dev/null +++ b/roles/opentelemetry_collector/molecule/latest/converge.yml @@ -0,0 +1,28 @@ +--- +- name: "Run role" + hosts: all + any_errors_fatal: true + roles: + - grafana.grafana.opentelemetry_collector + vars: + otel_collector_version: latest + otel_collector_receivers: + hostmetrics: + scrapers: + cpu: + memory: + otel_collector_processors: + memory_limiter: + check_interval: 2s + limit_percentage: 80 + spike_limit_percentage: 25 + batch: + otel_collector_exporters: + prometheus: + endpoint: '127.0.0.1:9999' + otel_collector_service: + pipelines: + metrics: + receivers: '{{ otel_collector_receivers.keys() }}' + processors: '{{ otel_collector_processors.keys() }}' + exporters: '{{ otel_collector_exporters.keys() }}' diff --git a/roles/opentelemetry_collector/molecule/latest/molecule.yml b/roles/opentelemetry_collector/molecule/latest/molecule.yml new file mode 100644 index 00000000..8e6493a2 --- /dev/null +++ b/roles/opentelemetry_collector/molecule/latest/molecule.yml @@ -0,0 +1,50 @@ +--- +platforms: + - name: almalinux-9 + image: dokken/almalinux-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: centos-stream-9 + image: dokken/centos-stream-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-10 + image: dokken/debian-10 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-11 + image: dokken/debian-11 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-36 + image: dokken/fedora-36 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-37 + image: dokken/fedora-37 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-20.04 + image: dokken/ubuntu-20.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-22.04 + image: dokken/ubuntu-22.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd diff --git a/roles/opentelemetry_collector/molecule/latest/tests/test_default.py b/roles/opentelemetry_collector/molecule/latest/tests/test_default.py new file mode 100644 index 00000000..f773241b --- /dev/null +++ b/roles/opentelemetry_collector/molecule/latest/tests/test_default.py @@ -0,0 +1,35 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import os +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("all") + + +def test_directories(host): + dirs = [ + "/etc/otel-collector", + ] + files = ["/etc/otel-collector/config.yaml"] + for directory in dirs: + d = host.file(directory) + assert d.is_directory + assert d.exists + for file in files: + f = host.file(file) + assert f.exists + assert f.is_file + + +def test_service(host): + s = host.service("otel-collector") + # assert s.is_enabled + assert s.is_running + + +def test_socket(host): + assert host.socket("tcp://127.0.0.1:9999").is_listening diff --git a/roles/opentelemetry_collector/molecule/non-contrib/converge.yml b/roles/opentelemetry_collector/molecule/non-contrib/converge.yml new file mode 100644 index 00000000..92d542df --- /dev/null +++ b/roles/opentelemetry_collector/molecule/non-contrib/converge.yml @@ -0,0 +1,27 @@ +--- +- name: "Run role" + hosts: all + any_errors_fatal: true + roles: + - grafana.grafana.opentelemetry_collector + vars: + otel_collector_type: '' + otel_collector_receivers: + hostmetrics: + scrapers: + cpu: + memory: + otel_collector_processors: + memory_limiter: + check_interval: 2s + limit_percentage: 80 + spike_limit_percentage: 25 + batch: + otel_collector_exporters: + debug: + otel_collector_service: + pipelines: + metrics: + receivers: '{{ otel_collector_receivers.keys() }}' + processors: '{{ otel_collector_processors.keys() }}' + exporters: '{{ otel_collector_exporters.keys() }}' diff --git a/roles/opentelemetry_collector/molecule/non-contrib/molecule.yml b/roles/opentelemetry_collector/molecule/non-contrib/molecule.yml new file mode 100644 index 00000000..8e6493a2 --- /dev/null +++ b/roles/opentelemetry_collector/molecule/non-contrib/molecule.yml @@ -0,0 +1,50 @@ +--- +platforms: + - name: almalinux-9 + image: dokken/almalinux-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: centos-stream-9 + image: dokken/centos-stream-9 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-10 + image: dokken/debian-10 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: debian-11 + image: dokken/debian-11 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-36 + image: dokken/fedora-36 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: fedora-37 + image: dokken/fedora-37 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-20.04 + image: dokken/ubuntu-20.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd + - name: ubuntu-22.04 + image: dokken/ubuntu-22.04 + pre_build_image: true + privileged: true + cgroup_parent: docker.slice + command: /lib/systemd/systemd diff --git a/roles/opentelemetry_collector/molecule/non-contrib/tests/test_default.py b/roles/opentelemetry_collector/molecule/non-contrib/tests/test_default.py new file mode 100644 index 00000000..ec37d6e4 --- /dev/null +++ b/roles/opentelemetry_collector/molecule/non-contrib/tests/test_default.py @@ -0,0 +1,31 @@ +from __future__ import absolute_import, division, print_function + +__metaclass__ = type + +import os +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ["MOLECULE_INVENTORY_FILE"] +).get_hosts("all") + + +def test_directories(host): + dirs = [ + "/etc/otel-collector", + ] + files = ["/etc/otel-collector/config.yaml"] + for directory in dirs: + d = host.file(directory) + assert d.is_directory + assert d.exists + for file in files: + f = host.file(file) + assert f.exists + assert f.is_file + + +def test_service(host): + s = host.service("otel-collector") + # assert s.is_enabled + assert s.is_running