fix: Prevent InvalidTypeIdException when Prometheus metric has 'type'… - #5696
fix: Prevent InvalidTypeIdException when Prometheus metric has 'type'…#5696nagendramohan wants to merge 2 commits into
Conversation
… label Add @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) on PrometheusResult to override the parent DataSourceResult interface's polymorphic type handling. This prevents Jackson from interpreting a metric label named 'type' as the polymorphic type discriminator, which caused InvalidTypeIdException during deserialization. The type dispatch is already handled explicitly via switch statement in ExecuteDirectQueryActionResponse, so polymorphic type annotations are not needed on the concrete class. Resolves opensearch-project#5684 Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
PR Reviewer Guide 🔍(Review updated until commit 08faca3)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 08faca3 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 48e4732
Suggestions up to commit 2b5e994
|
|
Friendly ping — this fixes a crash when Prometheus metrics contain a field named type (issue #5684). Small change: one annotation + regression test. Happy to address any feedback. |
Code review — findingsThe fix (adding 1. Transport round-trip becomes asymmetric across mixed-version nodes (correctness). Scope: one-directional (new→old only; old→new is fine since 2. The fix leaves the polymorphism/injection machinery as dead code. 3. The 4. Test coverage gap. The new regression test exercises only the raw-string constructor → 5. Nit: the test file still ends without a trailing newline ( |
|
Persistent review updated to latest commit 48e4732 |
|
Thanks for the thorough review @lezzago — the breakdown was really helpful. I ended up taking your suggestion in #2 and reworking the fix rather than layering Id.NONE on top of the existing machinery. The new commit removes the polymorphism scaffolding entirely:
The reason this is safe: the concrete result type is already carried as the separate dataSourceType string and dispatched via the switch in both For #4, I added a writeTo() → StreamInput round-trip test (testStreamSerializationPreservesTypeMetricLabel) that carries a metric label literally named type, so the transport path is now covered directly. And #5 — ran spotlessApply. That leaves your #1, which I want to be upfront about. This does change the serialized shape (no root type in the result JSON), so there's a bounded, My read is that's an acceptable tradeoff given the experimental status, but I'd rather not make that call unilaterally. Are you comfortable with it |
The direct-query transport already carries the concrete result type as a
separate 'dataSourceType' string and dispatches on it via a switch in
both writeTo() and the StreamInput constructor. The Jackson polymorphism
on DataSourceResult (@JsonTypeInfo/@JsonSubTypes) was therefore never
exercised through the interface, and the earlier @JsonTypeInfo(Id.NONE)
workaround plus the addTypeFieldToJson()/contains("\"type\":") guard
existed only to satisfy that unused machinery -- which is what let a
Prometheus metric label named 'type' break deserialization (opensearch-project#5684).
Remove the polymorphism scaffolding entirely: drop the discriminator
annotations, read PrometheusResult directly, and delete the type
injection. Add a writeTo()->StreamInput round-trip test that carries a
metric label named 'type' to cover the transport path.
Note: this changes the serialized shape (no root 'type' in the result
JSON). Dispatch is unaffected (the separate dataSourceType string), and
the API is @opensearch.experimental, so the only impact is a bounded,
one-directional mixed-version window during a rolling upgrade.
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
48e4732 to
08faca3
Compare
|
Persistent review updated to latest commit 08faca3 |
… label
Add @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) on PrometheusResult to override the parent DataSourceResult interface's polymorphic type handling. This prevents Jackson from interpreting a metric label named 'type' as the polymorphic type discriminator, which caused InvalidTypeIdException during deserialization.
The type dispatch is already handled explicitly via switch statement in ExecuteDirectQueryActionResponse, so polymorphic type annotations are not needed on the concrete class.
Resolves #5684
Description
PromQL queries fail with
InvalidTypeIdExceptionwhen a metric contains a label namedtype. This happens because theDataSourceResultinterface uses
@JsonTypeInfo(property = "type")for polymorphic deserialization, and Jackson interprets the metric'stypelabel as thetype discriminator.
Fix: Add
@JsonTypeInfo(use = JsonTypeInfo.Id.NONE)onPrometheusResultto override the parent's polymorphic type handling. The typedispatch is already handled explicitly via switch statement in
ExecuteDirectQueryActionResponse, so annotation-based polymorphism is unnecessary on the concrete class.Includes a regression test with a metric containing
"type": "gauge"label.Related Issues
Resolves #5684
Check List
created.
--signoffor-s.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.