diff --git a/.github/workflows/ci-loadbalancing.yaml b/.github/workflows/ci-loadbalancing.yaml new file mode 100644 index 0000000..9d340c7 --- /dev/null +++ b/.github/workflows/ci-loadbalancing.yaml @@ -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 diff --git a/.github/workflows/release-loadbalancing.yaml b/.github/workflows/release-loadbalancing.yaml new file mode 100644 index 0000000..2893090 --- /dev/null +++ b/.github/workflows/release-loadbalancing.yaml @@ -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 diff --git a/Makefile b/Makefile index b4e9f80..107c22c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 6d59991..7dcaa33 100644 --- a/README.md +++ b/README.md @@ -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-.yaml` and `./github/workflows/release-.yaml` files based on one of the existing distributions +3) add `./github/workflows/ci-.yaml` and `./github/workflows/release-.yaml` files based on one of the existing distributions You can test your new distribution with: diff --git a/distributions/loadbalancing/.goreleaser.yaml b/distributions/loadbalancing/.goreleaser.yaml new file mode 100644 index 0000000..f850687 --- /dev/null +++ b/distributions/loadbalancing/.goreleaser.yaml @@ -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 + 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 diff --git a/distributions/loadbalancing/Dockerfile b/distributions/loadbalancing/Dockerfile new file mode 100644 index 0000000..4a97b8c --- /dev/null +++ b/distributions/loadbalancing/Dockerfile @@ -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 diff --git a/distributions/loadbalancing/loadbalancing.conf b/distributions/loadbalancing/loadbalancing.conf new file mode 100644 index 0000000..eb4615c --- /dev/null +++ b/distributions/loadbalancing/loadbalancing.conf @@ -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" \ No newline at end of file diff --git a/distributions/loadbalancing/loadbalancing.service b/distributions/loadbalancing/loadbalancing.service new file mode 100644 index 0000000..73b399f --- /dev/null +++ b/distributions/loadbalancing/loadbalancing.service @@ -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 diff --git a/distributions/loadbalancing/manifest.yaml b/distributions/loadbalancing/manifest.yaml new file mode 100644 index 0000000..b49e8d0 --- /dev/null +++ b/distributions/loadbalancing/manifest.yaml @@ -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 diff --git a/distributions/loadbalancing/otelcol-test.yaml b/distributions/loadbalancing/otelcol-test.yaml new file mode 100644 index 0000000..c02c130 --- /dev/null +++ b/distributions/loadbalancing/otelcol-test.yaml @@ -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 diff --git a/distributions/loadbalancing/otelcol.yaml b/distributions/loadbalancing/otelcol.yaml new file mode 100644 index 0000000..3f635ee --- /dev/null +++ b/distributions/loadbalancing/otelcol.yaml @@ -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] diff --git a/distributions/loadbalancing/postinstall.sh b/distributions/loadbalancing/postinstall.sh new file mode 100644 index 0000000..64f2fc3 --- /dev/null +++ b/distributions/loadbalancing/postinstall.sh @@ -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 diff --git a/distributions/loadbalancing/preinstall.sh b/distributions/loadbalancing/preinstall.sh new file mode 100644 index 0000000..77267e7 --- /dev/null +++ b/distributions/loadbalancing/preinstall.sh @@ -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 diff --git a/distributions/loadbalancing/preremove.sh b/distributions/loadbalancing/preremove.sh new file mode 100644 index 0000000..77ecdaf --- /dev/null +++ b/distributions/loadbalancing/preremove.sh @@ -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 diff --git a/test/start-otelcol.sh b/test/start-otelcol.sh index 278432a..78ba1a8 100755 --- a/test/start-otelcol.sh +++ b/test/start-otelcol.sh @@ -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 @@ -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 @@ -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 diff --git a/test/stop-otelcol.sh b/test/stop-otelcol.sh index 2d9ec8f..6125265 100755 --- a/test/stop-otelcol.sh +++ b/test/stop-otelcol.sh @@ -13,6 +13,11 @@ if [[ -z $distribution ]]; then fi pid=$(cat otelcol-${distribution}.pid) +if [[ -z $pid ]]; then + echo "No Collectors running. Nothing to stop." + exit 0 +fi + kill "${pid}" if [ $? != 0 ]; then echo "Failed to stop the running instance. Return code: $? . Skipping tests." diff --git a/test/test-all.sh b/test/test-all.sh index 238a9af..8ec7fa8 100755 --- a/test/test-all.sh +++ b/test/test-all.sh @@ -18,4 +18,9 @@ echo "Distributions to test: $distributions"; for distribution in $(echo "$distributions" | tr "," "\n") do ./test/test.sh -d "${distribution}" + rc=$? + if [ $rc != 0 ]; then + echo "❌ FAIL. Test failed for '${distribution}' distribution." + exit $rc + fi done