Skip to content

Commit

Permalink
ci(otelcol): Add molecule tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis-tomtom committed Dec 5, 2024
1 parent c8140d7 commit 3d604e8
Show file tree
Hide file tree
Showing 10 changed files with 381 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/opentelemetry-collector-molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: OpenTelemetry Collector Molecule

on:
push:
branches:
- main
pull_request:
branches:
- main

defaults:
run:
working-directory: roles/promtail

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 }}
27 changes: 27 additions & 0 deletions roles/opentelemetry_collector/molecule/default/converge.yml
Original file line number Diff line number Diff line change
@@ -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() }}'
50 changes: 50 additions & 0 deletions roles/opentelemetry_collector/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions roles/opentelemetry_collector/molecule/latest/converge.yml
Original file line number Diff line number Diff line change
@@ -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() }}'
50 changes: 50 additions & 0 deletions roles/opentelemetry_collector/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions roles/opentelemetry_collector/molecule/non-contrib/converge.yml
Original file line number Diff line number Diff line change
@@ -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() }}'
50 changes: 50 additions & 0 deletions roles/opentelemetry_collector/molecule/non-contrib/molecule.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3d604e8

Please sign in to comment.