From 045cf925b955735ae2545ea712a7a1200aed4c22 Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Wed, 5 Feb 2025 09:42:34 +0000 Subject: [PATCH 01/21] Add in docker files --- docker/docker-compose.yml | 1 + docker/monitoring/docker-compose.yml | 82 +++++++++++++++++++ .../grafana/grafana-datasources.yaml | 33 ++++++++ .../otel-collector/otel-collector.yaml | 16 ++++ docker/monitoring/prometheus/prometheus.yml | 21 +++++ docker/monitoring/promtail/promtail.yaml | 26 ++++++ docker/monitoring/tempo/tempo.yaml | 56 +++++++++++++ 7 files changed, 235 insertions(+) create mode 100644 docker/monitoring/docker-compose.yml create mode 100644 docker/monitoring/grafana/grafana-datasources.yaml create mode 100644 docker/monitoring/otel-collector/otel-collector.yaml create mode 100644 docker/monitoring/prometheus/prometheus.yml create mode 100644 docker/monitoring/promtail/promtail.yaml create mode 100644 docker/monitoring/tempo/tempo.yaml diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index c93e660..8fb16fc 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -7,3 +7,4 @@ include: - ./indexer/docker-compose.yml - ./processor-persistence/docker-compose.yml - ./processor/docker-compose.yml + - ./monitoring/docker-compose.yml diff --git a/docker/monitoring/docker-compose.yml b/docker/monitoring/docker-compose.yml new file mode 100644 index 0000000..307339b --- /dev/null +++ b/docker/monitoring/docker-compose.yml @@ -0,0 +1,82 @@ +services: + prometheus: + image: prom/prometheus + container_name: prometheus + profiles: + - monitoring + command: + - '--config.file=/etc/prometheus/prometheus.yml' + ports: + - 9090:9090 + restart: unless-stopped + volumes: + - ./prometheus:/etc/prometheus + - ../data/prometheus:/prometheus + + loki: + image: grafana/loki:latest + container_name: loki + profiles: + - monitoring + ports: + - "3100:3100" + command: -config.file=/etc/loki/local-config.yaml + + promtail: + image: grafana/promtail:latest + container_name: promtail + profiles: + - monitoring + volumes: + - ./promtail/promtail.yaml:/etc/promtail/docker-config.yaml + - /var/lib/docker/containers:/var/lib/docker/containers:ro + - /var/run/docker.sock:/var/run/docker.sock + command: -config.file=/etc/promtail/docker-config.yaml + depends_on: + - loki + + otel-collector: + image: otel/opentelemetry-collector:0.86.0 + container_name: otel-collector + profiles: + - monitoring + command: [ "--config=/etc/otel-collector.yaml" ] + volumes: + - ./otel-collector/otel-collector.yaml:/etc/otel-collector.yaml + ports: + - "4318:4317" + + tempo: + image: grafana/tempo:latest + container_name: tempo + profiles: + - monitoring + command: [ "-config.file=/etc/tempo.yaml" ] + volumes: + - ./tempo/tempo.yaml:/etc/tempo.yaml + - ../data/tempo:/var/tempo + ports: + - "3200" # tempo + - "4317" # otlp grpc + + grafana: + image: grafana/grafana:11.0.1 + container_name: grafana + profiles: + - monitoring + restart: unless-stopped + ports: + - 3000:3000 + environment: + - GF_SECURITY_ADMIN_USER=admin + - GF_SECURITY_ADMIN_PASSWORD=grafana + - GF_SECURITY_ALLOW_EMBEDDING=true + volumes: + - ./grafana:/etc/grafana/provisioning/datasources + depends_on: + - loki + - tempo + - prometheus + labels: + logging: "promtail" + logging_jobname: "grafana" diff --git a/docker/monitoring/grafana/grafana-datasources.yaml b/docker/monitoring/grafana/grafana-datasources.yaml new file mode 100644 index 0000000..cc275cb --- /dev/null +++ b/docker/monitoring/grafana/grafana-datasources.yaml @@ -0,0 +1,33 @@ +apiVersion: 1 + +datasources: + - name: Prometheus + type: prometheus + url: http://prometheus:9090 + isDefault: true + access: proxy + editable: true + - name: Loki + type: loki + access: proxy + orgId: 1 + url: http://loki:3100 + basicAuth: false + version: 1 + editable: false + - name: Tempo + type: tempo + access: proxy + orgId: 1 + url: http://tempo:3200 + basicAuth: false + version: 1 + editable: false + apiVersion: 1 + uid: tempo + jsonData: + httpMethod: GET + serviceMap: + datasourceUid: prometheus + streamingEnabled: + search: true \ No newline at end of file diff --git a/docker/monitoring/otel-collector/otel-collector.yaml b/docker/monitoring/otel-collector/otel-collector.yaml new file mode 100644 index 0000000..e11401e --- /dev/null +++ b/docker/monitoring/otel-collector/otel-collector.yaml @@ -0,0 +1,16 @@ +receivers: + otlp: + protocols: + grpc: +exporters: + otlp: + endpoint: tempo:4317 + tls: + insecure: true + debug: + verbosity: detailed +service: + pipelines: + traces: + receivers: [otlp] + exporters: [otlp] \ No newline at end of file diff --git a/docker/monitoring/prometheus/prometheus.yml b/docker/monitoring/prometheus/prometheus.yml new file mode 100644 index 0000000..e702f43 --- /dev/null +++ b/docker/monitoring/prometheus/prometheus.yml @@ -0,0 +1,21 @@ +global: + scrape_interval: 15s + scrape_timeout: 10s + evaluation_interval: 15s +alerting: + alertmanagers: + - static_configs: + - targets: [] + scheme: http + timeout: 10s + api_version: v2 +scrape_configs: + - job_name: prometheus + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - localhost:9090 \ No newline at end of file diff --git a/docker/monitoring/promtail/promtail.yaml b/docker/monitoring/promtail/promtail.yaml new file mode 100644 index 0000000..dbc28d7 --- /dev/null +++ b/docker/monitoring/promtail/promtail.yaml @@ -0,0 +1,26 @@ +server: + http_listen_port: 9080 + grpc_listen_port: 0 + +positions: + filename: /tmp/positions.yaml + +clients: + - url: http://loki:3100/loki/api/v1/push + +scrape_configs: + - job_name: flog_scrape + docker_sd_configs: + - host: unix:///var/run/docker.sock + refresh_interval: 5s + filters: + - name: label + values: ["logging=promtail"] + relabel_configs: + - source_labels: ['__meta_docker_container_name'] + regex: '/(.*)' + target_label: 'container' + - source_labels: ['__meta_docker_container_log_stream'] + target_label: 'logstream' + - source_labels: ['__meta_docker_container_label_logging_jobname'] + target_label: 'job' \ No newline at end of file diff --git a/docker/monitoring/tempo/tempo.yaml b/docker/monitoring/tempo/tempo.yaml new file mode 100644 index 0000000..828f1ca --- /dev/null +++ b/docker/monitoring/tempo/tempo.yaml @@ -0,0 +1,56 @@ + +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 + metadata_slo: + duration_slo: 5s + throughput_bytes_slo: 1.073741824e+09 + trace_by_id: + duration_slo: 5s + +distributor: + receivers: + otlp: + protocols: + grpc: + endpoint: "tempo:4317" + +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 + +metrics_generator: + registry: + external_labels: + source: tempo + cluster: docker-compose + storage: + path: /var/tempo/generator/wal + remote_write: + - url: http://prometheus:9090/api/v1/write + send_exemplars: true + traces_storage: + path: /var/tempo/generator/traces + +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 + generate_native_histograms: both From 72531b0a1cf6f456a2a104f291cae490bcfa315d Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:38:19 +0000 Subject: [PATCH 02/21] Update modules --- packages/chain/src/environments/development/.env | 5 ++++- .../chain/src/environments/development/chain.config.ts | 9 +++++++++ packages/chain/src/environments/sovereign/.env | 3 +++ .../chain/src/environments/sovereign/chain.config.ts | 8 ++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/chain/src/environments/development/.env b/packages/chain/src/environments/development/.env index 5977346..8ab33f3 100644 --- a/packages/chain/src/environments/development/.env +++ b/packages/chain/src/environments/development/.env @@ -55,4 +55,7 @@ PROTOKIT_PROCESSOR_INDEXER_GRAPHQL_HOST=0.0.0.0 # expose graphql configuration to the client app-chain NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=http://localhost:8080/graphql NEXT_PUBLIC_PROTOKIT_INDEXER_GRAPHQL_URL=http://localhost:8081/graphql -NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=http://localhost:8082/graphql \ No newline at end of file +NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=http://localhost:8082/graphql + +OPEN_TELEMETRY_SERVER_URL=http://localhost:4318 +OPEN_TELEMETRY_SERVER_ENABLED=true \ No newline at end of file diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index 614f699..ec8ba6a 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -65,6 +65,15 @@ export default async (args: Arguments): Promise => { connection: process.env.DATABASE_URL!, }, }, + OpenTelemetryServer: { + tracing: { + enabled: process.env.OPEN_TELEMETRY_SERVER_URL, + otlp: { + url: process.env.OPEN_TELEMETRY_SERVER_ENABLED + }, + }, + }, + }, ...baseAppChainModulesConfig, }); diff --git a/packages/chain/src/environments/sovereign/.env b/packages/chain/src/environments/sovereign/.env index 8be21e6..1751aab 100644 --- a/packages/chain/src/environments/sovereign/.env +++ b/packages/chain/src/environments/sovereign/.env @@ -58,3 +58,6 @@ NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=https://localhost/graphql # NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=http://yourdomain.com/graphql NEXT_PUBLIC_PROTOKIT_INDEXER_GRAPHQL_URL=https://localhost/indexer/graphql NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=https://localhost/processor/graphql + +OPEN_TELEMETRY_SERVER_URL=http://localhost:4318 +OPEN_TELEMETRY_SERVER_ENABLED=true \ No newline at end of file diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index 614f699..19318cc 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -65,6 +65,14 @@ export default async (args: Arguments): Promise => { connection: process.env.DATABASE_URL!, }, }, + OpenTelemetryServer: { + tracing: { + enabled: process.env.OPEN_TELEMETRY_SERVER_URL, + otlp: { + url: process.env.OPEN_TELEMETRY_SERVER_ENABLED + }, + }, + }, }, ...baseAppChainModulesConfig, }); From 67dc2decc1043d2ec8417fe079e28075719f36e8 Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:47:16 +0000 Subject: [PATCH 03/21] Fix typos --- packages/chain/src/environments/development/chain.config.ts | 4 ++-- packages/chain/src/environments/sovereign/chain.config.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index ec8ba6a..5ded211 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -67,9 +67,9 @@ export default async (args: Arguments): Promise => { }, OpenTelemetryServer: { tracing: { - enabled: process.env.OPEN_TELEMETRY_SERVER_URL, + enabled: process.env.OPEN_TELEMETRY_SERVER_ENABLED otlp: { - url: process.env.OPEN_TELEMETRY_SERVER_ENABLED + url: process.env.OPEN_TELEMETRY_SERVER_URL }, }, }, diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index 19318cc..fa134c6 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -67,9 +67,9 @@ export default async (args: Arguments): Promise => { }, OpenTelemetryServer: { tracing: { - enabled: process.env.OPEN_TELEMETRY_SERVER_URL, + enabled: process.env.OPEN_TELEMETRY_SERVER_ENABLED, otlp: { - url: process.env.OPEN_TELEMETRY_SERVER_ENABLED + url: process.env.OPEN_TELEMETRY_SERVER_URL }, }, }, From e1e5d5636725e34fb9515ed708fa52d9290fac41 Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:25:03 +0000 Subject: [PATCH 04/21] Add in metric --- packages/chain/src/environments/development/.env | 8 ++++++-- .../chain/src/environments/development/chain.config.ts | 9 +++++++-- packages/chain/src/environments/sovereign/.env | 8 ++++++-- .../chain/src/environments/sovereign/chain.config.ts | 9 +++++++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/chain/src/environments/development/.env b/packages/chain/src/environments/development/.env index 8ab33f3..999729b 100644 --- a/packages/chain/src/environments/development/.env +++ b/packages/chain/src/environments/development/.env @@ -57,5 +57,9 @@ NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=http://localhost:8080/graphql NEXT_PUBLIC_PROTOKIT_INDEXER_GRAPHQL_URL=http://localhost:8081/graphql NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=http://localhost:8082/graphql -OPEN_TELEMETRY_SERVER_URL=http://localhost:4318 -OPEN_TELEMETRY_SERVER_ENABLED=true \ No newline at end of file +OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 +OPEN_TELEMETRY_TRACING_ENABLED=true + +OPEN_TELEMETRY_METRICS_URL=http://localhost:4318 +OPEN_TELEMETRY_METRICS_ENABLED=true +OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 \ No newline at end of file diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index 5ded211..6babe3f 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -66,10 +66,15 @@ export default async (args: Arguments): Promise => { }, }, OpenTelemetryServer: { + metrics: { + enabled: process.env.OPEN_TELEMETRY_METRICS_ENABLED, + prometheus: process.env.OPEN_TELEMETRY_METRICS_URL , + nodeScrapeInterval: process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY, + }, tracing: { - enabled: process.env.OPEN_TELEMETRY_SERVER_ENABLED + enabled: process.env.OPEN_TELEMETRY_TRACING_ENABLED, otlp: { - url: process.env.OPEN_TELEMETRY_SERVER_URL + url: process.env.OPEN_TELEMETRY_TRACING_URL, }, }, }, diff --git a/packages/chain/src/environments/sovereign/.env b/packages/chain/src/environments/sovereign/.env index 1751aab..a48b027 100644 --- a/packages/chain/src/environments/sovereign/.env +++ b/packages/chain/src/environments/sovereign/.env @@ -59,5 +59,9 @@ NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=https://localhost/graphql NEXT_PUBLIC_PROTOKIT_INDEXER_GRAPHQL_URL=https://localhost/indexer/graphql NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=https://localhost/processor/graphql -OPEN_TELEMETRY_SERVER_URL=http://localhost:4318 -OPEN_TELEMETRY_SERVER_ENABLED=true \ No newline at end of file +OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 +OPEN_TELEMETRY_TRACING_ENABLED=true + +OPEN_TELEMETRY_METRICS_URL=http://localhost:4318 +OPEN_TELEMETRY_METRICS_ENABLED=true +OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 \ No newline at end of file diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index fa134c6..ca4f558 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -66,10 +66,15 @@ export default async (args: Arguments): Promise => { }, }, OpenTelemetryServer: { + metrics: { + enabled: process.env.OPEN_TELEMETRY_METRICS_ENABLED, + prometheus: process.env.OPEN_TELEMETRY_METRICS_URL , + nodeScrapeInterval: process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY, + }, tracing: { - enabled: process.env.OPEN_TELEMETRY_SERVER_ENABLED, + enabled: process.env.OPEN_TELEMETRY_TRACING_ENABLED, otlp: { - url: process.env.OPEN_TELEMETRY_SERVER_URL + url: process.env.OPEN_TELEMETRY_TRACING_URL, }, }, }, From 8e2e4afd06a531c08a663aa4f0d045268f6a789c Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:49:09 +0000 Subject: [PATCH 05/21] Add in ReadMe --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index e08d66c..d2693e8 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,20 @@ pnpm env:development build --filter=chain pnpm env:development sequencer:start --filter=chain ``` +### Observability + +Protokit has the ability to report metrics, logs and traces to a Grafana instance for visualisation. +These can be configured by the following environment variables +```zsh +OPEN_TELEMETRY_TRACING_URL= +OPEN_TELEMETRY_TRACING_ENABLED= + +OPEN_TELEMETRY_METRICS_URL= +OPEN_TELEMETRY_METRICS_ENABLED= +OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY= +```` +Note that the functionality is not configured for the `in-memory` mode. + ### Running the UI ```zsh From f2d8add3013b3520261ec2da999a72eacab81a26 Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Thu, 6 Feb 2025 13:25:17 +0000 Subject: [PATCH 06/21] Get types working --- packages/chain/src/environments/development/.env | 3 ++- .../src/environments/development/chain.config.ts | 14 ++++++++++---- packages/chain/src/environments/sovereign/.env | 3 ++- .../src/environments/sovereign/chain.config.ts | 13 +++++++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/packages/chain/src/environments/development/.env b/packages/chain/src/environments/development/.env index 999729b..3ae391b 100644 --- a/packages/chain/src/environments/development/.env +++ b/packages/chain/src/environments/development/.env @@ -60,6 +60,7 @@ NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=http://localhost:8082/graphql OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 OPEN_TELEMETRY_TRACING_ENABLED=true -OPEN_TELEMETRY_METRICS_URL=http://localhost:4318 +OPEN_TELEMETRY_METRICS_PORT=4318 +OPEN_TELEMETRY_METRICS_ENDPOINT=http://localhost OPEN_TELEMETRY_METRICS_ENABLED=true OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 \ No newline at end of file diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index 6babe3f..39d3707 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -17,6 +17,7 @@ import { baseAppChainModules, baseAppChainModulesConfig, } from "../../app-chain"; +import {OpenTelemetryServer} from "../../../../../../framework/packages/api"; export const appChain = AppChain.from({ Runtime: Runtime.from({ @@ -33,6 +34,7 @@ export const appChain = AppChain.from({ ...indexerSequencerModules, TaskQueue: BullQueue, DatabasePruneModule, + OpenTelemetryServer: OpenTelemetryServer }, }), modules: baseAppChainModules, @@ -67,12 +69,16 @@ export default async (args: Arguments): Promise => { }, OpenTelemetryServer: { metrics: { - enabled: process.env.OPEN_TELEMETRY_METRICS_ENABLED, - prometheus: process.env.OPEN_TELEMETRY_METRICS_URL , - nodeScrapeInterval: process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY, + enabled: Boolean(process.env.OPEN_TELEMETRY_METRICS_ENABLED ?? false), + prometheus: { host: undefined, + port: Number(process.env.OPEN_TELEMETRY_METRICS_PORT), + endpoint: process.env.OPEN_TELEMETRY_METRICS_ENDPOINT, + prefix: "", + appendTimestamp: true}, + nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), }, tracing: { - enabled: process.env.OPEN_TELEMETRY_TRACING_ENABLED, + enabled: Boolean(process.env.OPEN_TELEMETRY_TRACING_ENABLED ?? false), otlp: { url: process.env.OPEN_TELEMETRY_TRACING_URL, }, diff --git a/packages/chain/src/environments/sovereign/.env b/packages/chain/src/environments/sovereign/.env index a48b027..051d158 100644 --- a/packages/chain/src/environments/sovereign/.env +++ b/packages/chain/src/environments/sovereign/.env @@ -62,6 +62,7 @@ NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=https://localhost/processor/graphql OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 OPEN_TELEMETRY_TRACING_ENABLED=true -OPEN_TELEMETRY_METRICS_URL=http://localhost:4318 +OPEN_TELEMETRY_METRICS_PORT=4318 +OPEN_TELEMETRY_METRICS_ENDPOINT=http://localhost OPEN_TELEMETRY_METRICS_ENABLED=true OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 \ No newline at end of file diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index ca4f558..0571c3a 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -17,6 +17,7 @@ import { baseAppChainModules, baseAppChainModulesConfig, } from "../../app-chain"; +import {OpenTelemetryServer} from "../../../../../../framework/packages/api"; export const appChain = AppChain.from({ Runtime: Runtime.from({ @@ -33,6 +34,7 @@ export const appChain = AppChain.from({ ...indexerSequencerModules, TaskQueue: BullQueue, DatabasePruneModule, + OpenTelemetryServer: OpenTelemetryServer }, }), modules: baseAppChainModules, @@ -67,12 +69,15 @@ export default async (args: Arguments): Promise => { }, OpenTelemetryServer: { metrics: { - enabled: process.env.OPEN_TELEMETRY_METRICS_ENABLED, - prometheus: process.env.OPEN_TELEMETRY_METRICS_URL , - nodeScrapeInterval: process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY, + enabled: Boolean(process.env.OPEN_TELEMETRY_METRICS_ENABLED ?? false), + prometheus: { host: undefined, + port: Number(process.env.OPEN_TELEMETRY_METRICS_PORT), + endpoint: process.env.OPEN_TELEMETRY_METRICS_ENDPOINT, + prefix: "", + appendTimestamp: true}, nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), }, tracing: { - enabled: process.env.OPEN_TELEMETRY_TRACING_ENABLED, + enabled: Boolean(process.env.OPEN_TELEMETRY_TRACING_ENABLED ?? false), otlp: { url: process.env.OPEN_TELEMETRY_TRACING_URL, }, From bb61c7f06237eb31f1682942c0b63a15c25abe9d Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:08:28 +0000 Subject: [PATCH 07/21] Add in env file --- packages/chain/src/environments/sovereign/.env | 2 +- packages/chain/src/environments/sovereign/chain.config.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/chain/src/environments/sovereign/.env b/packages/chain/src/environments/sovereign/.env index 051d158..b87ada6 100644 --- a/packages/chain/src/environments/sovereign/.env +++ b/packages/chain/src/environments/sovereign/.env @@ -1,4 +1,4 @@ -COMPOSE_PROFILES=db,indexer-db,monolithic-sequencer,monolithic-indexer,proxy,web,processor-db,monolithic-processor +COMPOSE_PROFILES=db,indexer-db,monolithic-sequencer,monolithic-indexer,proxy,web,processor-db,monolithic-processor, monitoring COMPOSE_PROJECT_NAME=starter-kit diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index 0571c3a..252f5d9 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -74,7 +74,8 @@ export default async (args: Arguments): Promise => { port: Number(process.env.OPEN_TELEMETRY_METRICS_PORT), endpoint: process.env.OPEN_TELEMETRY_METRICS_ENDPOINT, prefix: "", - appendTimestamp: true}, nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), + appendTimestamp: true}, + nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), }, tracing: { enabled: Boolean(process.env.OPEN_TELEMETRY_TRACING_ENABLED ?? false), From 65a7ccbe84c00caf67e274e94110272af616eb0e Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Fri, 7 Feb 2025 14:16:08 +0000 Subject: [PATCH 08/21] Standardized ports --- docker/monitoring/docker-compose.yml | 12 ++++++------ packages/chain/src/environments/sovereign/.env | 5 ++++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docker/monitoring/docker-compose.yml b/docker/monitoring/docker-compose.yml index 307339b..3061914 100644 --- a/docker/monitoring/docker-compose.yml +++ b/docker/monitoring/docker-compose.yml @@ -7,7 +7,7 @@ services: command: - '--config.file=/etc/prometheus/prometheus.yml' ports: - - 9090:9090 + - "9090:9090" restart: unless-stopped volumes: - ./prometheus:/etc/prometheus @@ -56,8 +56,8 @@ services: - ./tempo/tempo.yaml:/etc/tempo.yaml - ../data/tempo:/var/tempo ports: - - "3200" # tempo - - "4317" # otlp grpc + - "3200:3200" # tempo + - "4317:4317" # otlp grpc grafana: image: grafana/grafana:11.0.1 @@ -66,10 +66,10 @@ services: - monitoring restart: unless-stopped ports: - - 3000:3000 + - "3000:3000" environment: - - GF_SECURITY_ADMIN_USER=admin - - GF_SECURITY_ADMIN_PASSWORD=grafana + - GF_SECURITY_ADMIN_USER=${OPEN_TELEMETRY_GF_SECURITY_ADMIN_USER} + - GF_SECURITY_ADMIN_PASSWORD=${OPEN_TELEMETRY_GF_SECURITY_ADMIN_PASSWORD} - GF_SECURITY_ALLOW_EMBEDDING=true volumes: - ./grafana:/etc/grafana/provisioning/datasources diff --git a/packages/chain/src/environments/sovereign/.env b/packages/chain/src/environments/sovereign/.env index b87ada6..a8dab2b 100644 --- a/packages/chain/src/environments/sovereign/.env +++ b/packages/chain/src/environments/sovereign/.env @@ -65,4 +65,7 @@ OPEN_TELEMETRY_TRACING_ENABLED=true OPEN_TELEMETRY_METRICS_PORT=4318 OPEN_TELEMETRY_METRICS_ENDPOINT=http://localhost OPEN_TELEMETRY_METRICS_ENABLED=true -OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 \ No newline at end of file +OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 + +OPEN_TELEMETRY_GF_SECURITY_ADMIN_USER=admin +OPEN_TELEMETRY_GF_SECURITY_ADMIN_PASSWORD=grafana \ No newline at end of file From 5cd0c2074df5da7b013f28f532d2ba333b6f323d Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Mon, 10 Feb 2025 15:00:58 +0000 Subject: [PATCH 09/21] Add in code --- README.md | 2 +- docker/base/Dockerfile | 4 ++-- docker/web/Dockerfile | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d2693e8..b3f44d7 100644 --- a/README.md +++ b/README.md @@ -251,4 +251,4 @@ The caddy reverse-proxy automatically uses https for all connections, use this g 2. Adapt your starter-kit's package.json to use the file:// references to framework 3. Go into the framework folder, and build a docker image containing the sources with `docker build -f ./packages/deployment/docker/development-base/Dockerfile -t protokit-base .` -4. Comment out the first line of docker/base/Dockerfile to use protokit-base +4. Replace the first line of docker/base/Dockerfile to use `FROM protokit-base` diff --git a/docker/base/Dockerfile b/docker/base/Dockerfile index 92dc447..d2954d0 100644 --- a/docker/base/Dockerfile +++ b/docker/base/Dockerfile @@ -1,5 +1,5 @@ # For regular deployment -FROM node:18 +FROM protokit-base # For locally built and imported framework references # Make sure you build the base-image first @@ -17,7 +17,7 @@ COPY ./packages/chain/package.json ./packages/chain/package.json COPY ./packages/eslint-config-custom/package.json ./packages/eslint-config-custom/package.json COPY ./apps/web/package.json ./apps/web/package.json -RUN corepack enable +RUN npm i -g pnpm@9.8.0 COPY ./tsconfig.json . COPY ./packages/chain/tsconfig.json ./packages/chain/tsconfig.json diff --git a/docker/web/Dockerfile b/docker/web/Dockerfile index 4e5d483..99f6227 100644 --- a/docker/web/Dockerfile +++ b/docker/web/Dockerfile @@ -21,7 +21,7 @@ COPY package.json pnpm-workspace.yaml pnpm-lock.yaml turbo.json ./ COPY ./packages/chain/package.json ./packages/chain/package.json COPY ./apps/web/package.json ./apps/web/package.json -RUN corepack enable pnpm +RUN npm i -g pnpm@9.8.0 COPY ./tsconfig.json . COPY ./packages/chain/tsconfig.json ./packages/chain/tsconfig.json From 34e0b6acaab66cfd7da17cc129fadf36ef134cff Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Tue, 11 Feb 2025 12:36:19 +0000 Subject: [PATCH 10/21] Fix import errrors, resolvers and improve README.md --- README.md | 2 +- packages/chain/src/environments/development/chain.config.ts | 2 +- packages/chain/src/environments/sovereign/chain.config.ts | 2 +- packages/chain/src/processor/api/resolvers.ts | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b3f44d7..3b5217b 100644 --- a/README.md +++ b/README.md @@ -248,7 +248,7 @@ The caddy reverse-proxy automatically uses https for all connections, use this g ## Building the framework from source 1. Make sure the framework is located under ../framework from the starter-kit's location -2. Adapt your starter-kit's package.json to use the file:// references to framework +2. Adapt your starter-kit's `packages/chain` and `apps/web` package.json to use the file:// references to framework 3. Go into the framework folder, and build a docker image containing the sources with `docker build -f ./packages/deployment/docker/development-base/Dockerfile -t protokit-base .` 4. Replace the first line of docker/base/Dockerfile to use `FROM protokit-base` diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index 39d3707..972d2f0 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -17,7 +17,7 @@ import { baseAppChainModules, baseAppChainModulesConfig, } from "../../app-chain"; -import {OpenTelemetryServer} from "../../../../../../framework/packages/api"; +import {OpenTelemetryServer} from "@proto-kit/api"; export const appChain = AppChain.from({ Runtime: Runtime.from({ diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index 252f5d9..1a9b56e 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -17,7 +17,7 @@ import { baseAppChainModules, baseAppChainModulesConfig, } from "../../app-chain"; -import {OpenTelemetryServer} from "../../../../../../framework/packages/api"; +import {OpenTelemetryServer} from "@proto-kit/api"; export const appChain = AppChain.from({ Runtime: Runtime.from({ diff --git a/packages/chain/src/processor/api/resolvers.ts b/packages/chain/src/processor/api/resolvers.ts index 37b281f..a2c2565 100644 --- a/packages/chain/src/processor/api/resolvers.ts +++ b/packages/chain/src/processor/api/resolvers.ts @@ -4,6 +4,7 @@ import { resolvers as generatedResolvers, ResolversEnhanceMap, } from "./generated/type-graphql"; +import {NonEmptyArray} from "type-graphql"; // enhance the generated resolvers with custom middlewares/validations const resolversEnchanceMap: ResolversEnhanceMap = { @@ -22,4 +23,4 @@ const resolversEnchanceMap: ResolversEnhanceMap = { applyResolversEnhanceMap(resolversEnchanceMap); // remove non read only generated resolvers and their methods -export const resolvers = cleanResolvers(generatedResolvers); +export const resolvers: NonEmptyArray = cleanResolvers(generatedResolvers); From fc7aaaf8eec4a5bf388006c6a0b8e95080e728d5 Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Tue, 11 Feb 2025 13:47:42 +0000 Subject: [PATCH 11/21] add more detail to README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3b5217b..49931a0 100644 --- a/README.md +++ b/README.md @@ -248,7 +248,7 @@ The caddy reverse-proxy automatically uses https for all connections, use this g ## Building the framework from source 1. Make sure the framework is located under ../framework from the starter-kit's location -2. Adapt your starter-kit's `packages/chain` and `apps/web` package.json to use the file:// references to framework +2. Adapt your starter-kit's `packages/chain` and `apps/web` package.json to use the file:// references to framework, including +references to `o1js` and `tsyringe`. 3. Go into the framework folder, and build a docker image containing the sources with `docker build -f ./packages/deployment/docker/development-base/Dockerfile -t protokit-base .` - 4. Replace the first line of docker/base/Dockerfile to use `FROM protokit-base` From 44a1fc4e8e4da9da009c78250cc3206f4c50bd09 Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Tue, 11 Feb 2025 16:47:18 +0000 Subject: [PATCH 12/21] Correct README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49931a0..26f35a6 100644 --- a/README.md +++ b/README.md @@ -251,4 +251,4 @@ The caddy reverse-proxy automatically uses https for all connections, use this g 2. Adapt your starter-kit's `packages/chain` and `apps/web` package.json to use the file:// references to framework, including references to `o1js` and `tsyringe`. 3. Go into the framework folder, and build a docker image containing the sources with `docker build -f ./packages/deployment/docker/development-base/Dockerfile -t protokit-base .` -4. Replace the first line of docker/base/Dockerfile to use `FROM protokit-base` +4. Replace the first line of `docker/base/Dockerfile` and `docker/web/Dockerfile` to use `FROM protokit-base:latest` From e3487e021f18db1b362d3c1cb3883dd33395e67d Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:00:26 +0000 Subject: [PATCH 13/21] Update grafana port for docker-compose --- docker/monitoring/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/monitoring/docker-compose.yml b/docker/monitoring/docker-compose.yml index 3061914..ac2b4ca 100644 --- a/docker/monitoring/docker-compose.yml +++ b/docker/monitoring/docker-compose.yml @@ -66,7 +66,7 @@ services: - monitoring restart: unless-stopped ports: - - "3000:3000" + - "3001:3000" environment: - GF_SECURITY_ADMIN_USER=${OPEN_TELEMETRY_GF_SECURITY_ADMIN_USER} - GF_SECURITY_ADMIN_PASSWORD=${OPEN_TELEMETRY_GF_SECURITY_ADMIN_PASSWORD} From 01a5949f4d6050b632afabaea49966bfe6c282ba Mon Sep 17 00:00:00 2001 From: ejMina226 <118474890+ejMina226@users.noreply.github.com> Date: Wed, 12 Feb 2025 13:28:00 +0000 Subject: [PATCH 14/21] Remove --experimental-wasm-threads --- docker/base/entry.sh | 2 +- docker/proxy/Caddyfile | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/base/entry.sh b/docker/base/entry.sh index aeef42a..9134078 100644 --- a/docker/base/entry.sh +++ b/docker/base/entry.sh @@ -25,4 +25,4 @@ cd /app echo $@ # We can't use start:headless here bcs that task hardcodes the .js file, we want it to be extensible -node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads --es-module-specifier-resolution=node $@ \ No newline at end of file +node --experimental-vm-modules --experimental-wasm-modules --es-module-specifier-resolution=node $@ \ No newline at end of file diff --git a/docker/proxy/Caddyfile b/docker/proxy/Caddyfile index 3e4ebda..90c2baf 100644 --- a/docker/proxy/Caddyfile +++ b/docker/proxy/Caddyfile @@ -3,5 +3,6 @@ reverse_proxy /indexer/graphql indexer:8081 reverse_proxy /processor/graphql processor:8082 reverse_proxy web:3000 + reverse_proxy grafana:3000 encode gzip } From 554b308549cd757354362a991633332e998f48d0 Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 18:58:27 +0100 Subject: [PATCH 15/21] Adapter docker files --- docker/indexer/docker-compose.yml | 3 ++ docker/monitoring/docker-compose.yml | 26 ++++++++++++++-- .../{ => development}/prometheus.yml | 11 ++++++- .../prometheus/sovereign/prometheus.yml | 30 +++++++++++++++++++ docker/processor/docker-compose.yml | 3 ++ docker/sequencer/docker-compose.yml | 11 +++++++ docker/web/docker-compose.yml | 3 ++ 7 files changed, 83 insertions(+), 4 deletions(-) rename docker/monitoring/prometheus/{ => development}/prometheus.yml (62%) create mode 100644 docker/monitoring/prometheus/sovereign/prometheus.yml diff --git a/docker/indexer/docker-compose.yml b/docker/indexer/docker-compose.yml index 44d12ec..c8dacf1 100644 --- a/docker/indexer/docker-compose.yml +++ b/docker/indexer/docker-compose.yml @@ -43,6 +43,9 @@ services: [ "./packages/chain/dist/start.js start ./environments/${PROTOKIT_ENV_FOLDER}/indexer.config.js", ] + labels: + logging: "promtail" + logging_jobname: "indexer" networks: indexer-net: diff --git a/docker/monitoring/docker-compose.yml b/docker/monitoring/docker-compose.yml index ac2b4ca..5ee80b7 100644 --- a/docker/monitoring/docker-compose.yml +++ b/docker/monitoring/docker-compose.yml @@ -6,11 +6,16 @@ services: - monitoring command: - '--config.file=/etc/prometheus/prometheus.yml' + - '--web.enable-remote-write-receiver' + - '--enable-feature=native-histograms' + networks: + - monitoring + - chain-net ports: - "9090:9090" restart: unless-stopped volumes: - - ./prometheus:/etc/prometheus + - ./prometheus/${PROTOKIT_ENV_FOLDER}:/etc/prometheus - ../data/prometheus:/prometheus loki: @@ -18,6 +23,8 @@ services: container_name: loki profiles: - monitoring + networks: + - monitoring ports: - "3100:3100" command: -config.file=/etc/loki/local-config.yaml @@ -27,6 +34,8 @@ services: container_name: promtail profiles: - monitoring + networks: + - monitoring volumes: - ./promtail/promtail.yaml:/etc/promtail/docker-config.yaml - /var/lib/docker/containers:/var/lib/docker/containers:ro @@ -40,6 +49,9 @@ services: container_name: otel-collector profiles: - monitoring + networks: + - monitoring + - chain-net command: [ "--config=/etc/otel-collector.yaml" ] volumes: - ./otel-collector/otel-collector.yaml:/etc/otel-collector.yaml @@ -49,6 +61,8 @@ services: tempo: image: grafana/tempo:latest container_name: tempo + networks: + - monitoring profiles: - monitoring command: [ "-config.file=/etc/tempo.yaml" ] @@ -65,14 +79,17 @@ services: profiles: - monitoring restart: unless-stopped + networks: + - monitoring ports: - "3001:3000" environment: - - GF_SECURITY_ADMIN_USER=${OPEN_TELEMETRY_GF_SECURITY_ADMIN_USER} - - GF_SECURITY_ADMIN_PASSWORD=${OPEN_TELEMETRY_GF_SECURITY_ADMIN_PASSWORD} + - GF_SECURITY_ADMIN_USER=${GF_SECURITY_ADMIN_USER} + - GF_SECURITY_ADMIN_PASSWORD=${GF_SECURITY_ADMIN_PASSWORD} - GF_SECURITY_ALLOW_EMBEDDING=true volumes: - ./grafana:/etc/grafana/provisioning/datasources + - ../data/grafana:/var/lib/grafana depends_on: - loki - tempo @@ -80,3 +97,6 @@ services: labels: logging: "promtail" logging_jobname: "grafana" + +networks: + monitoring: \ No newline at end of file diff --git a/docker/monitoring/prometheus/prometheus.yml b/docker/monitoring/prometheus/development/prometheus.yml similarity index 62% rename from docker/monitoring/prometheus/prometheus.yml rename to docker/monitoring/prometheus/development/prometheus.yml index e702f43..0bc98da 100644 --- a/docker/monitoring/prometheus/prometheus.yml +++ b/docker/monitoring/prometheus/development/prometheus.yml @@ -18,4 +18,13 @@ scrape_configs: scheme: http static_configs: - targets: - - localhost:9090 \ No newline at end of file + - localhost:9090 + - job_name: sequencer + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - host.docker.internal:4320 diff --git a/docker/monitoring/prometheus/sovereign/prometheus.yml b/docker/monitoring/prometheus/sovereign/prometheus.yml new file mode 100644 index 0000000..f810d17 --- /dev/null +++ b/docker/monitoring/prometheus/sovereign/prometheus.yml @@ -0,0 +1,30 @@ +global: + scrape_interval: 15s + scrape_timeout: 10s + evaluation_interval: 15s +alerting: + alertmanagers: + - static_configs: + - targets: [] + scheme: http + timeout: 10s + api_version: v2 +scrape_configs: + - job_name: prometheus + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - localhost:9090 + - job_name: sequencer + honor_timestamps: true + scrape_interval: 15s + scrape_timeout: 10s + metrics_path: /metrics + scheme: http + static_configs: + - targets: + - starterkit-sequencer:4320 diff --git a/docker/processor/docker-compose.yml b/docker/processor/docker-compose.yml index 632d0f4..820205a 100644 --- a/docker/processor/docker-compose.yml +++ b/docker/processor/docker-compose.yml @@ -30,6 +30,9 @@ services: - 8082:8080 working_dir: /app command: ["./packages/chain/dist/start.js start ./environments/${PROTOKIT_ENV_FOLDER}/processor.config.js",] + labels: + logging: "promtail" + logging_jobname: "processor" networks: processor-net: \ No newline at end of file diff --git a/docker/sequencer/docker-compose.yml b/docker/sequencer/docker-compose.yml index 0bf00ea..7c37f61 100644 --- a/docker/sequencer/docker-compose.yml +++ b/docker/sequencer/docker-compose.yml @@ -23,6 +23,14 @@ services: - PROTOKIT_GRAPHQL_HOST=${PROTOKIT_GRAPHQL_HOST} - PROTOKIT_GRAPHQL_PORT=${PROTOKIT_GRAPHQL_PORT} - PROTOKIT_GRAPHIQL_ENABLED=${PROTOKIT_GRAPHIQL_ENABLED} + + - OPEN_TELEMETRY_TRACING_ENABLED=${OPEN_TELEMETRY_TRACING_ENABLED} + - OPEN_TELEMETRY_TRACING_URL=${OPEN_TELEMETRY_TRACING_URL} + + - OPEN_TELEMETRY_METRICS_ENABLED=${OPEN_TELEMETRY_METRICS_ENABLED} + - OPEN_TELEMETRY_METRICS_PORT=${OPEN_TELEMETRY_METRICS_PORT} + - OPEN_TELEMETRY_METRICS_HOST=${OPEN_TELEMETRY_METRICS_HOST} + - OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=${OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY} profiles: - monolithic-sequencer depends_on: @@ -37,6 +45,9 @@ services: ports: - 8080:8080 command: ["./packages/chain/dist/start.js start ./environments/${PROTOKIT_ENV_FOLDER}/chain.config.js"] + labels: + logging: "promtail" + logging_jobname: "sequencer" networks: chain-net: \ No newline at end of file diff --git a/docker/web/docker-compose.yml b/docker/web/docker-compose.yml index 6de1029..01c18ea 100644 --- a/docker/web/docker-compose.yml +++ b/docker/web/docker-compose.yml @@ -22,3 +22,6 @@ services: - chain-net ports: - 3000:3000 + labels: + logging: "promtail" + logging_jobname: "grafana" \ No newline at end of file From f124ae6c6f38a5e72f0bcf0523f6469eec2dc79b Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 18:58:55 +0100 Subject: [PATCH 16/21] Fixed Caddyfile --- docker/proxy/Caddyfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker/proxy/Caddyfile b/docker/proxy/Caddyfile index 90c2baf..a5bcdec 100644 --- a/docker/proxy/Caddyfile +++ b/docker/proxy/Caddyfile @@ -2,7 +2,7 @@ reverse_proxy /graphql sequencer:8080 reverse_proxy /indexer/graphql indexer:8081 reverse_proxy /processor/graphql processor:8082 + reverse_proxy /grafana grafana:3000 reverse_proxy web:3000 - reverse_proxy grafana:3000 encode gzip -} +} \ No newline at end of file From 34c7944a7f264586d3b3aed7e0d460498312f872 Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 18:59:14 +0100 Subject: [PATCH 17/21] Completed .env files --- packages/chain/src/environments/development/.env | 12 ++++++++---- packages/chain/src/environments/sovereign/.env | 10 +++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/chain/src/environments/development/.env b/packages/chain/src/environments/development/.env index 3ae391b..0ade698 100644 --- a/packages/chain/src/environments/development/.env +++ b/packages/chain/src/environments/development/.env @@ -1,4 +1,5 @@ COMPOSE_PROFILES=db, indexer-db, processor-db +; monitoring COMPOSE_PROJECT_NAME=starter-kit POSTGRES_PASSWORD=password @@ -57,10 +58,13 @@ NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=http://localhost:8080/graphql NEXT_PUBLIC_PROTOKIT_INDEXER_GRAPHQL_URL=http://localhost:8081/graphql NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=http://localhost:8082/graphql -OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 OPEN_TELEMETRY_TRACING_ENABLED=true +OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 -OPEN_TELEMETRY_METRICS_PORT=4318 -OPEN_TELEMETRY_METRICS_ENDPOINT=http://localhost OPEN_TELEMETRY_METRICS_ENABLED=true -OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 \ No newline at end of file +OPEN_TELEMETRY_METRICS_PORT=4320 +OPEN_TELEMETRY_METRICS_HOST=0.0.0.0 +OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 + +GF_SECURITY_ADMIN_USER=admin +GF_SECURITY_ADMIN_PASSWORD=grafana \ No newline at end of file diff --git a/packages/chain/src/environments/sovereign/.env b/packages/chain/src/environments/sovereign/.env index a8dab2b..6c298a8 100644 --- a/packages/chain/src/environments/sovereign/.env +++ b/packages/chain/src/environments/sovereign/.env @@ -59,13 +59,13 @@ NEXT_PUBLIC_PROTOKIT_GRAPHQL_URL=https://localhost/graphql NEXT_PUBLIC_PROTOKIT_INDEXER_GRAPHQL_URL=https://localhost/indexer/graphql NEXT_PUBLIC_PROTOKIT_PROCESSOR_GRAPHQL_URL=https://localhost/processor/graphql -OPEN_TELEMETRY_TRACING_URL=http://localhost:4318 OPEN_TELEMETRY_TRACING_ENABLED=true +OPEN_TELEMETRY_TRACING_URL=http://otel-collector:4317 -OPEN_TELEMETRY_METRICS_PORT=4318 -OPEN_TELEMETRY_METRICS_ENDPOINT=http://localhost OPEN_TELEMETRY_METRICS_ENABLED=true +OPEN_TELEMETRY_METRICS_PORT=4320 +OPEN_TELEMETRY_METRICS_HOST=0.0.0.0 OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY=10 -OPEN_TELEMETRY_GF_SECURITY_ADMIN_USER=admin -OPEN_TELEMETRY_GF_SECURITY_ADMIN_PASSWORD=grafana \ No newline at end of file +GF_SECURITY_ADMIN_USER=admin +GF_SECURITY_ADMIN_PASSWORD=grafana \ No newline at end of file From e0776f1bfe8033f95be0a7208a419b8c76c6d379 Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 18:59:28 +0100 Subject: [PATCH 18/21] Fixed broken state import --- packages/chain/src/runtime/modules/balances.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/chain/src/runtime/modules/balances.ts b/packages/chain/src/runtime/modules/balances.ts index ca4ec5a..98a2621 100644 --- a/packages/chain/src/runtime/modules/balances.ts +++ b/packages/chain/src/runtime/modules/balances.ts @@ -1,5 +1,5 @@ -import { runtimeModule, state, runtimeMethod } from "@proto-kit/module"; -import { State, assert } from "@proto-kit/protocol"; +import { runtimeModule, runtimeMethod } from "@proto-kit/module"; +import { State, assert, state } from "@proto-kit/protocol"; import { Balance, Balances as BaseBalances, TokenId } from "@proto-kit/library"; import { PublicKey } from "o1js"; From 73a2960d64e89223793651f6965f60740e0d3d27 Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 19:00:31 +0100 Subject: [PATCH 19/21] Completed and fixed module definition --- .../environments/development/chain.config.ts | 28 ++++----------- .../environments/sovereign/chain.config.ts | 34 +++++++------------ packages/chain/src/sequencer/index.ts | 28 +++++++++++++++ 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index 972d2f0..2f77d97 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -1,7 +1,7 @@ import { AppChain } from "@proto-kit/sdk"; import { Runtime } from "@proto-kit/module"; import { Protocol } from "@proto-kit/protocol"; -import { DatabasePruneModule, Sequencer } from "@proto-kit/sequencer"; +import { DatabasePruneModule, LocalTaskWorkerModule, Sequencer, VanillaTaskWorkerModules } from "@proto-kit/sequencer"; import { PrismaRedisDatabase } from "@proto-kit/persistance"; import runtime from "../../runtime"; import protocol from "../../protocol"; @@ -9,7 +9,7 @@ import { baseSequencerModules, baseSequencerModulesConfig, indexerSequencerModules, - indexerSequencerModulesConfig, + indexerSequencerModulesConfig, metricsSequencerModules, metricsSequencerModulesConfig, } from "../../sequencer"; import { BullQueue, Startable } from "@proto-kit/deployment"; import { Arguments } from "../../start"; @@ -30,11 +30,12 @@ export const appChain = AppChain.from({ modules: { // ordering of the modules matters due to dependency resolution Database: PrismaRedisDatabase, + ...metricsSequencerModules, + TaskQueue: BullQueue, + LocalTaskWorkerModule: LocalTaskWorkerModule.from(VanillaTaskWorkerModules.withoutSettlement()), ...baseSequencerModules, ...indexerSequencerModules, - TaskQueue: BullQueue, DatabasePruneModule, - OpenTelemetryServer: OpenTelemetryServer }, }), modules: baseAppChainModules, @@ -47,6 +48,7 @@ export default async (args: Arguments): Promise => { Sequencer: { ...baseSequencerModulesConfig, ...indexerSequencerModulesConfig, + ...metricsSequencerModulesConfig, DatabasePruneModule: { pruneOnStartup: args.pruneOnStartup, }, @@ -67,23 +69,7 @@ export default async (args: Arguments): Promise => { connection: process.env.DATABASE_URL!, }, }, - OpenTelemetryServer: { - metrics: { - enabled: Boolean(process.env.OPEN_TELEMETRY_METRICS_ENABLED ?? false), - prometheus: { host: undefined, - port: Number(process.env.OPEN_TELEMETRY_METRICS_PORT), - endpoint: process.env.OPEN_TELEMETRY_METRICS_ENDPOINT, - prefix: "", - appendTimestamp: true}, - nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), - }, - tracing: { - enabled: Boolean(process.env.OPEN_TELEMETRY_TRACING_ENABLED ?? false), - otlp: { - url: process.env.OPEN_TELEMETRY_TRACING_URL, - }, - }, - }, + LocalTaskWorkerModule: VanillaTaskWorkerModules.defaultConfig() }, ...baseAppChainModulesConfig, diff --git a/packages/chain/src/environments/sovereign/chain.config.ts b/packages/chain/src/environments/sovereign/chain.config.ts index 1a9b56e..441fc8b 100644 --- a/packages/chain/src/environments/sovereign/chain.config.ts +++ b/packages/chain/src/environments/sovereign/chain.config.ts @@ -1,7 +1,12 @@ import { AppChain } from "@proto-kit/sdk"; import { Runtime } from "@proto-kit/module"; import { Protocol } from "@proto-kit/protocol"; -import { DatabasePruneModule, Sequencer } from "@proto-kit/sequencer"; +import { + DatabasePruneModule, + LocalTaskWorkerModule, + Sequencer, + VanillaTaskWorkerModules +} from "@proto-kit/sequencer"; import { PrismaRedisDatabase } from "@proto-kit/persistance"; import runtime from "../../runtime"; import protocol from "../../protocol"; @@ -10,6 +15,8 @@ import { baseSequencerModulesConfig, indexerSequencerModules, indexerSequencerModulesConfig, + metricsSequencerModules, + metricsSequencerModulesConfig, } from "../../sequencer"; import { BullQueue, Startable } from "@proto-kit/deployment"; import { Arguments } from "../../start"; @@ -17,7 +24,6 @@ import { baseAppChainModules, baseAppChainModulesConfig, } from "../../app-chain"; -import {OpenTelemetryServer} from "@proto-kit/api"; export const appChain = AppChain.from({ Runtime: Runtime.from({ @@ -30,11 +36,12 @@ export const appChain = AppChain.from({ modules: { // ordering of the modules matters due to dependency resolution Database: PrismaRedisDatabase, + LocalTaskWorkerModule: LocalTaskWorkerModule.from(VanillaTaskWorkerModules.withoutSettlement()), + TaskQueue: BullQueue, ...baseSequencerModules, ...indexerSequencerModules, - TaskQueue: BullQueue, + ...metricsSequencerModules, DatabasePruneModule, - OpenTelemetryServer: OpenTelemetryServer }, }), modules: baseAppChainModules, @@ -47,6 +54,7 @@ export default async (args: Arguments): Promise => { Sequencer: { ...baseSequencerModulesConfig, ...indexerSequencerModulesConfig, + ...metricsSequencerModulesConfig, DatabasePruneModule: { pruneOnStartup: args.pruneOnStartup, }, @@ -67,23 +75,7 @@ export default async (args: Arguments): Promise => { connection: process.env.DATABASE_URL!, }, }, - OpenTelemetryServer: { - metrics: { - enabled: Boolean(process.env.OPEN_TELEMETRY_METRICS_ENABLED ?? false), - prometheus: { host: undefined, - port: Number(process.env.OPEN_TELEMETRY_METRICS_PORT), - endpoint: process.env.OPEN_TELEMETRY_METRICS_ENDPOINT, - prefix: "", - appendTimestamp: true}, - nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), - }, - tracing: { - enabled: Boolean(process.env.OPEN_TELEMETRY_TRACING_ENABLED ?? false), - otlp: { - url: process.env.OPEN_TELEMETRY_TRACING_URL, - }, - }, - }, + LocalTaskWorkerModule: VanillaTaskWorkerModules.defaultConfig() }, ...baseAppChainModulesConfig, }); diff --git a/packages/chain/src/sequencer/index.ts b/packages/chain/src/sequencer/index.ts index 900b228..f065b89 100644 --- a/packages/chain/src/sequencer/index.ts +++ b/packages/chain/src/sequencer/index.ts @@ -2,12 +2,14 @@ import { VanillaGraphqlModules, GraphqlSequencerModule, GraphqlServer, + OpenTelemetryServer, } from "@proto-kit/api"; import { PrivateMempool, SequencerModulesRecord, TimedBlockTrigger, BlockProducerModule, + SequencerStartupModule, } from "@proto-kit/sequencer"; import { ModulesConfig } from "@proto-kit/common"; import { IndexerNotifier } from "@proto-kit/indexer"; @@ -28,11 +30,36 @@ export const apiSequencerModulesConfig = { }, } satisfies ModulesConfig; +export const metricsSequencerModules = { + OpenTelemetryServer +} satisfies SequencerModulesRecord; + +export const metricsSequencerModulesConfig = { + OpenTelemetryServer: { + metrics: { + enabled: Boolean(process.env.OPEN_TELEMETRY_METRICS_ENABLED ?? false), + prometheus: { + host: process.env.OPEN_TELEMETRY_METRICS_HOST ?? "localhost", + port: Number(process.env.OPEN_TELEMETRY_METRICS_PORT), + appendTimestamp: true + }, + nodeScrapeInterval: Number(process.env.OPEN_TELEMETRY_METRICS_SCRAPING_FREQUENCY ?? 10), + }, + tracing: { + enabled: Boolean(process.env.OPEN_TELEMETRY_TRACING_ENABLED ?? false), + otlp: { + url: process.env.OPEN_TELEMETRY_TRACING_URL, + }, + }, + }, +} satisfies ModulesConfig; + export const baseSequencerModules = { ...apiSequencerModules, Mempool: PrivateMempool, BlockProducerModule: BlockProducerModule, BlockTrigger: TimedBlockTrigger, + SequencerStartupModule } satisfies SequencerModulesRecord; export const baseSequencerModulesConfig = { @@ -43,6 +70,7 @@ export const baseSequencerModulesConfig = { blockInterval: Number(process.env.PROTOKIT_BLOCK_INTERVAL!), produceEmptyBlocks: true, }, + SequencerStartupModule: {} } satisfies ModulesConfig; export const indexerSequencerModules = { From b913f2407a74348ef5ae8f5f5e72f8d29432ba80 Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 19:00:46 +0100 Subject: [PATCH 20/21] Added documentation to readme --- README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26f35a6..9e3e6b2 100644 --- a/README.md +++ b/README.md @@ -244,11 +244,43 @@ The caddy reverse-proxy automatically uses https for all connections, use this g +### Monitoring + +Protokit offers monitoring via three different kinds of data and a collection of preconfigured services: +- Logs via Promtail and Loki +- Metrics via OpenTelemetry and Prometheus +- Traces via OpenTelemetry, OTel Collector and Tempo +- Dashboard via Grafana + +#### Development + +In Development mode, monitoring is disabled by default. + +To enabled, edit the `development/.env` file in the following way: +1. Add the monitoring profile to `COMPOSE_PROFILES` +2. Uncomment `...metricsSequencerModules` in the sequencer's module definition. +Important: This has to be in front of all other modules (i.e. has to be first in the modules record) +3. Uncomment `...metricsSequencerModulesConfig` in the configuration call. + +Then, run `pnpm env:development docker:up` like usual. This should start all the services needed for monitoring. +Grafana is available at `localhost:3000`. + +Note: Logs are currently not available without docker, since promtail is only configured to pick up container logs + +#### Sovereign + +In Sovereign mode, monitoring is configured by default. + +Grafana is reachable under `localhost/grafana`. + +If you want to remove the monitoring services, remove the docker profile `monitoring` from the `.env` file and remove the `OpenTelemetryServer` configuration + +More information about monitoring can be found [here](https://github.com/proto-kit/framework/pull/272). ## Building the framework from source 1. Make sure the framework is located under ../framework from the starter-kit's location 2. Adapt your starter-kit's `packages/chain` and `apps/web` package.json to use the file:// references to framework, including -references to `o1js` and `tsyringe`. +references to `o1js` and `tsyringe`. Important: Make sure to update references in both chain and web, otherwise the location of the node_modules will be different and lead to errors 3. Go into the framework folder, and build a docker image containing the sources with `docker build -f ./packages/deployment/docker/development-base/Dockerfile -t protokit-base .` 4. Replace the first line of `docker/base/Dockerfile` and `docker/web/Dockerfile` to use `FROM protokit-base:latest` From e7d19dd8b57149666248355459ee07702acaaed3 Mon Sep 17 00:00:00 2001 From: Raphael Panic Date: Thu, 13 Feb 2025 19:01:03 +0100 Subject: [PATCH 21/21] Removed unused import --- packages/chain/src/environments/development/chain.config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/chain/src/environments/development/chain.config.ts b/packages/chain/src/environments/development/chain.config.ts index 2f77d97..e08e4dc 100644 --- a/packages/chain/src/environments/development/chain.config.ts +++ b/packages/chain/src/environments/development/chain.config.ts @@ -17,7 +17,6 @@ import { baseAppChainModules, baseAppChainModulesConfig, } from "../../app-chain"; -import {OpenTelemetryServer} from "@proto-kit/api"; export const appChain = AppChain.from({ Runtime: Runtime.from({