Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add HTTP API Server for Querying Events and Hooks
Summary
This PR implements a minimal read-only HTTP API server that provides RESTful endpoints for querying events, hooks, statistics, and health information. This addresses the feedback from PR #9 by implementing a generic API server that shares the same data sources as the event processor and create base line of future REST capabilities..
Context
This PR is a refactored implementation based on feedback from PR #9. Key changes from the original approach:
AgentRefinstead ofAgentId- Aligned with kagent standardsinterface{}typesChanges
Not applicable to this PR
Severity handling — I kept a default severity mapping function for the statistics endpoint (/api/v1/stats/events/summary) to provide severity breakdowns. Making it configurable requires adding a severity field to the EventConfiguration CRD schema, which is outside this PR’s scope (API server only). The current default mapping (oom-kill/node-not-ready → "critical", probe-failed/pod-restart → "warning", pod-pending → "info") need to be replaced in a future PR's that adds the optional severity field to the Hook CRD, allowing teams to customize per event type while falling back to defaults when not specified.
NotificationSuppressionDuration — Not part of API server scope (deduplication manager concern)
Database/Postgres — Using in-memory managers (appropriate for this scope)
New Components
internal/apiserver/- Complete API server implementationserver.go- Main server, routing, and middleware (228 lines)events.go- Event query and streaming handlers (228 lines)hooks.go- Hook configuration handlers (77 lines)health.go- Health, diagnostics, and metrics handlers (162 lines)stats.go- Event statistics handlers (179 lines)json.go- JSON encoding utilities (14 lines)swagger.go- Swagger/OpenAPI documentation (30 lines)test/server_test.go- Comprehensive unit tests (334 lines, 58% coverage)Modified Components
cmd/main.go- Integrated API server startup with shared managersinternal/config/config.go- AddedAPIServerPortconfigurationinternal/interfaces/controller.go- AddedGetAllHookNames()andGetEventCount()methodsinternal/workflow/coordinator.go- Updated to accept shared managers viaNewCoordinatorWithManagers()API Endpoints
Health & Diagnostics
GET /api/v1/health- Health check endpointGET /api/v1/diagnostics- Detailed diagnostics (memory, connections, event stats)GET /api/v1/metrics- Prometheus-style metricsEvents
GET /api/v1/events- List events with optional filteringnamespace,eventType,resourceName,statusGET /api/v1/events/stream- Server-Sent Events stream for real-time updatesHooks
GET /api/v1/hooks- List all Hook configurationsStatistics
GET /api/v1/stats/events/summary- Event summary with counts by severity and typeGET /api/v1/stats/events/by-type- Events grouped by type with percentagesDocumentation
GET /swagger/index.html- Swagger UIGET /swagger/doc.json- OpenAPI specificationDocumentation
/swagger/index.htmlBreaking Changes
None. This is a purely additive change.
Checklist
AgentRefthroughoutinterface{})Related