From ab5d0c316a7c60b48fe014b7f311ae9f3f89d390 Mon Sep 17 00:00:00 2001 From: Ben B Date: Thu, 16 May 2024 16:05:30 +0200 Subject: [PATCH] rpm: provide systemd and microshift defaults (#63) * rpm: provide systemd and microshift defaults Signed-off-by: Benedikt Bongartz * fix: wrong place of microshift manifests Signed-off-by: Benedikt Bongartz * rpm: retrieve config files from source0 Signed-off-by: Benedikt Bongartz * fix collector start script Signed-off-by: Benedikt Bongartz * rename default config Signed-off-by: Benedikt Bongartz * add readme entry * spec: install launch script more explicit Signed-off-by: Benedikt Bongartz --------- Signed-off-by: Benedikt Bongartz --- .packit.yaml | 8 +- 00-default-receivers.yaml | 32 ++++++ Makefile | 16 +++ README.md | 12 +++ collector.spec.in | 50 +++++++++ kustomization.yaml | 6 ++ microshift-opentelemetry-gateway.yaml | 141 ++++++++++++++++++++++++++ opentelemetry-collector-with-options | 16 +++ opentelemetry-collector.service | 14 +++ 9 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 00-default-receivers.yaml create mode 100644 kustomization.yaml create mode 100644 microshift-opentelemetry-gateway.yaml create mode 100755 opentelemetry-collector-with-options create mode 100644 opentelemetry-collector.service diff --git a/.packit.yaml b/.packit.yaml index 2f70ebbb..2a2098e2 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -9,7 +9,13 @@ files_to_sync: - .packit.yaml - Makefile - _build - + - README.md + - LICENSE + - opentelemetry-collector-with-options + - 00-default-receivers.yaml + - kustomization.yaml + - microshift-opentelemetry-gateway.yaml + - opentelemetry-collector.service ./dist # name in upstream package repository or registry (e.g. in PyPI) upstream_package_name: red-hat-build-of-opentelemetry-collector # downstream (Fedora) RPM package name diff --git a/00-default-receivers.yaml b/00-default-receivers.yaml new file mode 100644 index 00000000..a7c1bce0 --- /dev/null +++ b/00-default-receivers.yaml @@ -0,0 +1,32 @@ +--- +receivers: + otlp/microshift: + protocols: + grpc: + # TODO: Its not going to work if the default ip range in microshift got modified + endpoint: "10.44.0.0:54317" + journald: + units: + priority: info + + hostmetrics: + root_path: / + collection_interval: 10s + scrapers: + cpu: + memory: + hostmetrics/disk: + root_path: / + collection_interval: 30s + scrapers: + disk: + filesystem: + +processors: + batch: + resourcedetection/system: + detectors: ["system"] + +exporters: + debug: + diff --git a/Makefile b/Makefile index bb43c501..e07a7eb9 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb PROJECT ?= opentelemetry-collector RPM_BUILDER ?= fedpkg RELEASE ?= epel7 +MAKEFLAGS += --silent build: ocb mkdir -p _build @@ -46,6 +47,7 @@ archive: vendor # NOTE: we copy README and LICENSE into _build, since append does not work on a tar.gz. cp README.md _build cp LICENSE _build + cp opentelemetry-collector-with-options 00-default-receivers.yaml kustomization.yaml microshift-opentelemetry-gateway.yaml opentelemetry-collector.service _build @echo "Creating a tarball with the source code & dependencies..." tar -cz \ @@ -72,3 +74,17 @@ rpm/fedora-testbuild: .PHONY: version version: @echo $(OTELCOL_VERSION) + +.PHONY: packit/srpm +packit/srpm: + packit --debug srpm + +.PHONY: packit/srpm +packit/rpm/mock: + packit build in-mock + +.PHONY: clean +clean: + rm -rf ./dist ./_build/vendor ./bin + rm -rf collector.spec + rm -rf *.tar.gz *.rpm diff --git a/README.md b/README.md index 27e85748..16fbb3cc 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,15 @@ This repository configures a build of the OpenTelemetry Collector with the suppo ``` git tag v0.48.0 && git push origin v0.48.0 ``` + +## RPM + +To build `srpm` and `rpm`s we used (packit)[https://packit.dev/]. + +``` +# build srpm +make clean packit/srpm + +# build rpm (includes srpm) +make clean packit/rpm/mock +``` diff --git a/collector.spec.in b/collector.spec.in index fc6f766b..d2b56719 100644 --- a/collector.spec.in +++ b/collector.spec.in @@ -19,10 +19,14 @@ License: Apache-2.0 Source0: %{name}-%{version}.tar.gz +BuildRequires: systemd BuildRequires: %{?go_compiler:compiler(go-compiler)}%{!?go_compiler:golang} BuildRequires: binutils BuildRequires: git +Requires(pre): /usr/sbin/useradd, /usr/bin/getent +Requires(postun): /usr/sbin/userdel + %description %{common_description} @@ -33,22 +37,68 @@ mkdir -p _build/bin %setup -q -n %{name}-%{version} %build + go build -v -buildmode pie -mod vendor -o %{gobuilddir}/bin/opentelemetry-collector %define debug_package %{nil} %install +# create expected directory layout +mkdir -p %{buildroot}%{_sysconfdir}/opentelemetry-collector +mkdir -p %{buildroot}%{_sysconfdir}/opentelemetry-collector/configs +mkdir -p %{buildroot}%{_sysconfdir}/microshift/manifests/opentelemetry-collector/ +mkdir -p %{buildroot}%{_unitdir} + +# install files +install -p -m 0644 ./00-default-receivers.yaml %{buildroot}%{_sysconfdir}/opentelemetry-collector/configs/00-default-receivers.yaml +install -p -m 0644 ./opentelemetry-collector.service %{buildroot}%{_unitdir}/%{name}.service +install -p -m 0644 ./microshift-opentelemetry-gateway.yaml %{buildroot}%{_sysconfdir}/microshift/manifests/opentelemetry-collector/manifest.yaml +install -p -m 0644 ./kustomization.yaml %{buildroot}%{_sysconfdir}/microshift/manifests/opentelemetry-collector/kustomization.yaml + install -m 0755 -vd %{buildroot}%{_bindir} install -m 0755 -vp %{gobuilddir}/bin/* %{buildroot}%{_bindir}/ +install -m 0755 -p ./opentelemetry-collector-with-options %{buildroot}%{_bindir}/ + +%pre +/usr/bin/getent group observability > /dev/null || /usr/sbin/groupadd -r observability +/usr/bin/getent passwd observability > /dev/null || /usr/sbin/useradd -r -M -s /sbin/nologin -g observability -G systemd-journal observability + +%postun +/usr/sbin/userdel observability + +%post +/bin/systemctl --system daemon-reload 2>&1 + +%preun +if [ $1 -eq 0 ]; then + /bin/systemctl --quiet stop %{name}.service + /bin/systemctl --quiet disable %{name}.service +fi + +%posttrans +/bin/systemctl is-enabled %{name}.service >/dev/null 2>&1 +if [ $? -eq 0 ]; then + /bin/systemctl restart %{name}.service >/dev/null +fi %check %gocheck %files +%{_unitdir}/%{name}.service +%{_sysconfdir}/opentelemetry-collector/configs/00-default-receivers.yaml +%{_sysconfdir}/microshift/manifests/opentelemetry-collector/manifest.yaml +%{_sysconfdir}/microshift/manifests/opentelemetry-collector/kustomization.yaml + %license %{golicenses} %doc %{godocs} %{_bindir}/* %changelog +* Fri Apr 12 2024 Benedikt Bongartz - 0.95.0 +- add observability user that is part of the systemd-journal group +- add opentelemetry collector config folder (`/etc/opentelemetry-collector/configs`) +- add opentelemetry collector default config +- add microshift manifests * Thu Feb 1 21:59:10 CET 2024 Nina Olear - 0.93.4 - First package for Copr diff --git a/kustomization.yaml b/kustomization.yaml new file mode 100644 index 00000000..e1ac340b --- /dev/null +++ b/kustomization.yaml @@ -0,0 +1,6 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - manifest.yaml diff --git a/microshift-opentelemetry-gateway.yaml b/microshift-opentelemetry-gateway.yaml new file mode 100644 index 00000000..813a91b2 --- /dev/null +++ b/microshift-opentelemetry-gateway.yaml @@ -0,0 +1,141 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: observability +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: opentelemetry-gateway-config + namespace: observability +data: +# TODO: remove hostnetwork-v2 scc and flip exporter config fromlocalhost to ${env:K8S_HOST_IP}. + config.yaml: | + receivers: + kubeletstats: + collection_interval: 20s + auth_type: "serviceAccount" + endpoint: "https://${env:K8S_HOST_IP}:10250" + insecure_skip_verify: true + otlp: + protocols: + grpc: + http: + processors: + batch: + send_batch_size: 10000 + timeout: 10s + exporters: + otlp/host: + endpoint: ${env:K8S_HOST_IP}:54317 + tls: + insecure: true + insecure_skip_verify: true + service: + pipelines: + traces: + receivers: [otlp] + processors: [batch] + exporters: [otlp/host] + metrics: + receivers: [otlp, kubeletstats] + processors: [batch] + exporters: [otlp/host] + logs: + receivers: [otlp] + processors: [batch] + exporters: [otlp/host] +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: opentelemetry-gateway + namespace: observability +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: otel-apiserver +rules: + - apiGroups: [''] + resources: ['nodes/stats'] + verbs: ['get', 'watch', 'list'] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: otel-collector +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: otel-apiserver +subjects: + - kind: ServiceAccount + name: opentelemetry-gateway + namespace: observability +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: opentelemetry-gateway + namespace: observability + labels: + app: opentelemetry-gateway +spec: + selector: + matchLabels: + app: opentelemetry-gateway + template: + metadata: + labels: + app: opentelemetry-gateway + spec: + serviceAccountName: opentelemetry-gateway + nodeSelector: + kubernetes.io/os: linux + containers: + - name: opentelemetry-collector + image: ghcr.io/os-observability/redhat-opentelemetry-collector/redhat-opentelemetry-collector:main + command: ["/otelcol", "--config=/etc/opentelemetry/config.yaml"] + # TODO: enable after 3.1 release + # image: registry.redhat.io/rhosdt/opentelemetry-collector-rhel8:0.93.0 + # command: ["/go/bin/otelcol-linux", "--config=/etc/opentelemetry/config.yaml"] + securityContext: + allowPrivilegeEscalation: false + runAsNonRoot: true + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + volumeMounts: + - name: config-volume + mountPath: /etc/opentelemetry + env: + - name: K8S_HOST_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + volumes: + - name: config-volume + configMap: + name: opentelemetry-gateway-config +--- +apiVersion: v1 +kind: Service +metadata: + name: gateway + namespace: observability +spec: + ports: + - name: http-otlp + port: 4318 + targetPort: 54318 + protocol: TCP + - name: grpc-otlp + port: 4317 + targetPort: 54317 + protocol: TCP + selector: + app: opentelemetry-gateway diff --git a/opentelemetry-collector-with-options b/opentelemetry-collector-with-options new file mode 100755 index 00000000..57886f54 --- /dev/null +++ b/opentelemetry-collector-with-options @@ -0,0 +1,16 @@ +#!/bin/bash + +PATCH_DIR="/etc/opentelemetry-collector/configs" + +if [ -d "$PATCH_DIR" ]; then + PATCH_FILES=$(ls "$PATCH_DIR"/*.yaml 2>/dev/null | sort) + if [ -n "$PATCH_FILES" ]; then + CONFIG_OPTIONS="" + + for PATCH_FILE in $PATCH_FILES; do + CONFIG_OPTIONS+=" --config file:$PATCH_FILE" + done + fi +fi + +/usr/bin/opentelemetry-collector $CONFIG_OPTIONS diff --git a/opentelemetry-collector.service b/opentelemetry-collector.service new file mode 100644 index 00000000..26adcf24 --- /dev/null +++ b/opentelemetry-collector.service @@ -0,0 +1,14 @@ +[Unit] +Description=RHDE Observability Agent +After=network.target + +[Service] +Type=simple +ExecStart=/usr/bin/opentelemetry-collector-with-options +User=observability +Group=observability +Restart=on-failure +RestartSec=30 + +[Install] +WantedBy=multi-user.target