Skip to content

Commit 90eceb9

Browse files
authored
Add debugger to Docker compose (#2667)
* Run Cortex under Delve debugger, and allow remote debugging. Signed-off-by: Peter Štibraný <[email protected]> * Added remote debugging config for Goland. Signed-off-by: Peter Štibraný <[email protected]>
1 parent bc2588c commit 90eceb9

11 files changed

+67
-11
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#!/bin/bash
22

3+
set -e
4+
35
SCRIPT_DIR=$(cd `dirname $0` && pwd)
46

5-
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${SCRIPT_DIR}/cortex ${SCRIPT_DIR}/../../cmd/cortex && \
6-
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml build distributor && \
7+
# -gcflags "all=-N -l" disables optimizations that allow for better run with combination with Delve debugger.
8+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=vendor -gcflags "all=-N -l" -o ${SCRIPT_DIR}/cortex ${SCRIPT_DIR}/../../cmd/cortex
9+
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml build distributor
710
docker-compose -f ${SCRIPT_DIR}/docker-compose.yml up $@
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
FROM golang:1.14
2+
ENV CGO_ENABLED=0 GOOS=linux GOARCH=amd64
3+
RUN go get github.com/go-delve/delve/cmd/dlv
14
FROM alpine:3.10
25

36
RUN mkdir /cortex
47
WORKDIR /cortex
58
ADD ./cortex ./
9+
COPY --from=0 /go/bin/dlv ./

development/tsdb-blocks-storage-s3/docker-compose.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ services:
5555
context: .
5656
dockerfile: dev.dockerfile
5757
image: cortex
58-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=distributor -server.http-listen-port=8001 -server.grpc-listen-port=9001"]
58+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18001 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=distributor -server.http-listen-port=8001 -server.grpc-listen-port=9001"]
5959
depends_on:
6060
- consul
6161
- minio
@@ -67,6 +67,7 @@ services:
6767
- JAEGER_SAMPLER_PARAM=1
6868
ports:
6969
- 8001:8001
70+
- 18001:18001
7071
volumes:
7172
- ./config:/cortex/config
7273

@@ -75,7 +76,7 @@ services:
7576
context: .
7677
dockerfile: dev.dockerfile
7778
image: cortex
78-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=ingester -server.http-listen-port=8002 -server.grpc-listen-port=9002"]
79+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18002 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=ingester -server.http-listen-port=8002 -server.grpc-listen-port=9002"]
7980
depends_on:
8081
- consul
8182
- minio
@@ -87,6 +88,7 @@ services:
8788
- JAEGER_SAMPLER_PARAM=1
8889
ports:
8990
- 8002:8002
91+
- 18002:18002
9092
volumes:
9193
- ./config:/cortex/config
9294
- .data-ingester-1:/tmp/cortex-tsdb-ingester:delegated
@@ -96,7 +98,7 @@ services:
9698
context: .
9799
dockerfile: dev.dockerfile
98100
image: cortex
99-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=ingester -server.http-listen-port=8003 -server.grpc-listen-port=9003"]
101+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18003 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=ingester -server.http-listen-port=8003 -server.grpc-listen-port=9003"]
100102
depends_on:
101103
- consul
102104
- minio
@@ -108,6 +110,7 @@ services:
108110
- JAEGER_SAMPLER_PARAM=1
109111
ports:
110112
- 8003:8003
113+
- 18003:18003
111114
volumes:
112115
- ./config:/cortex/config
113116
- .data-ingester-2:/tmp/cortex-tsdb-ingester:delegated
@@ -117,7 +120,7 @@ services:
117120
context: .
118121
dockerfile: dev.dockerfile
119122
image: cortex
120-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=querier -server.http-listen-port=8004 -server.grpc-listen-port=9004"]
123+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18004 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=querier -server.http-listen-port=8004 -server.grpc-listen-port=9004"]
121124
depends_on:
122125
- consul
123126
- minio
@@ -129,6 +132,7 @@ services:
129132
- JAEGER_SAMPLER_PARAM=1
130133
ports:
131134
- 8004:8004
135+
- 18004:18004
132136
volumes:
133137
- ./config:/cortex/config
134138

@@ -137,7 +141,7 @@ services:
137141
context: .
138142
dockerfile: dev.dockerfile
139143
image: cortex
140-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=store-gateway -server.http-listen-port=8008 -server.grpc-listen-port=9008"]
144+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18008 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=store-gateway -server.http-listen-port=8008 -server.grpc-listen-port=9008"]
141145
depends_on:
142146
- consul
143147
- minio
@@ -149,6 +153,7 @@ services:
149153
- JAEGER_SAMPLER_PARAM=1
150154
ports:
151155
- 8008:8008
156+
- 18008:18008
152157
volumes:
153158
- ./config:/cortex/config
154159

@@ -157,7 +162,7 @@ services:
157162
context: .
158163
dockerfile: dev.dockerfile
159164
image: cortex
160-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=store-gateway -server.http-listen-port=8009 -server.grpc-listen-port=9009"]
165+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18009 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=store-gateway -server.http-listen-port=8009 -server.grpc-listen-port=9009"]
161166
depends_on:
162167
- consul
163168
- minio
@@ -169,6 +174,7 @@ services:
169174
- JAEGER_SAMPLER_PARAM=1
170175
ports:
171176
- 8009:8009
177+
- 18009:18009
172178
volumes:
173179
- ./config:/cortex/config
174180

@@ -177,7 +183,7 @@ services:
177183
context: .
178184
dockerfile: dev.dockerfile
179185
image: cortex
180-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=ruler -server.http-listen-port=8005 -server.grpc-listen-port=9005"]
186+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18005 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=ruler -server.http-listen-port=8005 -server.grpc-listen-port=9005"]
181187
depends_on:
182188
- consul
183189
- minio
@@ -189,6 +195,7 @@ services:
189195
- JAEGER_SAMPLER_PARAM=1
190196
ports:
191197
- 8005:8005
198+
- 18005:18005
192199
volumes:
193200
- ./config:/cortex/config
194201

@@ -197,7 +204,7 @@ services:
197204
context: .
198205
dockerfile: dev.dockerfile
199206
image: cortex
200-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=compactor -server.http-listen-port=8006 -server.grpc-listen-port=9006"]
207+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18006 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=compactor -server.http-listen-port=8006 -server.grpc-listen-port=9006"]
201208
depends_on:
202209
- consul
203210
- minio
@@ -209,6 +216,7 @@ services:
209216
- JAEGER_SAMPLER_PARAM=1
210217
ports:
211218
- 8006:8006
219+
- 18006:18006
212220
volumes:
213221
- ./config:/cortex/config
214222

@@ -217,7 +225,7 @@ services:
217225
context: .
218226
dockerfile: dev.dockerfile
219227
image: cortex
220-
command: ["sh", "-c", "sleep 3 && exec ./cortex -config.file=./config/cortex.yaml -target=query-frontend -server.http-listen-port=8007 -server.grpc-listen-port=9007"]
228+
command: ["sh", "-c", "sleep 3 && exec ./dlv exec ./cortex --listen=:18007 --headless=true --api-version=2 --accept-multiclient --continue -- -config.file=./config/cortex.yaml -target=query-frontend -server.http-listen-port=8007 -server.grpc-listen-port=9007"]
221229
depends_on:
222230
- consul
223231
- minio
@@ -229,5 +237,6 @@ services:
229237
- JAEGER_SAMPLER_PARAM=1
230238
ports:
231239
- 8007:8007
240+
- 18007:18007
232241
volumes:
233242
- ./config:/cortex/config
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Compactor" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18006">
3+
<method v="2" />
4+
</configuration>
5+
</component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Distributor" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18001">
3+
<method v="2" />
4+
</configuration>
5+
</component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Ingester-1" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18002">
3+
<method v="2" />
4+
</configuration>
5+
</component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Ingester-2" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18003">
3+
<method v="2" />
4+
</configuration>
5+
</component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Querier" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18004">
3+
<method v="2" />
4+
</configuration>
5+
</component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Query-frontend" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18007">
3+
<method v="2" />
4+
</configuration>
5+
</component>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TSDB Store-gateway-1" type="GoRemoteDebugConfigurationType" factoryName="Go Remote" port="18008">
3+
<method v="2" />
4+
</configuration>
5+
</component>

0 commit comments

Comments
 (0)