Skip to content

Commit

Permalink
rpm: provide systemd and microshift defaults (#63)
Browse files Browse the repository at this point in the history
* rpm: provide systemd and microshift defaults

Signed-off-by: Benedikt Bongartz <[email protected]>

* fix: wrong place of microshift manifests

Signed-off-by: Benedikt Bongartz <[email protected]>

* rpm: retrieve config files from source0

Signed-off-by: Benedikt Bongartz <[email protected]>

* fix collector start script

Signed-off-by: Benedikt Bongartz <[email protected]>

* rename default config

Signed-off-by: Benedikt Bongartz <[email protected]>

* add readme entry

* spec: install launch script more explicit

Signed-off-by: Benedikt Bongartz <[email protected]>

---------

Signed-off-by: Benedikt Bongartz <[email protected]>
  • Loading branch information
frzifus authored May 16, 2024
1 parent 1c82f98 commit ab5d0c3
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 1 deletion.
8 changes: 7 additions & 1 deletion .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions 00-default-receivers.yaml
Original file line number Diff line number Diff line change
@@ -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:

16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 \
Expand All @@ -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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
50 changes: 50 additions & 0 deletions collector.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -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 <[email protected]> - 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 <[email protected]> - 0.93.4
- First package for Copr
6 changes: 6 additions & 0 deletions kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- manifest.yaml
141 changes: 141 additions & 0 deletions microshift-opentelemetry-gateway.yaml
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions opentelemetry-collector-with-options
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions opentelemetry-collector.service
Original file line number Diff line number Diff line change
@@ -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

1 comment on commit ab5d0c3

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were not able to find or create Copr project packit/os-observability-redhat-opentelemetry-collector-main specified in the config with the following error:

Cannot create a new Copr project (owner=packit project=os-observability-redhat-opentelemetry-collector-main chroots=['fedora-40-x86_64', 'rhel-9-x86_64', 'rhel-9-aarch64', 'fedora-40-aarch64']): delete_after_days: Number must be between 0 and 60.

Please check your configuration for:

  1. typos in owner and project name (groups need to be prefixed with @)
  2. whether the project name doesn't contain not allowed characters (only letters, digits, underscores, dashes and dots must be used)
  3. whether the project itself exists (Packit creates projects only in its own namespace)
  4. whether Packit is allowed to build in your Copr project
  5. whether your Copr project/group is not private

Please sign in to comment.