Conversation
6d140f5 to
fde3627
Compare
f5e6e8f to
85a72e4
Compare
|
Reopening the original PR after closing the new one the contributor had opened. Please see this guide on contributing to projects: https://docs.github.com/en/get-started/exploring-projects-on-github/contributing-to-open-source#working-with-project-maintainers
|
|
@siavashs Thank you for your valuable feedback on the previous attempts. I have addressed all the concerns: Changes Made1. Fixed Code Generation (Copyright Headers)
2. Consistent Messages in Logs and API
message := "Failed to compile receiver regex"
logger.Debug(message, "err", err)
eb := badRequestError(message, err)3. Prometheus v1 Error Format (Addressing Breaking Change Concern)To address the concern about breaking existing integrations, I've aligned the error format with Prometheus API v1: {
"status": "error",
"errorType": "bad_data",
"error": "Failed to parse matchers: bad matcher format: invalidfilter"
}Why this is the right approach:
I would appreciate your feedback on whether this Prometheus v1 format approach is acceptable. If you prefer a different approach (e.g., adding versioning or Accept header negotiation), please let me know and I can implement that instead. Thank you for your time and guidance! |
294c0e8 to
c56a0f6
Compare
|
@siavashs I have rebased on the latest upstream/main and addressed all the feedback from the previous review: Changes Made1. Fixed Code Generation (Copyright Headers) ✅
2. Consistent Messages in Logs and API ✅
message := "Failed to compile receiver regex"
logger.Debug(message, "err", err)
eb := badRequestError(message, err)3. Prometheus v1 Error Format ✅Aligned error format with Prometheus API v1: {
"status": "error",
"errorType": "bad_data",
"error": "Failed to parse matchers: bad matcher format: invalidfilter"
}Rationale:
4. Rebased on Latest Upstream ✅
I would appreciate your feedback on this approach. Thank you for your time and guidance! |
- Update openapi.yaml error responses to use Prometheus v1 format:
{status: 'error', errorType: string, error: string}
- Regenerate API code using make apiv2 with proper copyright headers
- Update all error handlers in api.go to use consistent messages
in logs and API responses (per reviewer feedback)
- Add helper functions badRequestError() and internalError()
Example error response:
{
"status": "error",
"errorType": "bad_data",
"error": "Failed to parse matchers: bad matcher format"
}
This aligns Alertmanager API with Prometheus API v1 error format
for ecosystem consistency.
Signed-off-by: mehrdadbn9 <mehrdabbiukian@gmail.com>
c56a0f6 to
6a9ab5d
Compare
Fix #4973: Return JSON error responses instead of plain text
Problem
The Alertmanager API was returning error responses as plain text strings with incorrect Content-Type header:
application/json"bad matcher format: invalidfilter"(plain text string)This violates the JSON API specification as the response body is a quoted string, not a JSON object.
Solution
Updated the API to return proper JSON error responses with an
errorfield:application/json{"error":"bad matcher format: invalidfilter"}(valid JSON object)Changes Made
OpenAPI Spec (
api/v2/openapi.yaml)type: stringto JSON objects witherrorfieldSwagger Code Generation
GetAlertsBadRequestBody,GetAlertsInternalServerErrorBodyGetAlertGroupsBadRequestBody,GetAlertGroupsInternalServerErrorBodyGetSilencesBadRequestBody,GetSilencesInternalServerErrorBodyGetSilenceInternalServerErrorBodyDeleteSilenceInternalServerErrorBodyPostAlertsBadRequestBody,PostAlertsInternalServerErrorBodyPostSilencesBadRequestBodyAPI Handlers (
api/v2/api.go)Example
Before