Validate api_type matches path in ClusterMetricsInput#912
Conversation
When creating a cluster metrics monitor, the api_type field was silently ignored during deserialization. This allowed creating monitors with mismatched api_type and path fields, which then could not be deleted via the DeleteMonitor API. Added validation in parseInner to reject requests where the provided api_type does not match the API derived from the path. Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com> Resolves opensearch-project/alerting#1987 Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com>
|
Code change looks good to me. In your failure case example above, user passes in |
│ Good catch on the wording — there's no silent change or fallback happening. The api_type field was never parsed in parseInner(), so the user-provided value is ignored entirely. The |
When creating a cluster metrics monitor, the api_type field was silently ignored during deserialization. This allowed creating monitors with mismatched api_type and path fields, which then could not be deleted via the DeleteMonitor API. Added validation in parseInner to reject requests where the provided api_type does not match the API derived from the path. Resolves opensearch-project/alerting#1987 Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com> Co-authored-by: Manaswini Ragamouni <ragamanu@amazon.com> (cherry picked from commit 5103490) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
When creating a cluster metrics monitor, the api_type field was silently ignored during deserialization. This allowed creating monitors with mismatched api_type and path fields, which then could not be deleted via the DeleteMonitor API. Added validation in parseInner to reject requests where the provided api_type does not match the API derived from the path. Resolves opensearch-project/alerting#1987 (cherry picked from commit 5103490) Signed-off-by: Manaswini Ragamouni <ragamanu@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Manaswini Ragamouni <ragamanu@amazon.com>
Description
When creating a cluster metrics monitor, the
api_typefield was never parsed inClusterMetricsInput.parseInner()— the user-provided value is ignored entirely. TheclusterMetricTypeis always derived from thepathviafindApiType(constructedUri. path)in theinitblock. This allowed creating monitors with mismatchedapi_typeandpathfields (e.g., user sendsapi_type: CLUSTER_STATSwithpath: /_cat/indices, butCAT_INDICESis derived from the path). These malformed monitors could not be deleted via the DeleteMonitor API, failing with "The provided URL and URI fields form different URLs."
Added validation in
parseInnerto parse theapi_typefield and reject requests where the providedapi_typedoes not match the type derived from thepath.Testing
Before fix — monitor created successfully. User-provided
api_typeis ignored, type is derived frompathinstead:json
After fix — monitor creation rejected with clear error:
json
Related Issues
Resolves opensearch-project/alerting#1987
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.