Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry Collector: Add tests and support version latest #299

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/opentelemetry-collector-molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
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:
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'
4 changes: 2 additions & 2 deletions roles/opentelemetry_collector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ This Ansible role to install and configure the OpenTelemetry Collector, which ca

## Requirements

Please ensure that `curl` is intalled on Ansible controller.
Please ensure that `curl` is installed on Ansible controller.

## Role Variables

Available variables with their default values are listed below (`defaults/main.yml`):

| Variable Name | Description | Default Value |
|---------------|-------------|---------------|
| `otel_collector_version` | Version of OpenTelemetry Collector to install. | `"0.90.1"` |
| `otel_collector_version` | Version of OpenTelemetry Collector to install. Set to 'latest' to automatically determine and install the latest release | `"0.90.1"` |
| `otel_collector_binary_url` | URL for downloading the OpenTelemetry Collector binary. This URL is constructed based on the collector version, type, and architecture. | `"https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v{{ otel_collector_version }}/{% if otel_collector_type == 'contrib' %}otelcol-contrib_{{ otel_collector_version }}_linux_{{ otel_collector_arch }}{% else %}otelcol_{{ otel_collector_version }}_linux_{{ otel_collector_arch }}{% endif %}.tar.gz"` |
| `arch_mapping` | Mapping of `ansible_architecture` values to OpenTelemetry Collector binary architecture names. | See below\* |
| `otel_collector_arch` | Architecture for the OpenTelemetry Collector binary, determined based on the `ansible_architecture` fact. | `"{{ arch_mapping[ansible_architecture] | default('amd64') }}"` |
Expand Down
2 changes: 2 additions & 0 deletions roles/opentelemetry_collector/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ otel_collector_version: "0.90.1"

otel_collector_binary_url: "https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v{{ otel_collector_version }}/{% if otel_collector_type == 'contrib' %}otelcol-contrib_{{ otel_collector_version }}_linux_{{ otel_collector_arch }}{% else %}otelcol_{{ otel_collector_version }}_linux_{{ otel_collector_arch }}{% endif %}.tar.gz"

otel_collector_latest_url: 'https://api.github.com/repos/open-telemetry/opentelemetry-collector-releases/releases/latest'

arch_mapping:
x86_64: amd64
aarch64: arm64
Expand Down
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() }}'
44 changes: 44 additions & 0 deletions roles/opentelemetry_collector/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
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-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() }}'
44 changes: 44 additions & 0 deletions roles/opentelemetry_collector/molecule/latest/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
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-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() }}'
44 changes: 44 additions & 0 deletions roles/opentelemetry_collector/molecule/non-contrib/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
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-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
Loading
Loading