From f2813977e4fb55861dfefaa894de61869b03a10d Mon Sep 17 00:00:00 2001 From: Philippe GUEMKAM Date: Sun, 4 Aug 2024 22:13:28 +0200 Subject: [PATCH] Add Opentelemetry --- .github/workflows/{ci.yaml => cicd.yaml} | 5 +++-- Dockerfile | 20 ++++++++++++++++++-- entrypoint.sh | 2 +- k8s-env.yaml => microservice.yaml | 0 4 files changed, 22 insertions(+), 5 deletions(-) rename .github/workflows/{ci.yaml => cicd.yaml} (98%) rename k8s-env.yaml => microservice.yaml (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/cicd.yaml similarity index 98% rename from .github/workflows/ci.yaml rename to .github/workflows/cicd.yaml index fdfa195..6d29045 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/cicd.yaml @@ -72,7 +72,8 @@ jobs: tags: imzerofiltre/zerofiltretech-provisioner:${{ github.run_number }}_${{ env.DOCKER_TAG_SUFFIX }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new - + build-args: PROFILE=${{ env.env_name }} + - name: Set up kubectl uses: tale/kubectl-action@v1 with: @@ -80,7 +81,7 @@ jobs: - name: Set up k8s manifest run: | - envsubst < k8s-env.yaml > k8s.yml + envsubst < microservice.yaml > k8s.yml cat k8s.yml - name: Deploy to k8s diff --git a/Dockerfile b/Dockerfile index 72f8a19..7b66812 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,13 +2,29 @@ FROM python:3.8 WORKDIR /app +ARG PROFILE=dev + COPY requirements.txt /app/ COPY . /app/ +# Install dependencies RUN pip install --no-cache-dir -r requirements.txt -EXPOSE 5000 +# Install OpenTelemetry dependencies +RUN pip install opentelemetry-distro opentelemetry-exporter-otlp +RUN opentelemetry-bootstrap -a install +# Make sure entrypoint.sh is executable RUN chmod 755 entrypoint.sh -ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file +EXPOSE 5000 + +# Set environment variables for OpenTelemetry +ENV OTEL_SERVICE_NAME=sandbox-provisioner-${PROFILE} +ENV OTEL_LOGS_EXPORTER=otlp,console +ENV OTEL_TRACES_EXPORTER=otlp +ENV OTEL_METRICS_EXPORTER=otlp +ENV OTEL_EXPORTER_OTLP_ENDPOINT=http://otelcol-opentelemetry-collector.monitoring.svc.cluster.local:4317 + +# Set entrypoint +ENTRYPOINT ["./entrypoint.sh"] diff --git a/entrypoint.sh b/entrypoint.sh index 8a38eca..28b028f 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,4 +2,4 @@ echo "The app is starting ..." -python run.py \ No newline at end of file +opentelemetry-instrument python run.py \ No newline at end of file diff --git a/k8s-env.yaml b/microservice.yaml similarity index 100% rename from k8s-env.yaml rename to microservice.yaml