Skip to content

Commit

Permalink
add 'loadbalancing' distribution (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling authored Dec 13, 2023
1 parent ae6a8c9 commit c1405f7
Show file tree
Hide file tree
Showing 17 changed files with 344 additions and 10 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci-loadbalancing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Continuous Integration - load-balancing

on:
workflow_run:
workflows: [Continuous Integration]
types:
- completed

jobs:
release:
name: Continuous Integration - loadbalancing - GoReleaser
uses: ./.github/workflows/base-goreleaser-ci.yaml
with:
distribution: loadbalancing
secrets: inherit
14 changes: 14 additions & 0 deletions .github/workflows/release-loadbalancing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release loadbalancing

on:
release:
types: [published]

jobs:
release:
name: Release loadbalancing
uses: ./.github/workflows/base-release.yaml
with:
distribution: loadbalancing
secrets: inherit
permissions: write-all
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OTELCOL_BUILDER_VERSION ?= 0.91.0
OTELCOL_BUILDER_DIR ?= ${HOME}/bin
OTELCOL_BUILDER ?= ${OTELCOL_BUILDER_DIR}/ocb

DISTRIBUTIONS ?= "sidecar,tracing"
DISTRIBUTIONS ?= "loadbalancing,sidecar,tracing"

ci: check build
check: test
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ To add a new distribution to this repository:

1) create a directory under `distributions` and place the `manifest.yaml` there
2) change the `Makefile`'s `DISTRIBUTIONS` var to include the new distribution
3) add a configuration file in the `test/config` with your distribution's name
4) add `./github/workflows/ci-<distribution>.yaml` and `./github/workflows/release-<distribution>.yaml` files based on one of the existing distributions
3) add `./github/workflows/ci-<distribution>.yaml` and `./github/workflows/release-<distribution>.yaml` files based on one of the existing distributions

You can test your new distribution with:

Expand Down
135 changes: 135 additions & 0 deletions distributions/loadbalancing/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
project_name: loadbalancing
builds:
- id: loadbalancing
goos:
- darwin
- linux
- windows
goarch:
- "386"
- amd64
- arm64
- ppc64le
ignore:
- goos: darwin
goarch: "386"
- goos: windows
goarch: arm64
dir: _build
binary: loadbalancing
ldflags:
- -s
- -w
flags:
- -trimpath
env:
- CGO_ENABLED=0
archives:
- id: loadbalancing
builds:
- loadbalancing
name_template: '{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}_{{ .Mips }}{{ end }}'
nfpms:
- package_name: loadbalancing
contents:
- src: loadbalancing.service
dst: /lib/systemd/system/loadbalancing.service
- src: loadbalancing.conf
dst: /etc/loadbalancing/loadbalancing.conf
type: config|noreplace
- src: otelcol.yaml
dst: /etc/loadbalancing/config.yaml
type: config
scripts:
preinstall: preinstall.sh
postinstall: postinstall.sh
preremove: preremove.sh
id: loadbalancing
builds:
- loadbalancing
formats:
- apk
- deb
- rpm
maintainer: Juraci Paixão Kröhling <distributions@kroehling.de>
description: loadbalancing distribution of the OpenTelemetry Collector
license: Apache 2.0
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
dockers:
- goos: linux
goarch: "386"
dockerfile: Dockerfile
image_templates:
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-386
extra_files:
- otelcol.yaml
build_flag_templates:
- --pull
- --platform=linux/386
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}
use: buildx
- goos: linux
goarch: amd64
dockerfile: Dockerfile
image_templates:
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-amd64
extra_files:
- otelcol.yaml
build_flag_templates:
- --pull
- --platform=linux/amd64
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}
use: buildx
- goos: linux
goarch: arm64
dockerfile: Dockerfile
image_templates:
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-arm64
extra_files:
- otelcol.yaml
build_flag_templates:
- --pull
- --platform=linux/arm64
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}
use: buildx
- goos: linux
goarch: ppc64le
dockerfile: Dockerfile
image_templates:
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-ppc64le
extra_files:
- otelcol.yaml
build_flag_templates:
- --pull
- --platform=linux/ppc64le
- --label=org.opencontainers.image.created={{.Date}}
- --label=org.opencontainers.image.name={{.ProjectName}}
- --label=org.opencontainers.image.revision={{.FullCommit}}
- --label=org.opencontainers.image.version={{.Version}}
- --label=org.opencontainers.image.source={{.GitURL}}
use: buildx
docker_manifests:
- name_template: ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}
image_templates:
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-386
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-amd64
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-arm64
- ghcr.io/jpkrohling/otelcol-distributions/loadbalancing:{{ .Version }}-ppc64le
sboms:
- id: archive
artifacts: archive
- id: package
artifacts: package
10 changes: 10 additions & 0 deletions distributions/loadbalancing/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM alpine:latest

