From d456dc3b2b6b04dc4934ea63079cbf68fde8f965 Mon Sep 17 00:00:00 2001 From: Michiel de Mare Date: Tue, 16 Apr 2024 16:25:36 +0200 Subject: [PATCH] Open telemetry --- .envrc-docker | 36 ++++++++++++++++++++++++++++++ .gitignore | 1 + Dockerfile | 9 ++++---- Makefile | 20 +++++++++++++++++ dev-infra/prometheus.yml | 41 +++++++++++++++++++++++++++++++++++ docker-compose.yml | 47 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 .envrc-docker create mode 100644 Makefile create mode 100644 dev-infra/prometheus.yml create mode 100644 docker-compose.yml diff --git a/.envrc-docker b/.envrc-docker new file mode 100644 index 00000000..28cef9f1 --- /dev/null +++ b/.envrc-docker @@ -0,0 +1,36 @@ +export KEYSTORE_PASSWORD=xxxxxx +#export KEYSTORE_PASSWORD_FILE=/Users/mdemare/proj/jomco/surf/eduhub-rio-mapper/KEYSTORE_PASSWORD_FILE +export TRUSTSTORE=/app/truststore.jks +export TRUSTSTORE_PASSWORD=xxxxxx +export API_HOSTNAME=0.0.0.0 +export API_PORT=3000 +export WORKER_API_HOSTNAME=0.0.0.0 +export WORKER_API_PORT=3001 +export CLIENTS_INFO_PATH=/app/test/test-clients.json +export GATEWAY_ROOT_URL=https://gateway.test.surfeduhub.nl/ +export GATEWAY_USER=rio-test +export JOB_MAX_RETRIES=2 +export JOB_RETRY_WAIT_MS=3000 +export KEYSTORE=/app/keystore.jks +export KEYSTORE_ALIAS=test-surf +export OIN_MAPPING_PATH=/app/test-oin-mapping.json +export REDIS_URI=redis://redis:6379/ +export RIO_RETRY_ATTEMPTS_SECONDS=5,10,15,20 +export RIO_READ_URL=https://vt-webservice.duo.nl:6977/RIO/services/raadplegen4.0 +export RIO_UPDATE_URL=https://vt-webservice.duo.nl:6977/RIO/services/beheren4.0 + +export RIO_SENDER_OIN=0000000700025BE00000 +export RIO_RECIPIENT_OIN=00000001800866472000 +export SURF_CONEXT_CLIENT_ID=rio-mapper-server-dev.jomco.nl +export SURF_CONEXT_INTROSPECTION_ENDPOINT=https://connect.test.surfconext.nl/oidc/introspect + +# For smoketest only; these are needed to retrieve a valid access +# token to the mapper api +export CLIENT_ID=rio-mapper-dev.jomco.nl +export TOKEN_ENDPOINT=https://connect.test.surfconext.nl/oidc/token + +# https://proxy.swift.surfsara.nl/v1/KEY_8e0eecf8d38141f7aa98bc3078fc9ccd/rio-mapper-test-suite/ +export OS_AUTH_URL=https://proxy.swift.surfsara.nl:5000/v3 +export OS_CONTAINER_NAME=rio-mapper-test-suite +export OS_PROJECT_NAME=rio_mapper_test_suite +export OS_USERNAME=rio_mapper_test_suite diff --git a/.gitignore b/.gitignore index af0033b5..302baa76 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ pom.xml.asc /logs /keystore.jks /.envrc +/opentelemetry-javaagent.jar diff --git a/Dockerfile b/Dockerfile index 9e888109..55eba03c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,12 @@ -FROM clojure:temurin-11-lein-2.9.10-alpine as builder +FROM clojure:temurin-17-lein-jammy as builder RUN mkdir /app WORKDIR /app COPY . /app/ RUN lein uberjar -FROM gcr.io/distroless/java:11 -COPY --from=builder /app/target/eduhub-rio-mapper.jar /eduhub-rio-mapper.jar +# FROM gcr.io/distroless/java:11 +# COPY --from=builder /app/target/eduhub-rio-mapper.jar /eduhub-rio-mapper.jar +# COPY --from=builder /app/opentelemetry-javaagent.jar /opentelemetry-javaagent.jar -ENTRYPOINT ["java", "-jar", "/eduhub-rio-mapper.jar"] +ENTRYPOINT ["java", "-jar", "/app/target/eduhub-rio-mapper.jar"] diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..e702fd33 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: lint test check clean + +lint: + clojure -M:lint + +test: + clojure -M:test + +check: lint test + +clean: + rm -rf classes target + +opentelemetry-javaagent.jar: + curl -L https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest/download/opentelemetry-javaagent.jar -o $@ + +.PHONY: docker-build test lint check + +docker-build: Dockerfile docker-compose.yml opentelemetry-javaagent.jar + docker-compose build diff --git a/dev-infra/prometheus.yml b/dev-infra/prometheus.yml new file mode 100644 index 00000000..5178cdf7 --- /dev/null +++ b/dev-infra/prometheus.yml @@ -0,0 +1,41 @@ +# my global config +global: + scrape_interval: 15s + evaluation_interval: 30s + # scrape_timeout is set to the global default (10s). + + external_labels: + monitor: codelab + foo: bar + +#rule_files: +# - "first.rules" +# - "my/*.rules" + +scrape_configs: + - job_name: scrape-static + + honor_labels: true + # scrape_interval is defined by the configured global (15s). + # scrape_timeout is defined by the global default (10s). + + # metrics_path defaults to '/metrics' + # scheme defaults to 'http'. + scheme: http + + static_configs: + - targets: ["localhost:9090"] + labels: + service: prometheus +# - targets: ["host.docker.internal:8080"] +# labels: +# service: eduhub-gateway + - targets: ["worker:9464"] + labels: + service: worker + - targets: ["api:3000"] + labels: + service: api + - targets: ["api:9464"] + labels: + service: api diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..66b537ff --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,47 @@ +services: + redis: + image: redis:7-alpine + restart: always + ports: + - '6380:6379' + command: redis-server --save 20 1 --loglevel warning + volumes: + - redis:/data + prometheus: + image: prom/prometheus + ports: + - "9090:9090" + volumes: + - ./dev-infra/prometheus.yml:/etc/prometheus/prometheus.yml + worker: + image: edumapper + env_file: + - .envrc-docker # read environment from local direnv settings + environment: + OTEL_METRICS_EXPORTER: prometheus + OTEL_EXPORTER_PROMETHEUS_ENDPOINT: http://localhost:9464/metrics + OTEL_SERVICE_NAME: edumapper-worker + OTEL_LOGS_EXPORTER: none + OTEL_TRACES_EXPORTER: none + JAVA_TOOL_OPTIONS: -javaagent:./opentelemetry-javaagent.jar + command: worker + ports: + - "9465:9464" + api: + image: edumapper + env_file: + - .envrc-docker # read environment from local direnv settings + environment: + OTEL_METRICS_EXPORTER: prometheus + OTEL_EXPORTER_PROMETHEUS_ENDPOINT: http://localhost:9464/metrics + OTEL_SERVICE_NAME: edumapper-api + OTEL_LOGS_EXPORTER: none + OTEL_TRACES_EXPORTER: none + JAVA_TOOL_OPTIONS: -javaagent:./opentelemetry-javaagent.jar + ports: + - "3000:3000" + - "9464:9464" + command: serve-api +volumes: + redis: + driver: local