[Bug] JDBC trace profiling query fails with SQL syntax error when the segment list is empty

Open Beginner friendly
#14,239 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java, mariadb, sql

Research direction

Start with JDBCTraceQueryDAO.queryBySegmentIdList in the stack trace and trace how ProfileTaskQueryService.getTaskSegments passes the segment IDs. Check the JDBC DAO tests for a place to add an empty collection regression case. Done means a task with no sampled segments returns an empty list without producing invalid SQL.

Written by the indexing model from the issue text.

Description

bug
Search before asking
  • I had searched in the issues and found no similar issues.
Apache SkyWalking Component

OAP server (apache/skywalking)

What happened

Opening trace profiling results for a task with no collected calls fails with a MariaDB SQL syntax error at GraphQL /segmentList. Locally, the failure occurs when there are no collected calls.

Environment

  • OAP image: apache/skywalking-oap-server:11.1.0
  • Horizon image: ghcr.io/apache/skywalking-horizon-ui:1.1.0
  • Storage: MariaDB, SW_STORAGE=mysql
  • MySQL Connector/J: 8.4.0
What you expected to happen

A profiling task with no sampled segments should return an empty list, allowing the UI to display no data, without executing invalid SQL.

How to reproduce
  1. Run OAP with JDBC/MySQL storage backed by MariaDB.
  2. Create a trace profiling task for an instrumented service.
  3. Do not generate matching calls / collected profiling segments.
  4. Open the task segment list in Horizon Trace Profiling (GraphQL getProfileTaskSegments).
  5. Observe the SQLSyntaxErrorException at /segmentList.
Anything else

Observed OAP stack trace

Exception while fetching data (/segmentList): java.sql.SQLSyntaxErrorException:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version
for the right syntax to use near ')' at line 1

at org.apache.skywalking.oap.server.library.client.jdbc.hikaricp.JDBCClient.executeQuery(JDBCClient.java:118)
at org.apache.skywalking.oap.server.storage.plugin.jdbc.common.dao.JDBCTraceQueryDAO.queryBySegmentIdList(JDBCTraceQueryDAO.java:265)
at org.apache.skywalking.oap.server.core.profiling.trace.ProfileTaskQueryService.getTaskSegments(ProfileTaskQueryService.java:202)
at org.apache.skywalking.oap.server.core.profiling.trace.ProfileTaskQueryService.getProfileTaskSegments(ProfileTaskQueryService.java:207)
at org.apache.skywalking.oap.query.graphql.resolver.ProfileQuery.lambda$getProfileTaskSegments$2(ProfileQuery.java:66)

Suspected cause: an empty segment ID collection reaches queryBySegmentIdList and produces an empty IN () predicate. The full generated SQL was not captured, so this SQL shape is an inference from the trigger and stack trace. Please check empty-list handling and add an empty-collection regression test.

Searched existing issues for segmentList + syntax and queryBySegmentIdList + empty. #14172 concerns profiling records disappearing with BanyanDB; this report concerns a JDBC/MariaDB syntax error. No local OAP code modification has been applied.

Are you willing to submit a pull request to fix on your own?
  • Yes I am willing to submit a pull request on my own!
Code of Conduct
Dominant language
Java
Stars
25k
Forks
6.6k
Avg merge
12h 1m
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/skywalking

All issues in apache/skywalking

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.