Skip to content

Commit e301e0a

Browse files
authored
add configuration & related readme notes for debugging gen-ai bff (tested in vscode) (opendatahub-io#5566)
1 parent 5d538c6 commit e301e0a

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

packages/gen-ai/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ dev-bff-mock: ## Run only the bff in development mode
3535
dev-bff:
3636
cd bff && MAAS_URL=${MAAS_URL} DISTRIBUTION_NAME=${DISTRIBUTION_NAME} LLAMA_STACK_URL=${LLAMA_STACK_URL} AUTH_TOKEN=user_token AUTH_TOKEN_HEADER=Authorization AUTH_TOKEN_PREFIX="Bearer " make run STATIC_ASSETS_DIR=../frontend/dist
3737

38+
.PHONY: dev-bff-debug
39+
dev-bff-debug: ## Run BFF with Delve debugger (VSCode can attach - requires Delve installation, see readme)
40+
cd bff && MAAS_URL=${MAAS_URL} DISTRIBUTION_NAME=${DISTRIBUTION_NAME} LLAMA_STACK_URL=${LLAMA_STACK_URL} AUTH_TOKEN=user_token AUTH_TOKEN_HEADER=Authorization AUTH_TOKEN_PREFIX="Bearer " make debug STATIC_ASSETS_DIR=../frontend/dist
3841

3942
.PHONY: dev-frontend
4043
dev-frontend: ## Run only the frontend in development mode
@@ -58,6 +61,16 @@ dev-start: dev-portforward ## Start frontend, bff, and port-forwarding
5861
@sleep 2
5962
make -j 2 dev-bff dev-frontend
6063

64+
.PHONY: dev-start-debug
65+
dev-start-debug: dev-portforward ## Start frontend, bff with debugger, and port-forwarding (VSCode can attach on port 2345)
66+
@sleep 2
67+
@echo ""
68+
@echo "🐛 Starting in DEBUG mode..."
69+
@echo "📍 Delve debugger will listen on port 2345"
70+
@echo "📍 In VSCode: Press F5 and select 'Attach to Delve (make dev-start-debug)'"
71+
@echo ""
72+
make -j 2 dev-bff-debug dev-frontend
73+
6174
.PHONY: dev-start-no-portforward
6275
dev-start-no-portforward: ## Start frontend and bff without port-forwarding
6376
make -j 2 dev-bff dev-frontend

packages/gen-ai/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,46 @@ make dev-start-no-portforward
124124

125125
These commands will run both services in parallel, making it easier to start your development environment with a single command.
126126

127+
## Debugging the bff
128+
129+
If you want to be able to set breakpoints in vscode, you must first ensure the following debug config is added to your .vscode/launch.json file.
130+
131+
```json
132+
{
133+
"version": "0.2.0",
134+
"configurations": [
135+
{
136+
"name": "Attach to Delve (make dev-start-debug)",
137+
"type": "go",
138+
"request": "attach",
139+
"mode": "remote",
140+
"remotePath": "${workspaceFolder}/packages/gen-ai/bff",
141+
"port": 2345,
142+
"host": "localhost",
143+
"showLog": true,
144+
"trace": "verbose"
145+
},
146+
]
147+
}
148+
```
149+
150+
The debug approach will use the 'debug' command defined in packages/gen-ai/bff/Makefile, which uses 'dlv' (short for Delve, a debugger for the Go programming language, more at [github repo](https://github.com/go-delve/delve/tree/master)), which will need to be installed locally first.
151+
152+
You can install the latest version with:
153+
154+
```bash
155+
go install github.com/go-delve/delve/cmd/dlv@latest
156+
```
157+
158+
Then run the below, which will start the gen-ai frontend, bff with debugger, and port-forwarding (VSCode can attach on port 2345).
159+
160+
```bash
161+
cd packages/gen-ai
162+
make dev-start-debug
163+
```
164+
165+
Once everything is running and ready, you can click on the 'Run and Debug' tab in left navbar, and in the top dropdown, select and run 'Attach to Delve (make dev-start-debug)'. Now you should be able to set breakpoints in order to debug code inside packages/gen-ai/bff.
166+
127167
## Building and Running with Docker
128168

129169
The project includes a multi-stage Dockerfile that builds both the frontend and backend components and creates a minimal production image.

packages/gen-ai/bff/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
vendor/
22
pkg/
3+
4+
# Debug files generated by running debugger can be ignored
5+
__debug*

packages/gen-ai/bff/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ run: fmt vet envtest ## Runs the project.
5656
ENVTEST_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
5757
go run ./cmd --port=$(PORT) --static-assets-dir=$(STATIC_ASSETS_DIR) --log-level=$(LOG_LEVEL) --allowed-origins=$(ALLOWED_ORIGINS) --llama-stack-url=$(LLAMA_STACK_URL) --maas-url=$(MAAS_URL) --mock-ls-client=$(MOCK_LS_CLIENT) --mock-k8s-client=$(MOCK_K8S_CLIENT) --mock-mcp-client=$(MOCK_MCP_CLIENT) --mock-maas-client=$(MOCK_MAAS_CLIENT) --auth-method=$(AUTH_METHOD) --path-prefix=$(PATH_PREFIX) --filtered-model-keywords=$(FILTERED_MODEL_KEYWORDS) --distribution-name=$(DISTRIBUTION_NAME)
5858

59+
.PHONY: debug
60+
debug: fmt vet envtest ## Runs the project with Delve debugger (VSCode can attach on port 2345).
61+
@echo "Starting BFF with Delve debugger on port 2345..."
62+
@echo "In VSCode: Press F5 and select 'Attach to Delve (make dev-start-debug)'"
63+
ENVTEST_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" \
64+
dlv debug ./cmd --headless --listen=:2345 --api-version=2 --accept-multiclient --continue -- \
65+
--port=$(PORT) --static-assets-dir=$(STATIC_ASSETS_DIR) --log-level=$(LOG_LEVEL) --allowed-origins=$(ALLOWED_ORIGINS) --llama-stack-url=$(LLAMA_STACK_URL) --maas-url=$(MAAS_URL) --mock-ls-client=$(MOCK_LS_CLIENT) --mock-k8s-client=$(MOCK_K8S_CLIENT) --mock-mcp-client=$(MOCK_MCP_CLIENT) --mock-maas-client=$(MOCK_MAAS_CLIENT) --auth-method=$(AUTH_METHOD) --path-prefix=$(PATH_PREFIX) --filtered-model-keywords=$(FILTERED_MODEL_KEYWORDS) --distribution-name=$(DISTRIBUTION_NAME)
66+
5967
##@ Dependencies
6068

6169
## Location to install dependencies to

0 commit comments

Comments
 (0)