-
Notifications
You must be signed in to change notification settings - Fork 0
chore(spring-prometheus-grafana-example): adjustments to bring abstra… #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ction in the GitHub workflows
WalkthroughThe GitHub Actions workflows for both the Spring Kafka and Spring Prometheus Grafana examples were updated to dynamically extract service names from their Docker Compose files. The health check steps now iterate over all detected services, checking each container's running state, replacing previous hardcoded service checks. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
♻️ Duplicate comments (1)
.github/workflows/spring-kafka-example.yml (1)
48-77: Same improvements recommended as for the Prometheus/Grafana workflowThe extraction step should enable strict shell flags, and the health-check loop should rely on container IDs from
docker compose psto prevent false negatives. See prior comments on lines 48-54 and 70-77 of the Prometheus/Grafana workflow for concrete diffs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/spring-kafka-example.yml(2 hunks).github/workflows/spring-prometheus-grafana-example.yml(2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#21
File: spring-kafka-example/README.md:12-17
Timestamp: 2025-07-22T01:35:41.406Z
Learning: User igorcampos-dev prefers minimal, high-level documentation in README files without detailed version specifications, choosing to keep tech stack information simple rather than adding precise version numbers.
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#26
File: spring-kafka-example/compose.yaml:3-4
Timestamp: 2025-07-24T01:40:49.337Z
Learning: User igorcampos-dev requires hard-coded container names in Docker Compose files (like `container_name: app`) for CI pipeline validation purposes, which is a valid operational requirement that overrides the general best practice of avoiding hard-coded container names.
Learnt from: igorcampos-dev
PR: igorcampos-dev/spring-integrations-examples#21
File: spring-kafka-example/compose.yaml:30-32
Timestamp: 2025-07-22T01:30:57.054Z
Learning: User igorcampos-dev prefers to maintain environment parity between local development and production, avoiding development-specific configurations like ALLOW_PLAINTEXT_LISTENER even when they might provide clearer intent or safety nets.
.github/workflows/spring-kafka-example.yml (1)
Learnt from: igorcampos-dev
PR: #26
File: spring-kafka-example/compose.yaml:3-4
Timestamp: 2025-07-24T01:40:49.337Z
Learning: User igorcampos-dev requires hard-coded container names in Docker Compose files (like container_name: app) for CI pipeline validation purposes, which is a valid operational requirement that overrides the general best practice of avoiding hard-coded container names.
.github/workflows/spring-prometheus-grafana-example.yml (1)
Learnt from: igorcampos-dev
PR: #26
File: spring-kafka-example/compose.yaml:3-4
Timestamp: 2025-07-24T01:40:49.337Z
Learning: User igorcampos-dev requires hard-coded container names in Docker Compose files (like container_name: app) for CI pipeline validation purposes, which is a valid operational requirement that overrides the general best practice of avoiding hard-coded container names.
🪛 YAMLlint (1.37.1)
.github/workflows/spring-kafka-example.yml
[error] 78-78: no new line character at the end of file
(new-line-at-end-of-file)
.github/workflows/spring-prometheus-grafana-example.yml
[error] 78-78: no new line character at the end of file
(new-line-at-end-of-file)
| echo "::error ::Service $service is not running." | ||
| exit 1 | ||
| fi | ||
| done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Add a trailing newline
Identical lint warning as the other workflow—insert a newline at EOF.
- done
\ No newline at end of file
+ done
+📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| done | |
| done | |
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 78-78: no new line character at the end of file
(new-line-at-end-of-file)
🤖 Prompt for AI Agents
In .github/workflows/spring-kafka-example.yml at line 78, the file is missing a
trailing newline at the end of the file. Add a single newline character after
the last line to comply with linting rules and ensure proper file formatting.
| - name: Extract service names from docker compose | ||
| id: services | ||
| run: | | ||
| echo "services<<EOF" >> $GITHUB_OUTPUT | ||
| docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT | ||
| echo "EOF" >> $GITHUB_OUTPUT | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add strict shell-flags to surface failures early
If docker compose config --services fails (e.g., syntax error in compose.yaml or missing CLI plugin), the step will still succeed and later steps will receive an empty services output, masking the root cause. Enable set -euo pipefail so that the workflow aborts immediately on any error.
- - name: Extract service names from docker compose
+ - name: Extract service names from docker compose
id: services
run: |
+ set -euo pipefail
echo "services<<EOF" >> $GITHUB_OUTPUT
docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| - name: Extract service names from docker compose | |
| id: services | |
| run: | | |
| echo "services<<EOF" >> $GITHUB_OUTPUT | |
| docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Extract service names from docker compose | |
| id: services | |
| run: | | |
| set -euo pipefail | |
| echo "services<<EOF" >> $GITHUB_OUTPUT | |
| docker compose -f ./spring-prometheus-grafana-example/compose.yaml config --services >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT |
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml around lines 48 to
54, the shell script running the docker compose command lacks strict error
handling, so failures do not abort the workflow immediately. Add `set -euo
pipefail` at the start of the run block to ensure the step fails fast on any
error, preventing silent failures and empty outputs downstream.
| SERVICES="${{ steps.services.outputs.services }}" | ||
| for service in $SERVICES; do | ||
| status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false") | ||
| echo "$service status: $status" | ||
| if [ "$status" != "true" ]; then | ||
| echo "::error ::Service $service is not running." | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Use container IDs from docker compose ps to avoid name-mismatch errors
docker inspect "$service" assumes every service sets container_name: and that the runtime name equals the service name. If those assumptions ever change, the health-check produces false negatives. Resolve by asking Compose for the container ID first:
- for service in $SERVICES; do
- status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
+ for service in $SERVICES; do
+ cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
+ status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
doneI need to inspect the workflow to see how services are defined and whether a COMPOSE_FILE variable is in use. Gathering context now:
🏁 Script executed:
#!/bin/bash
# Locate and preview the workflow around the health-check step
file=$(fd spring-prometheus-grafana-example.yml)
echo "Workflow file: $file"
sed -n '1,200p' "$file"Length of output: 155
Gathering workflow files and inspecting Docker commands:
🏁 Script executed:
#!/bin/bash
# List all workflow files
echo "Workflow files:"
find .github/workflows -type f \( -name '*.yml' -o -name '*.yaml' \)
echo ""
# Search for docker inspect in workflows
echo "docker inspect occurrences:"
rg -n 'docker inspect' .github/workflows || true
echo ""
# Search for docker compose usage in workflows
echo "docker compose occurrences:"
rg -n 'docker compose' .github/workflows || trueLength of output: 1294
Use container IDs from docker compose ps for reliable health checks
Relying on service names in docker inspect assumes the runtime container name matches the Compose service name (or a hard-coded container_name:). To avoid false negatives if that ever changes, first query the container ID with docker compose ps -q and then inspect that ID:
In .github/workflows/spring-prometheus-grafana-example.yml (around lines 70–77), update the loop as follows:
- for service in $SERVICES; do
- status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false")
+ for service in $SERVICES; do
+ # Get the container ID for this service
+ cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service")
+ # Inspect by ID to avoid name mismatches
+ status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false")
echo "$service status: $status"
if [ "$status" != "true" ]; then
echo "::error ::Service $service is not running."
exit 1
fi
done- Ensures the health check always targets the correct container, regardless of explicit
container_name:settings or Compose naming conventions. - Uses the same Compose file path you already reference for
config --services.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| SERVICES="${{ steps.services.outputs.services }}" | |
| for service in $SERVICES; do | |
| status=$(docker inspect -f '{{.State.Running}}' "$service" || echo "false") | |
| echo "$service status: $status" | |
| if [ "$status" != "true" ]; then | |
| echo "::error ::Service $service is not running." | |
| exit 1 | |
| fi | |
| SERVICES="${{ steps.services.outputs.services }}" | |
| for service in $SERVICES; do | |
| # Get the container ID for this service | |
| cid=$(docker compose -f ./spring-prometheus-grafana-example/compose.yaml ps -q "$service") | |
| # Inspect by ID to avoid name mismatches | |
| status=$(docker inspect -f '{{.State.Running}}' "$cid" 2>/dev/null || echo "false") | |
| echo "$service status: $status" | |
| if [ "$status" != "true" ]; then | |
| echo "::error ::Service $service is not running." | |
| exit 1 | |
| fi | |
| done |
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml around lines 70 to
77, the current health check uses service names with docker inspect, which can
fail if container names differ from service names. To fix this, first retrieve
container IDs using docker compose ps -q with the same Compose file path, then
loop over these container IDs to inspect their running state. This ensures the
health check targets the correct containers regardless of naming conventions or
container_name overrides.
| echo "::error ::Service $service is not running." | ||
| exit 1 | ||
| fi | ||
| done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Add a trailing newline
The YAML file is missing a final newline, flagged by yamllint.
Fixing it avoids noisy lint failures.
- done
\ No newline at end of file
+ done
+📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| done | |
| done | |
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 78-78: no new line character at the end of file
(new-line-at-end-of-file)
🤖 Prompt for AI Agents
In .github/workflows/spring-prometheus-grafana-example.yml at line 78, the file
is missing a trailing newline at the end. Add a newline character after the last
line to comply with YAML formatting standards and prevent yamllint warnings.
…ction in the GitHub workflows
Summary by CodeRabbit