Skip to content

Fix MQE top_n raising a raw storage IO exception for an invalid attribute condition#13940

Merged
wu-sheng merged 1 commit into
masterfrom
fix/mqe-topn-attribute-validation
Jul 7, 2026
Merged

Fix MQE top_n raising a raw storage IO exception for an invalid attribute condition#13940
wu-sheng merged 1 commit into
masterfrom
fix/mqe-topn-attribute-validation

Conversation

@wu-sheng

@wu-sheng wu-sheng commented Jul 7, 2026

Copy link
Copy Markdown
Member

Fix top_n(metric, N, order, attrX='value') returning a raw storage IOException when the attribute is not a column of the metric

  • Add a unit test to verify that the fix works.
  • Explain briefly why the bug exists and how to fix it.

Why the bug exists. An MQE top_n(...) query accepts attribute conditions (e.g. attr0='VIRTUAL_DATABASE', attr0!='MESH'). These attr0..attrN columns exist only on decorated metrics — service_* / endpoint_* / kubernetes_service_*, where OAL .decorator("ServiceDecorator"/"EndpointDecorator"/"K8SServiceDecorator") sets attr0 to the entity's layer — plus the MAL Meter base class. Metrics whose source declares no attribute columns (service/instance/endpoint relations, and database_access_* / cache_* / mq_* virtual-access metrics) carry no attr0 tag at all.

When such an attribute condition is passed for one of those metrics, nothing validated it before the storage call: MQEVisitor.querySortMetricsAggregationQueryService.sortMetrics → the storage DAO builds a query filtering on a tag the measure does not define, and the backend fails. On BanyanDB the BanyanDBException is wrapped as IOException, which MQEVisitor flattens into the opaque, non-actionable "Internal IO exception, query metrics error." — indistinguishable from a genuine I/O fault. A well-formed MQE should never surface a storage I/O exception.

How it's fixed. MQEVisitor.checkAttributes(...) now runs before the storage call and validates each attribute key against the metric's registered queryable columns (via IModelManager). If the attribute is not a column of the metric it raises IllegalExpressionException naming the attribute and the metric, which the existing catch in visitMetric turns into a descriptive ExpressionResult error (the same graceful path already used for "metric does not exist", "TopN value must be > 0", etc.). Decorated metrics and empty attribute lists are unaffected; the check is on the attribute key, so = and != conditions are both covered.

The guard lives only in MQEVisitor because MQE is the sole caller that populates TopNCondition.attributes (PromQL's buildTopNCondition never sets them; the GraphQL TopNCondition input does not expose attributes).

Unit test: MQEVisitorAttributeTest (4 cases — reject =/!= on a no-attr metric, allow a valid attribute, allow empty attributes).

…bute

An MQE top_n(metric, N, order, attrX='value') whose attribute is not a queryable
column of the metric reached the storage engine with a tag the measure does not
define and failed there, surfacing the opaque "Internal IO exception, query
metrics error.". Attribute columns (attr0..attrN) exist only on decorated metrics
(service_*/endpoint_*/kubernetes_service_*, set to the layer via OAL .decorator())
and the MAL meter base; relations and database/cache/mq access carry none.

MQEVisitor now validates each attribute key against the metric's registered
queryable columns before the storage call and raises IllegalExpressionException
(naming the attribute and metric), which the existing catch turns into a
descriptive MQE error instead of the opaque storage exception.
@wu-sheng wu-sheng added this to the 11.0.0 milestone Jul 7, 2026
@wu-sheng wu-sheng added bug Something isn't working and you are sure it's a bug! backend OAP backend related. labels Jul 7, 2026
@wu-sheng wu-sheng requested review from Copilot and wankai123 July 7, 2026 11:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds an MQE-side validation guard for top_n(..., attrX='value') so invalid attribute conditions (attributes not present as queryable columns on the target metric) fail fast with a descriptive MQE error rather than propagating a backend IOException.

Changes:

  • Add MQEVisitor.checkAttributes(...) and invoke it before executing top_n storage queries to validate attribute keys against the metric model schema.
  • Add unit tests covering rejecting =/!= for no-attribute metrics, allowing valid attributes, and allowing empty attribute lists.
  • Document the fix in the CHANGES log.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/mqe/rt/MQEVisitor.java Adds schema-based attribute validation prior to top_n storage execution to prevent raw backend IO errors.
oap-server/server-query-plugin/query-graphql-plugin/src/test/java/org/apache/skywalking/oap/query/graphql/mqe/rt/MQEVisitorAttributeTest.java Adds unit tests verifying the new attribute validation behavior.
docs/en/changes/changes.md Records the MQE top_n attribute validation fix in release notes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@wu-sheng wu-sheng merged commit 432d55f into master Jul 7, 2026
439 of 446 checks passed
@wu-sheng wu-sheng deleted the fix/mqe-topn-attribute-validation branch July 7, 2026 12:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend OAP backend related. bug Something isn't working and you are sure it's a bug!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants