fix: add componentUid and projectUid filters for alert rule SQL and update required fields in request body#58
Conversation
…pdate required fields in request body Signed-off-by: Nilushan Costa <nilushan@wso2.com>
📝 WalkthroughWalkthroughThe chart version is bumped from 0.4.0 to 0.4.1 across metadata and documentation. Alert parameter construction in handlers is refactored to use struct literal syntax, and SQL alert queries are enhanced with environment and component UID filters. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
observability-logs-openobserve/internal/handlers_test.go (2)
751-760: Consider populating UIDs in update success test.Similar to the create test,
TestUpdateAlertRule_Successdoesn't set any UID fields. For consistency with the "all fields required" contract, consider populatingProjectUid,EnvironmentUid, andComponentUid.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@observability-logs-openobserve/internal/handlers_test.go` around lines 751 - 760, The TestUpdateAlertRule_Success test's Metadata literal omits UID fields; update the Metadata struct in TestUpdateAlertRule_Success to populate ProjectUid, EnvironmentUid, and ComponentUid with valid openapi_types.UUID values (matching the create test pattern) so the "all fields required" contract is satisfied; locate the Metadata block within TestUpdateAlertRule_Success and assign non-empty UUIDs to ProjectUid, EnvironmentUid, and ComponentUid.
559-575:ProjectUidnot set in success test.In
TestCreateAlertRule_Success,envUIDandcompUIDare correctly initialized and assigned, butProjectUidis left as a zero-value UUID. While this works functionally, consider settingProjectUidfor consistency with real-world usage where all fields are required:+ projUID, _ := parseUUID("550e8400-e29b-41d4-a716-446655440000") envUID, _ := parseUUID("550e8400-e29b-41d4-a716-446655440001") compUID, _ := parseUUID("550e8400-e29b-41d4-a716-446655440002") ... Name: "test-alert", Namespace: "ns-1", + ProjectUid: projUID, EnvironmentUid: envUID, ComponentUid: compUID,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@observability-logs-openobserve/internal/handlers_test.go` around lines 559 - 575, The test TestCreateAlertRule_Success leaves ProjectUid as a zero UUID; update the test to initialize a project UID (e.g., call parseUUID like envUID/compUID) and assign it to the ProjectUid field in the AlertRuleRequest metadata so metadata.ProjectUid is a realistic non-zero value when calling handler.CreateAlertRule (look for parseUUID usage and the AlertRuleRequest.Metadata struct in this test).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@observability-logs-openobserve/internal/handlers_test.go`:
- Around line 751-760: The TestUpdateAlertRule_Success test's Metadata literal
omits UID fields; update the Metadata struct in TestUpdateAlertRule_Success to
populate ProjectUid, EnvironmentUid, and ComponentUid with valid
openapi_types.UUID values (matching the create test pattern) so the "all fields
required" contract is satisfied; locate the Metadata block within
TestUpdateAlertRule_Success and assign non-empty UUIDs to ProjectUid,
EnvironmentUid, and ComponentUid.
- Around line 559-575: The test TestCreateAlertRule_Success leaves ProjectUid as
a zero UUID; update the test to initialize a project UID (e.g., call parseUUID
like envUID/compUID) and assign it to the ProjectUid field in the
AlertRuleRequest metadata so metadata.ProjectUid is a realistic non-zero value
when calling handler.CreateAlertRule (look for parseUUID usage and the
AlertRuleRequest.Metadata struct in this test).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2860e735-f5a4-4244-8a16-f3d932547851
⛔ Files ignored due to path filters (2)
observability-logs-openobserve/internal/api/gen/models.gen.gois excluded by!**/gen/**observability-logs-openobserve/internal/api/gen/server.gen.gois excluded by!**/gen/**
📒 Files selected for processing (6)
observability-logs-openobserve/README.mdobservability-logs-openobserve/helm/Chart.yamlobservability-logs-openobserve/internal/handlers.goobservability-logs-openobserve/internal/handlers_test.goobservability-logs-openobserve/internal/openobserve/queries.goobservability-logs-openobserve/internal/openobserve/queries_test.go
Purpose
openchoreo/openchoreo#2859
Log-based alerts created in the observability-logs-openobserve module match log entries from any component and environment because the generated OpenObserve SQL query only filters by the search pattern, without scoping to a specific environment or component.
Goals
Approach
Summary by CodeRabbit
Release
Improvements