ARG USER_UID=10001
USER ${USER_UID}

COPY loadbalancing /loadbalancing
COPY otelcol.yaml /etc/loadbalancing/config.yaml
ENTRYPOINT ["/loadbalancing"]
CMD ["--config", "/etc/loadbalancing/config.yaml"]
EXPOSE 4317
5 changes: 5 additions & 0 deletions distributions/loadbalancing/loadbalancing.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Systemd environment file for the loadbalancing service

# Command-line options for the loadbalancing service.
# Run `/usr/bin/loadbalancing --help` to see all available options.
OTELCOL_OPTIONS="--config=/etc/loadbalancing/config.yaml"
15 changes: 15 additions & 0 deletions distributions/loadbalancing/loadbalancing.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Load-balancer distribution of the OpenTelemetry Collector
After=network.target

[Service]
EnvironmentFile=/etc/loadbalancing/loadbalancing.conf
ExecStart=/usr/bin/loadbalancing $OTELCOL_OPTIONS
KillMode=mixed
Restart=on-failure
Type=simple
User=loadbalancing
Group=loadbalancing

[Install]
WantedBy=multi-user.target
15 changes: 15 additions & 0 deletions distributions/loadbalancing/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dist:
module: github.com/jpkrohling/otelcol-distributions/loadbalancing
name: otelcol
description: Load-balancer distribution of the OpenTelemetry Collector
version: 0.91.0
output_path: ./_build
otelcol_version: 0.91.0

extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/healthcheckextension v0.91.0
receivers:
- gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.91.0
exporters:
- gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.91.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/loadbalancingexporter v0.91.0
29 changes: 29 additions & 0 deletions distributions/loadbalancing/otelcol-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
extensions:
health_check:

receivers:
otlp:
protocols:
grpc:

processors:

exporters:
loadbalancing:
protocol:
otlp:
timeout: 1s
resolver:
static:
hostnames:
- example.com:4317

service:
extensions: [health_check]
pipelines:
traces:
receivers:
- otlp
processors: []
exporters:
- loadbalancing
33 changes: 33 additions & 0 deletions distributions/loadbalancing/otelcol.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
extensions:
health_check:

receivers:
otlp:
protocols:
grpc:

processors:

exporters:
loadbalancing:
protocol:
otlp:
timeout: 1s
resolver:
static:
hostnames:
- example.com:4317

service:
pipelines:
traces:
receivers: [otlp]
processors: []
exporters: [otlp]

logs:
receivers: [otlp]
processors: []
exporters: [otlp]

extensions: [health_check]
22 changes: 22 additions & 0 deletions distributions/loadbalancing/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if command -v systemctl >/dev/null 2>&1; then
systemctl enable loadbalancing.service
if [ -f /etc/loadbalancing/config.yaml ]; then
systemctl start loadbalancing.service
fi
fi
17 changes: 17 additions & 0 deletions distributions/loadbalancing/preinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

getent passwd loadbalancing >/dev/null || useradd --system --user-group --no-create-home --shell /sbin/nologin loadbalancing
20 changes: 20 additions & 0 deletions distributions/loadbalancing/preremove.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if command -v systemctl >/dev/null 2>&1; then
systemctl stop loadbalancing.service
systemctl disable loadbalancing.service
fi
9 changes: 2 additions & 7 deletions test/start-otelcol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ fi
max_retries=50

# start the distribution
mkdir -p ./test/logs
./distributions/${distribution}/_build/otelcol --config ./distributions/${distribution}/otelcol-test.yaml > ./test/logs/otelcol-${distribution}.log 2>&1 &
pid=$!
echo "${pid}" > "otelcol-${distribution}.pid"

retries=0
while true
Expand All @@ -31,7 +33,6 @@ do
curl -s localhost:13133 | grep "Server available" > /dev/null
if [ $? == 0 ]; then
echo "✅ The '${distribution}' distribution of the OpenTelemetry Collector started."
echo "${pid}" > "otelcol-${distribution}.pid"
break
fi

Expand All @@ -40,12 +41,6 @@ do
let "retries++"
if [ "$retries" -gt "$max_retries" ]; then
echo "❌ FAIL. Server wasn't up after about 5s."

kill "${pid}"
if [ $? != 0 ]; then
echo "Failed to stop the running instance. Return code: $? . Skipping tests."
exit 8
fi
exit 16
fi
sleep 0.1s
Expand Down
Loading

0 comments on commit c1405f7

Please sign in to comment.