Skip to content

Commit

Permalink
docker: adds zipkin-rabbitmq test image (#3626)
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt authored Dec 12, 2023
1 parent 25dfdbd commit 01929cb
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
!docker/test-images/zipkin-mysql/start-mysql
!zipkin-storage/mysql-v1/src/main/resources/mysql.sql

!docker/test-images/zipkin-rabbitmq/install.sh
!docker/test-images/zipkin-rabbitmq/start-rabbitmq

!docker/test-images/zipkin-ui/nginx.conf
!docker/test-images/zipkin-ui/start-nginx
!zipkin-lens/target/zipkin-lens-*.jar
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/readme_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,9 @@ jobs:
build-bin/docker/docker_test_image openzipkin/zipkin-mysql:test
env:
DOCKER_FILE: docker/test-images/zipkin-mysql/Dockerfile
- name: docker/test-images/zipkin-rabbitmq/README.md
run: |
build-bin/docker/docker_build openzipkin/zipkin-rabbitmq:test &&
build-bin/docker/docker_test_image openzipkin/zipkin-rabbitmq:test
env:
DOCKER_FILE: docker/test-images/zipkin-rabbitmq/Dockerfile
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ base layer `openzipkin/zipkin`, and setting up schema where relevant.
* [ghcr.io/openzipkin/zipkin-elasticsearch7](test-images/zipkin-elasticsearch7/README.md) - runs Elasticsearch 7.x
* [ghcr.io/openzipkin/zipkin-kafka](test-images/zipkin-kafka/README.md) - runs both Kafka+ZooKeeper
* [ghcr.io/openzipkin/zipkin-mysql](test-images/zipkin-mysql/README.md) - runs MySQL initialized with Zipkin's schema
* [ghcr.io/openzipkin/zipkin-rabbitmq](test-images/zipkin-rabbitmq/README.md) - runs RabbitMQ
* [ghcr.io/openzipkin/zipkin-ui](test-images/zipkin-ui/README.md) - serves the (Lens) UI directly with NGINX

## Getting started
Expand Down
42 changes: 29 additions & 13 deletions docker/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ To start the Cassandra-backed configuration, run:
$ docker-compose -f docker-compose-cassandra.yml up
```

## MySQL

You can store traces in [MySQL](../test-images/zipkin-mysql/README.md) instead of memory, using the
`docker-compose-mysql.yml` file. This configuration starts `zipkin`, `zipkin-mysql` and
`zipkin-dependencies` (cron job) in their own containers.

To start the MySQL-backed configuration, run:

```bash
$ docker-compose -f docker-compose-mysql.yml up
```

## Kafka

You can collect traces from [Kafka](../test-images/zipkin-kafka/README.md) in addition to HTTP, using the
Expand All @@ -71,6 +59,34 @@ In other words, if you are running a sample application on your laptop, you woul
If you are using Docker machine, adjust `KAFKA_ADVERTISED_HOST_NAME` in `docker-compose-kafka.yml`
and the `bootstrapServers` configuration of the kafka sender to match your Docker host IP (ex. 192.168.99.100:19092).

## MySQL

You can store traces in [MySQL](../test-images/zipkin-mysql/README.md) instead of memory, using the
`docker-compose-mysql.yml` file. This configuration starts `zipkin`, `zipkin-mysql` and
`zipkin-dependencies` (cron job) in their own containers.

To start the MySQL-backed configuration, run:

```bash
$ docker-compose -f docker-compose-mysql.yml up
```

## RabbitMQ

You can collect traces from [RabbitMQ](../test-images/zipkin-rabbitmq/README.md) in addition to HTTP, using the
`docker-compose-rabbitmq.yml` file. This configuration starts `zipkin` and `zipkin-rabbitmq` in their
own containers.

To add RabbitMQ configuration, run:
```bash
$ docker-compose -f docker-compose-rabbitmq.yml up
```

Then configure the [RabbitMQ sender](https://github.com/openzipkin/zipkin-reporter-java/blob/master/amqp-client/src/main/java/zipkin2/reporter/amqp/RabbitMQSender.java)
using a `host` value of `host.docker.internal` if your application is inside the docker network.
Otherwise, an application can use the default `host` value of `localhost` to send spans to RabbitMQ
via the AMQP protocol.

# Example

The docker-compose configuration can be extended to host an [example application](https://github.com/openzipkin/brave-example)
Expand All @@ -85,7 +101,7 @@ $ docker-compose -f docker-compose.yml -f docker-compose-example.yml up
Once the services start, open http://localhost:8081/
* This calls the backend (http://127.0.0.1:9000/api) and shows its result: a formatted date.

Afterwards, you can view traces that went through the backend via http://127.0.0.1:9411/zipkin?serviceName=backend
Afterward, you can view traces that went through the backend via http://127.0.0.1:9411/zipkin?serviceName=backend

## UI

Expand Down
8 changes: 4 additions & 4 deletions docker/examples/docker-compose-kafka.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2020 The OpenZipkin Authors
# Copyright 2015-2023 The OpenZipkin 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
Expand All @@ -21,9 +21,9 @@
version: '2.4'

services:
kafka-zookeeper:
kafka:
image: ghcr.io/openzipkin/zipkin-kafka:${TAG:-latest}
container_name: kafka-zookeeper
container_name: kafka
# If using docker machine, uncomment the below and set your bootstrap
# server list to 192.168.99.100:19092
# environment:
Expand All @@ -39,6 +39,6 @@ services:
# slim doesn't include Kafka support, so switch to the larger image
image: ghcr.io/openzipkin/zipkin:${TAG:-latest}
environment:
- KAFKA_BOOTSTRAP_SERVERS=kafka-zookeeper:9092
- KAFKA_BOOTSTRAP_SERVERS=kafka:9092
depends_on:
- kafka-zookeeper
40 changes: 40 additions & 0 deletions docker/examples/docker-compose-rabbitmq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Copyright 2015-2023 The OpenZipkin 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.
#

# This file uses the version 2 docker-compose file format, described here:
# https://docs.docker.com/compose/compose-file/#version-2
#
# It extends the default configuration from docker-compose.yml to add a test
# rabbitmq server, which is used as a span transport.

version: '2.4'

services:
rabbitmq:
image: ghcr.io/openzipkin/zipkin-rabbitmq:${TAG:-latest}
container_name: rabbitmq
# Uncomment to expose the AMQP port for testing
# ports:
# - 5672:5672

zipkin:
extends:
file: docker-compose.yml
service: zipkin
# slim doesn't include Kafka support, so switch to the larger image
image: ghcr.io/openzipkin/zipkin:${TAG:-latest}
environment:
- RABBIT_ADDRESSES=rabbitmq:5672
depends_on:
- rabbitmq
4 changes: 2 additions & 2 deletions docker/test-images/zipkin-mysql/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2021 The OpenZipkin Authors
# Copyright 2015-2023 The OpenZipkin 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
Expand All @@ -15,7 +15,7 @@
# Use latest version here: https://github.com/orgs/openzipkin/packages/container/package/alpine
# This is defined in many places because Docker has no "env" script functionality unless you use
# docker-compose: When updating, update everywhere.
ARG alpine_version=3.18.5
ARG alpine_version=3.19.0

# We copy files from the context into a scratch container first to avoid a problem where docker and
# docker-compose don't share layer hashes https://github.com/docker/compose/issues/883 normally.
Expand Down
59 changes: 59 additions & 0 deletions docker/test-images/zipkin-rabbitmq/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#
# Copyright 2015-2023 The OpenZipkin 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.
#

# Use latest version here: https://github.com/orgs/openzipkin/packages/container/package/alpine
# This is defined in many places because Docker has no "env" script functionality unless you use
# docker-compose: When updating, update everywhere.
ARG alpine_version=3.19.0

# We copy files from the context into a scratch container first to avoid a problem where docker and
# docker-compose don't share layer hashes https://github.com/docker/compose/issues/883 normally.
# COPY --from= works around the issue.
FROM scratch as scratch

WORKDIR /docker-bin
COPY build-bin/docker/docker-healthcheck /docker-bin/
COPY docker/test-images/zipkin-rabbitmq/start-rabbitmq /docker-bin/
COPY docker/test-images/zipkin-rabbitmq/install.sh /install/

FROM ghcr.io/openzipkin/alpine:${alpine_version} as zipkin-rabbitmq
LABEL org.opencontainers.image.description="RabbitMQ on Alpine Linux"

# Add HEALTHCHECK and ENTRYPOINT scripts into the default search path
COPY --from=scratch /docker-bin/* /usr/local/bin/
# We use start period of 30s to avoid marking the container unhealthy on slow or contended CI hosts
HEALTHCHECK --interval=1s --start-period=30s --timeout=5s CMD ["docker-healthcheck"]
ENTRYPOINT ["start-rabbitmq"]

# Use latest from https://pkgs.alpinelinux.org/packages?name=rabbitmq-server
ARG rabbitmq_version=3.12.8
LABEL rabbitmq-version=$rabbitmq_version
ENV RABBITMQ_SERVER_VERSION=$rabbitmq_version
# Use latest from https://pkgs.alpinelinux.org/packages?name=rabbitmq-c-utils
ARG rabbitmq_c_utils_version=0.13.0
ENV RABBITMQ_C_UTILS_VERSION=$rabbitmq_c_utils_version

COPY --from=scratch /install/install.sh /tmp/install/

ARG USER=rabbitmq
# We don't set USER because rabbitmq-server needs to start as root.
RUN adduser -g '' -h ${PWD} -D ${USER} && \
(cd /tmp/install && ./install.sh) && rm -rf /tmp/install

# Usually, we read env set from pid 1 to get docker-healthcheck parameters.
# However, rabbitmq-server has to start as root even if permissions are dropped
# later. So, we expose it in the Dockerfile instead.
ENV HEALTHCHECK_PORT=5672
ENV HEALTHCHECK_KIND=tcp
EXPOSE 5672
12 changes: 12 additions & 0 deletions docker/test-images/zipkin-rabbitmq/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
## zipkin-rabbitmq Docker image

The `zipkin-rabbitmq` testing image runs `rabbitmq-server` for the
[RabbitMQ collector](../../../zipkin-collector/rabbitmq) integration.

For convenience, this includes the "guest" user and a default queue named
"zipkin". To add more queues, exec `amqp-declare-queue` in a running container.

To build `openzipkin/zipkin-rabbitmq:test`, from the top-level of the repository, run:
```bash
$ DOCKER_FILE=docker/test-images/zipkin-rabbitmq/Dockerfile build-bin/docker/docker_build openzipkin/zipkin-rabbitmq:test
```
46 changes: 46 additions & 0 deletions docker/test-images/zipkin-rabbitmq/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
#
# Copyright 2015-2023 The OpenZipkin 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.
#

set -eux

echo "*** Installing RabbitMQ"
apk add --update --no-cache rabbitmq-server=~${RABBITMQ_SERVER_VERSION} rabbitmq-c-utils=~${RABBITMQ_C_UTILS_VERSION}

echo "*** Ensuring guest can access RabbitMQ from any hostname"
mkdir -p /etc/rabbitmq/
echo "loopback_users.guest = false" >> /etc/rabbitmq/rabbitmq.conf
chown -R rabbitmq /var/lib/rabbitmq /etc/rabbitmq

echo "*** Starting RabbitMQ"
rabbitmq-server &
temp_rabbitmq_pid=$!

# Excessively long timeout to avoid having to create an ENV variable, decide its name, etc.
timeout=180
echo "Will wait up to ${timeout} seconds for RabbitMQ to come up before configuring"
while [ "$timeout" -gt 0 ] && kill -0 ${temp_rabbitmq_pid} && ! rabbitmqctl status > /dev/null 2>&1; do
sleep 1
timeout=$(($timeout - 1))
done

echo "*** Adding zipkin queue"
amqp-declare-queue -q zipkin

echo "*** Stopping RabbitMQ"
kill ${temp_rabbitmq_pid}
wait

echo "*** Cleaning Up"
rm /var/log/rabbitmq/*
22 changes: 22 additions & 0 deletions docker/test-images/zipkin-rabbitmq/start-rabbitmq
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
#
# Copyright 2015-2023 The OpenZipkin 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.
#

# ENTRYPOINT script that starts RabbitMQ
#
# This intentionally locates config using the current working directory, in order to consolidate
# Dockerfile instructions to WORKDIR
set -eu

exec rabbitmq-server "$@"
4 changes: 2 additions & 2 deletions docker/test-images/zipkin-ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2015-2021 The OpenZipkin Authors
# Copyright 2015-2023 The OpenZipkin 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
Expand All @@ -15,7 +15,7 @@
# Use latest version here: https://github.com/orgs/openzipkin/packages/container/package/alpine
# This is defined in many places because Docker has no "env" script functionality unless you use
# docker-compose: When updating, update everywhere.
ARG alpine_version=3.18.5
ARG alpine_version=3.19.0

# java_version is used during the installation process to build or download the zipkin-lens jar.
#
Expand Down

0 comments on commit 01929cb

Please sign in to comment.