From c357a213149d8ffff5524c54e4466ab7a84856a5 Mon Sep 17 00:00:00 2001 From: Andy Postnikov Date: Tue, 5 Nov 2024 03:48:54 +0100 Subject: [PATCH] Open Telemetry tracing - add tempo and grafana - add PECL extensions - php83-pecl-opentelemetry required --- .env.default | 9 +++-- Makefile | 1 + composer.json | 6 ++- docker/docker-compose.override.yml.default | 42 ++++++++++++++++++++ docker/grafana-datasources.yml | 18 +++++++++ docker/tempo.yml | 46 ++++++++++++++++++++++ 6 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 docker/grafana-datasources.yml create mode 100644 docker/tempo.yml diff --git a/.env.default b/.env.default index 4ae7ff204..0cf7886b3 100644 --- a/.env.default +++ b/.env.default @@ -7,10 +7,10 @@ SITE_MAIL=admin@example.com ADMIN_NAME=admin ADMIN_MAIL=admin@example.com PROJECT_INSTALL= -#IMAGE_PHP=skilldlabs/php:83-unit -IMAGE_PHP=skilldlabs/php:83-frankenphp -EXEC_SHELL=bash -PKGMAN=apt +IMAGE_PHP=skilldlabs/php:83-unit +#IMAGE_PHP=skilldlabs/php:83-frankenphp +#EXEC_SHELL=bash +#PKGMAN=apt IMAGE_NGINX=skilldlabs/nginx:1.24 IMAGE_FRONT=node:lts-alpine IMAGE_SOLR=solr:8-slim @@ -32,3 +32,4 @@ REDIS_PORT=6379 REDIS_PASSWD=1234567890 # See readme for basicauth convention RA_BASIC_AUTH= +ADDITIONAL_PHP_PACKAGES=php83-pecl-grpc php83-pecl-opentelemetry php83-pecl-protobuf diff --git a/Makefile b/Makefile index c56630e39..0824f1577 100644 --- a/Makefile +++ b/Makefile @@ -241,3 +241,4 @@ drush: # frankenphp/caddy https://caddyserver.com/docs/api reload: $(call php-0, /bin/sh ./scripts/makefile/reload.sh /var/www/html/docker) + $(call php-0, /bin/sh ./scripts/makefile/reload.sh) diff --git a/composer.json b/composer.json index 52442ae98..540d27df2 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,8 @@ "drupal/migrate_generator": "^2.0", "drupal/seven": "^1.0", "drush/drush": "^13.2", + "mladenrtl/opentelemetry-auto-drupal": "^0.1", + "open-telemetry/exporter-otlp": "^1.1", "skilldlabs/drupal-cleanup": "^1", "skilldlabs/druxxy": "^1.1", "webflo/drupal-finder": "^1.3" @@ -59,7 +61,9 @@ "drupal/core-composer-scaffold": true, "drupal/core-project-message": true, "drupal/core-vendor-hardening": true, - "skilldlabs/drupal-cleanup": true + "php-http/discovery": false, + "skilldlabs/drupal-cleanup": true, + "tbachert/spi": false } }, "autoload": { diff --git a/docker/docker-compose.override.yml.default b/docker/docker-compose.override.yml.default index 91b4c0535..0bcb2be31 100644 --- a/docker/docker-compose.override.yml.default +++ b/docker/docker-compose.override.yml.default @@ -18,6 +18,10 @@ services: php: environment: COMPOSER_MEMORY_LIMIT: "1G" + OTEL_PHP_AUTOLOAD_ENABLED: true + OTEL_TRACES_EXPORTER: otlp + OTEL_EXPORTER_OTLP_ENDPOINT: http://tempo:4318 + OTEL_EXPORTER_OTLP_PROTOCOL: http/json # BLACKFIRE_CLIENT_ID: x # BLACKFIRE_CLIENT_TOKEN: x # NEW_RELIC_APPNAME: "${COMPOSE_PROJECT_NAME}" @@ -43,6 +47,44 @@ services: - 'traefik.http.middlewares.web-${COMPOSE_PROJECT_NAME}.basicauth.users=${RA_BASIC_AUTH}' - 'traefik.http.middlewares.web-${COMPOSE_PROJECT_NAME}.basicauth.removeheader=true' +# Tempo runs as user 10001, and docker compose creates the volume as root. +# As such, we need to chown the volume in order for Tempo to start correctly. + + init: + image: &tempoImage grafana/tempo:latest + user: root + entrypoint: + - "chown" + - "10001:10001" + - "/var/tempo" + volumes: + - ${DB_DATA_DIR}/tempo:/var/tempo + + # To eventually offload to Tempo... + tempo: + <<: *service-defaults + image: *tempoImage + container_name: "${COMPOSE_PROJECT_NAME}_tempo" + command: [ "-config.file=/etc/tempo.yaml" ] + volumes: + - "./tempo.yml:/etc/tempo.yaml" + - ${DB_DATA_DIR}/tempo:/var/tempo + + grafana: + <<: *service-defaults + image: grafana/grafana:latest + container_name: "${COMPOSE_PROJECT_NAME}_grafana" + volumes: + - "./grafana-datasources.yml:/etc/grafana/provisioning/datasources/datasources.yaml" + environment: + - GF_AUTH_ANONYMOUS_ENABLED=true + - GF_AUTH_ANONYMOUS_ORG_ROLE=Admin + - GF_AUTH_DISABLE_LOGIN_FORM=true + - GF_FEATURE_TOGGLES_ENABLE=traceqlEditor + labels: + - 'sdc.port=3000' + - 'traefik.enable=true' + # Get access keys from https://blackfire.io/my/profiles # Then download extension using "make blackfire" diff --git a/docker/grafana-datasources.yml b/docker/grafana-datasources.yml new file mode 100644 index 000000000..7b9553c77 --- /dev/null +++ b/docker/grafana-datasources.yml @@ -0,0 +1,18 @@ +apiVersion: 1 + +datasources: + - name: Tempo + type: tempo + access: proxy + orgId: 1 + url: http://tempo:3200 + basicAuth: false + isDefault: true + version: 1 + editable: false + apiVersion: 1 + uid: tempo +# jsonData: +# httpMethod: GET +# serviceMap: +# datasourceUid: prometheus diff --git a/docker/tempo.yml b/docker/tempo.yml new file mode 100644 index 000000000..30ef3bbd8 --- /dev/null +++ b/docker/tempo.yml @@ -0,0 +1,46 @@ +stream_over_http_enabled: true +server: + http_listen_port: 3200 + log_level: info + +query_frontend: + search: + duration_slo: 5s + throughput_bytes_slo: 1.073741824e+09 + trace_by_id: + duration_slo: 5s + +distributor: + receivers: # this configuration will listen on all ports and protocols that tempo is capable of. + jaeger: # the receives all come from the OpenTelemetry collector. more configuration information can + protocols: # be found there: https://github.com/open-telemetry/opentelemetry-collector/tree/main/receiver + thrift_http: # + grpc: # for a production deployment you should only enable the receivers you need! + thrift_binary: + thrift_compact: + zipkin: + otlp: + protocols: + http: + grpc: + opencensus: + +ingester: + max_block_duration: 5m # cut the headblock when this much time passes. this is being set for demo purposes and should probably be left alone normally + +compactor: + compaction: + block_retention: 1h # overall Tempo trace retention. set for demo purposes + +storage: + trace: + backend: local # backend configuration to use + wal: + path: /var/tempo/wal # where to store the wal locally + local: + path: /var/tempo/blocks + +overrides: + defaults: + metrics_generator: + processors: [service-graphs, span-metrics, local-blocks] # enables metrics generator