Repository navigation
feat: richer diagnostics health summary #84
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,16 @@ import ( | |
| "encoding/json" | ||
| "net/http" | ||
| "net/http/httptest" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "blackbox/server/internal/auth" | ||
| "blackbox/server/internal/db" | ||
| "blackbox/server/internal/handlers" | ||
| bbmcp "blackbox/server/internal/mcp" | ||
| "blackbox/server/internal/models" | ||
| "github.com/oklog/ulid/v2" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
@@ -97,6 +101,98 @@ func TestHealthCheck_DBError_Returns503(t *testing.T) { | |
| assert.Equal(t, "error", resp["database"]) | ||
| } | ||
|
|
||
| func TestHealthCheck_RichLocalSummaryDoesNotExposeSecretsOrProbeProviders(t *testing.T) { | ||
| database := newTestDB(t) | ||
| registry := auth.NewOIDCRegistry(database) | ||
| mcpManager := bbmcp.NewMCPManager(database) | ||
| require.NoError(t, mcpManager.ApplySettings(true, "mcp-health-secret")) | ||
|
|
||
| now := time.Now().UTC() | ||
| require.NoError(t, database.Create(&models.AppSetting{Key: "ai_provider", Value: "openai_compat"}).Error) | ||
| require.NoError(t, database.Create(&models.AppSetting{Key: "ai_url", Value: "http://127.0.0.1:1"}).Error) | ||
| require.NoError(t, database.Create(&models.AppSetting{Key: "ai_model", Value: "local-model"}).Error) | ||
| require.NoError(t, database.Create(&models.AppSetting{Key: "ai_api_key", Value: "ai-health-secret"}).Error) | ||
| require.NoError(t, database.Create(&models.AppSetting{Key: "mcp_enabled", Value: "true"}).Error) | ||
| require.NoError(t, database.Create(&models.AppSetting{Key: "mcp_auth_token", Value: "mcp-health-secret"}).Error) | ||
| require.NoError(t, database.Create(&models.NotificationDest{ | ||
| ID: "notification-1", Name: "Ops", Type: "slack", URL: "https://hooks.example/notification-secret", Enabled: true, | ||
| }).Error) | ||
| require.NoError(t, database.Create(&models.DataSourceInstance{ | ||
| ID: ulid.Make().String(), Type: "webhook_uptime_kuma", Scope: models.ScopeServer, | ||
| Name: "Uptime Kuma", Config: `{"secret":"webhook-health-secret"}`, Enabled: true, | ||
| }).Error) | ||
| require.NoError(t, database.Create(&models.DataSourceInstance{ | ||
| ID: ulid.Make().String(), Type: "webhook_watchtower", Scope: models.ScopeServer, | ||
| Name: "Watchtower", Config: `{"secret":"disabled-webhook-secret"}`, Enabled: false, | ||
| }).Error) | ||
| require.NoError(t, database.Create(&models.Node{ID: "node-online", Name: "online", LastSeen: now, Status: "online"}).Error) | ||
| require.NoError(t, database.Create(&models.Node{ID: "node-stale", Name: "stale", LastSeen: now.Add(-10 * time.Minute), Status: "online"}).Error) | ||
| require.NoError(t, database.Create(&models.Node{ID: "node-offline", Name: "offline", LastSeen: now, Status: "offline"}).Error) | ||
|
|
||
| req := httptest.NewRequest(http.MethodGet, "/api/setup/health", nil) | ||
| w := httptest.NewRecorder() | ||
| handlers.HealthCheckWithBuildInfo(database, registry, mcpManager, "1.2.3", "abc123")(w, req) | ||
|
|
||
| assert.Equal(t, http.StatusOK, w.Code) | ||
| body := w.Body.String() | ||
| for _, secret := range []string{"mcp-health-secret", "ai-health-secret", "webhook-health-secret", "disabled-webhook-secret", "notification-secret"} { | ||
| assert.NotContains(t, body, secret) | ||
| } | ||
|
|
||
| var resp struct { | ||
| Version string `json:"version"` | ||
| Commit string `json:"commit"` | ||
| MCP struct { | ||
| Enabled bool `json:"enabled"` | ||
| TokenConfigured bool `json:"token_configured"` | ||
| Running bool `json:"running"` | ||
| } `json:"mcp"` | ||
| AI struct { | ||
| Provider string `json:"provider"` | ||
| Configured bool `json:"configured"` | ||
| Testable bool `json:"testable"` | ||
| APIKeyConfigured bool `json:"api_key_configured"` | ||
| } `json:"ai"` | ||
| Nodes struct { | ||
| Total int64 `json:"total"` | ||
| Online int64 `json:"online"` | ||
| Offline int64 `json:"offline"` | ||
| Stale int64 `json:"stale"` | ||
| } `json:"nodes"` | ||
| Notifications struct { | ||
| Configured bool `json:"configured"` | ||
| Total int64 `json:"total"` | ||
| Enabled int64 `json:"enabled"` | ||
| } `json:"notifications"` | ||
| Webhooks struct { | ||
| Configured bool `json:"configured"` | ||
| Total int64 `json:"total"` | ||
| Enabled int64 `json:"enabled"` | ||
| } `json:"webhooks"` | ||
| } | ||
| require.NoError(t, json.NewDecoder(w.Body).Decode(&resp)) | ||
| assert.Equal(t, "1.2.3", resp.Version) | ||
| assert.Equal(t, "abc123", resp.Commit) | ||
| assert.True(t, resp.MCP.Enabled) | ||
| assert.True(t, resp.MCP.TokenConfigured) | ||
| assert.True(t, resp.MCP.Running) | ||
| assert.Equal(t, "openai_compat", resp.AI.Provider) | ||
| assert.True(t, resp.AI.Configured) | ||
| assert.True(t, resp.AI.Testable) | ||
| assert.True(t, resp.AI.APIKeyConfigured) | ||
| assert.Equal(t, int64(3), resp.Nodes.Total) | ||
| assert.Equal(t, int64(1), resp.Nodes.Online) | ||
| assert.Equal(t, int64(2), resp.Nodes.Offline) | ||
| assert.Equal(t, int64(1), resp.Nodes.Stale) | ||
| assert.True(t, resp.Notifications.Configured) | ||
| assert.Equal(t, int64(1), resp.Notifications.Total) | ||
| assert.Equal(t, int64(1), resp.Notifications.Enabled) | ||
| assert.True(t, resp.Webhooks.Configured) | ||
| assert.Equal(t, int64(2), resp.Webhooks.Total) | ||
| assert.Equal(t, int64(1), resp.Webhooks.Enabled) | ||
| assert.False(t, strings.Contains(body, "127.0.0.1:1")) | ||
|
Comment on lines
+179
to
+193
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Confirm the default value of mode returned by getAISettings.
rg -nP --type=go -C12 'func getAISettings'
# Confirm nodeOfflineAfter, which the stale-node assertion at line 186 depends on.
rg -nP --type=go -C2 '\bnodeOfflineAfter\b\s*='Repository: maxjb-xyz/blackbox Length of output: 156 🏁 Script executed: #!/bin/bash
set -u
printf 'Tracked files matching health_test.go:\n'
git ls-files | rg '(^|/)health_test\.go$' || true
printf '\nSearch for getAISettings:\n'
rg -n --type=go 'getAISettings|nodeOfflineAfter|ai_mode|mode' . || true
printf '\nLocate files around likely paths:\n'
fd -a 'setup\.go|handlers|health' . | sed 's#^\./##' | head -80Repository: maxjb-xyz/blackbox Length of output: 50375 🏁 Script executed: #!/bin/bash
set -u
printf 'health_test.go relevant lines:\n'
sed -n '1,220p' server/internal/handlers/health_test.go
printf '\nsetup.go relevant lines:\n'
sed -n '130,165p' server/internal/handlers/setup.go
printf '\nadmin_config.go relevant lines:\n'
sed -n '420,545p' server/internal/handlers/admin_config.go
printf '\nimports in health_test.go:\n'
sed -n '1,20p' server/internal/handlers/health_test.goRepository: maxjb-xyz/blackbox Length of output: 12787 Assert
🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| func setRegistryProvider(t *testing.T, registry *auth.OIDCRegistry, id string, provider *auth.OIDCProvider) { | ||
| t.Helper() | ||
| registry.SetProvider(id, provider) | ||
|
|
||
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.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Document the 503 response.
The
responsesblock lists only"200". The handler returns503when the database probe fails. Seeserver/internal/handlers/setup.goline 105. Generated clients and the container health check both depend on that path.The 503 body uses the same schema, with
databaseset toerrorand the remaining sections at zero values.📝 Proposed addition
enabled: type: integer + "503": + description: Database unavailable. The body uses the 200 schema with `database` set to `error`; the remaining sections contain zero values. + content: + application/json: + schema: + type: objectPlace it after line 532, aligned with the
"200"key.🤖 Prompt for AI Agents