Skip to content

Commit 742ff6c

Browse files
authored
chore: add docker-compose for mysql and begin deprecating go_sql_* (#2904)
1 parent 12d975a commit 742ff6c

File tree

2 files changed

+183
-1
lines changed

2 files changed

+183
-1
lines changed

docker-compose.mysql.yaml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
# FOR DEVELOPMENT ONLY
3+
# docker-compose -f docker-compose.mysql.yaml up --build
4+
services:
5+
mysql:
6+
image: "mysql:latest"
7+
restart: "unless-stopped"
8+
ports:
9+
- "3306:3306"
10+
environment:
11+
- "MYSQL_ROOT_PASSWORD=secret"
12+
- "MYSQL_DATABASE=spicedb"
13+
healthcheck:
14+
test:
15+
[
16+
"CMD",
17+
"mysqladmin",
18+
"ping",
19+
"-h",
20+
"localhost",
21+
"-u",
22+
"root",
23+
"-psecret",
24+
]
25+
interval: "3s"
26+
timeout: "3s"
27+
retries: 10
28+
migrate:
29+
depends_on:
30+
mysql:
31+
condition: "service_healthy"
32+
build: "."
33+
container_name: "migrate"
34+
environment:
35+
- "SPICEDB_DATASTORE_ENGINE=mysql"
36+
- "SPICEDB_DATASTORE_CONN_URI=root:secret@(mysql:3306)/spicedb?parseTime=true"
37+
command: "datastore migrate head"
38+
networks:
39+
- "default"
40+
nginx:
41+
image: "nginx:latest"
42+
ports:
43+
- "50051:50051" # grpc
44+
- "8443:8443" # http
45+
volumes:
46+
- "./development/nginx.conf:/etc/nginx/nginx.conf"
47+
depends_on:
48+
spicedb-1:
49+
condition: "service_healthy"
50+
spicedb-2:
51+
condition: "service_healthy"
52+
spicedb-1:
53+
container_name: "spicedb-1"
54+
build: "."
55+
command: "serve"
56+
restart: "no"
57+
ports:
58+
- "9090" # prometheus metrics
59+
- "50051" # grpc endpoint
60+
- "8443" # http endpoint
61+
- "50053" # dispatch endpoint
62+
environment:
63+
- "SPICEDB_LOG_FORMAT=json"
64+
- "SPICEDB_LOG_LEVEL=info"
65+
- "SPICEDB_HTTP_ENABLED=true"
66+
- "SPICEDB_GRPC_PRESHARED_KEY=foobar"
67+
- "SPICEDB_DATASTORE_ENGINE=mysql"
68+
- "SPICEDB_DATASTORE_CONN_URI=root:secret@(mysql:3306)/spicedb?parseTime=true"
69+
- "SPICEDB_DISPATCH_CLUSTER_ENABLED=true"
70+
- "SPICEDB_DISPATCH_UPSTREAM_ADDR=spicedb-2:50053"
71+
- "SPICEDB_OTEL_PROVIDER=otlpgrpc"
72+
- "SPICEDB_OTEL_SAMPLE_RATIO=1"
73+
- "SPICEDB_TELEMETRY_ENDPOINT="
74+
- "SPICEDB_GRPC_LOG_REQUESTS_ENABLED=false"
75+
- "SPICEDB_GRPC_LOG_RESPONSES_ENABLED=false"
76+
- "SPICEDB_STREAMING_API_RESPONSE_DELAY_TIMEOUT=0s"
77+
- "OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317"
78+
depends_on:
79+
migrate:
80+
condition: "service_completed_successfully"
81+
otel-collector:
82+
condition: "service_started"
83+
healthcheck:
84+
test: ["CMD", "/bin/grpc_health_probe", "-addr=localhost:50051"]
85+
interval: "5s"
86+
timeout: "30s"
87+
retries: 3
88+
spicedb-2:
89+
container_name: "spicedb-2"
90+
build: "."
91+
command: "serve"
92+
restart: "no"
93+
ports:
94+
- "9090" # prometheus metrics
95+
- "50051" # grpc endpoint
96+
- "8443" # http endpoint
97+
- "50053" # dispatch endpoint
98+
environment:
99+
- "SPICEDB_LOG_FORMAT=json"
100+
- "SPICEDB_LOG_LEVEL=info"
101+
- "SPICEDB_HTTP_ENABLED=true"
102+
- "SPICEDB_GRPC_PRESHARED_KEY=foobar"
103+
- "SPICEDB_DATASTORE_ENGINE=mysql"
104+
- "SPICEDB_DATASTORE_CONN_URI=root:secret@(mysql:3306)/spicedb?parseTime=true"
105+
- "SPICEDB_DISPATCH_CLUSTER_ENABLED=true"
106+
- "SPICEDB_DISPATCH_UPSTREAM_ADDR=spicedb-1:50053"
107+
- "SPICEDB_OTEL_PROVIDER=otlpgrpc"
108+
- "SPICEDB_OTEL_SAMPLE_RATIO=1"
109+
- "SPICEDB_TELEMETRY_ENDPOINT="
110+
- "SPICEDB_GRPC_LOG_REQUESTS_ENABLED=true"
111+
- "SPICEDB_GRPC_LOG_RESPONSES_ENABLED=false"
112+
- "SPICEDB_STREAMING_API_RESPONSE_DELAY_TIMEOUT=0s"
113+
- "OTEL_EXPORTER_OTLP_ENDPOINT=http://otel-collector:4317"
114+
depends_on:
115+
migrate:
116+
condition: "service_completed_successfully"
117+
otel-collector:
118+
condition: "service_started"
119+
healthcheck:
120+
test: ["CMD", "/bin/grpc_health_probe", "-addr=localhost:50051"]
121+
interval: "5s"
122+
timeout: "30s"
123+
retries: 3
124+
prometheus:
125+
image: "prom/prometheus:v2.47.0"
126+
command:
127+
- "--config.file=/etc/prometheus/prometheus.yaml"
128+
- "--storage.tsdb.path=/prometheus"
129+
volumes:
130+
- "./development/prometheus.yaml:/etc/prometheus/prometheus.yaml"
131+
ports:
132+
- "9091:9090" # Prometheus UI
133+
restart: "unless-stopped"
134+
otel-collector:
135+
image: "otel/opentelemetry-collector:0.60.0"
136+
command: "--config /etc/otel-config.yaml"
137+
volumes:
138+
- "./development/otel-config.yaml:/etc/otel-config.yaml"
139+
ports:
140+
- "4317:4317" # OTLP gRPC
141+
- "8888" # Prometheus metrics for collector
142+
depends_on:
143+
- "tempo"
144+
loki:
145+
image: "grafana/loki:2.9.0"
146+
command: "-config.file=/etc/loki/loki.yaml"
147+
volumes:
148+
- "./development/loki.yaml:/etc/loki/loki.yaml"
149+
ports:
150+
- "3100" # Loki API
151+
restart: "unless-stopped"
152+
tempo:
153+
image: "grafana/tempo:1.5.0"
154+
command: "-search.enabled=true -config.file=/etc/tempo.yaml"
155+
volumes:
156+
- "./development/tempo.yaml:/etc/tempo.yaml"
157+
restart: "unless-stopped"
158+
ports:
159+
- "4317" # OTLP gRPC
160+
- "3100" # tempo
161+
grafana:
162+
image: "grafana/grafana:9.1.5-ubuntu"
163+
volumes:
164+
- "./development/grafana/provisioning/datasources:/etc/grafana/provisioning/datasources"
165+
- "./development/grafana/provisioning/dashboards:/etc/grafana/provisioning/dashboards"
166+
- "./development/grafana/dashboards:/etc/grafana/dashboards"
167+
environment:
168+
- "GF_AUTH_ANONYMOUS_ENABLED=true"
169+
- "GF_AUTH_ANONYMOUS_ORG_ROLE=Admin"
170+
- "GF_AUTH_DISABLE_LOGIN_FORM=true"
171+
ports:
172+
- "3000:3000" # UI
173+
depends_on:
174+
- "tempo"
175+
- "prometheus"
176+
- "loki"

internal/datastore/mysql/datastore.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/go-sql-driver/mysql"
1717
"github.com/google/uuid"
1818
"github.com/prometheus/client_golang/prometheus"
19+
prom_collectors "github.com/prometheus/client_golang/prometheus/collectors"
1920
"go.opentelemetry.io/otel"
2021
"golang.org/x/sync/errgroup"
2122

@@ -700,7 +701,12 @@ func registerAndReturnPrometheusCollectors(replicaIndex int, isPrimary bool, con
700701
}
701702

702703
db := sql.OpenDB(connector)
703-
collector := sqlstats.NewStatsCollector(dbName, db)
704+
deprecatedCollector := sqlstats.NewStatsCollector(dbName, db) // TODO(miparnisari): remove in v1.51.0
705+
collector := prom_collectors.NewDBStatsCollector(db, dbName)
706+
if err := prometheus.Register(deprecatedCollector); err != nil {
707+
return nil, collectors, err
708+
}
709+
collectors = append(collectors, deprecatedCollector)
704710
if err := prometheus.Register(collector); err != nil {
705711
return nil, collectors, err
706712
}

0 commit comments

Comments
 (0)