Skip to content

Introduced includeTrailerHeader to enable TrailerHeaders in response#16672

Merged
abhishekagarwal87 merged 11 commits intoapache:masterfrom
deep-bi:deep/feature/trailer-headers-to-indicate-truncated-results
Sep 21, 2024
Merged

Introduced includeTrailerHeader to enable TrailerHeaders in response#16672
abhishekagarwal87 merged 11 commits intoapache:masterfrom
deep-bi:deep/feature/trailer-headers-to-indicate-truncated-results

Conversation

@vivek807
Copy link
Copy Markdown
Contributor

@vivek807 vivek807 commented Jun 28, 2024

Introduced includeTrailerHeader to enable TrailerHeaders in response
If enabled, a header X-Error-Message will be added to indicate reasons for partial results.

Description

Currently, when requesting large amounts of data, the result may be truncated due to query timeouts or other issues. To address this, we are using a non-standard solution.

    // Terminate the last output line, then write an extra blank line, so users can tell the response was not cut off.
    outputStream.write(new byte[]{'\n', '\n'});

To handle this in a standard way, we can implement a trailer header that indicates partial results and the reason for the truncation.

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

…nse.

If enabled, a header `X-Error-Message` will be added to indicate partial results.
@abhishekagarwal87
Copy link
Copy Markdown
Contributor

You may want to look into an old PR of mine (now stale) - #13492 - The solution in the PR stopped working after query resources were refactored and I didn't get the time to dig into the reason. But given you are in this area, maybe you can explore that patch.

@vivek807
Copy link
Copy Markdown
Contributor Author

vivek807 commented Jul 2, 2024

You may want to look into an old PR of mine (now stale) - #13492 - The solution in the PR stopped working after query resources were refactored and I didn't get the time to dig into the reason. But given you are in this area, maybe you can explore that patch.

Thanks @abhishekagarwal87 for your comment.
We added a trailer header to indicate truncated results when fetching large amounts of data. For instance, if a query times out after streaming some results, the count and the actual result may mismatch. To signal this, we included an error message in the trailer header to indicate the reason for truncated results, which can be enabled in query context

@nozjkoitop
Copy link
Copy Markdown
Contributor

Hi @abhishekagarwal87,

While it's not straightforward to resolve the query result truncation issue, this solution is aimed at highlighting when results are truncated and helping to identify the reason. The rationale is pretty legit - we don't want to truncate the query results silently.

@vivek807, could you please revert the formatting changes in the documentation?

@vivek807
Copy link
Copy Markdown
Contributor Author

vivek807 commented Aug 4, 2024

Hi @abhishekagarwal87,

While it's not straightforward to resolve the query result truncation issue, this solution is aimed at highlighting when results are truncated and helping to identify the reason. The rationale is pretty legit - we don't want to truncate the query results silently.

@vivek807, could you please revert the formatting changes in the documentation?

Updated, thanks @nozjkoitop

Copy link
Copy Markdown
Contributor

@abhishekagarwal87 abhishekagarwal87 left a comment

Choose a reason for hiding this comment

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

thanks. I have some comments and yet to go over the test code. Is the test code based on some existing tests?

Comment thread docs/querying/query-context.md Outdated
Comment thread server/src/main/java/org/apache/druid/server/QueryResultPusher.java Outdated
Comment thread server/src/main/java/org/apache/druid/server/QueryResultPusher.java Outdated
Updated docs and unit tests.
Comment thread server/src/main/java/org/apache/druid/server/QueryResultPusher.java
Comment thread server/src/main/java/org/apache/druid/server/QueryResultPusher.java Outdated
…ler-headers-to-indicate-truncated-results

# Conflicts:
#	server/src/test/java/org/apache/druid/server/QueryResourceTest.java
@abhishekagarwal87 abhishekagarwal87 merged commit df680ba into apache:master Sep 21, 2024
@adarshsanjeev
Copy link
Copy Markdown
Contributor

adarshsanjeev commented Oct 8, 2024

@vivek807 I was trying out this change. I was able to see this header only if I was directly hitting the broker. Hitting the router (that is, localhost:8888 if you run it locally) does not add the header. Have you seen this behaviors as well?

@vivek807
Copy link
Copy Markdown
Contributor Author

vivek807 commented Dec 7, 2024

@vivek807 I was trying out this change. I was able to see this header only if I was directly hitting the broker. Hitting the router (that is, localhost:8888 if you run it locally) does not add the header. Have you seen this behaviors as well?

@adarshsanjeev, Apologies for the delayed response—I somehow missed your comment. After a quick review, it appears that Jetty’s AsyncProxyServlet does not inherently support forwarding trailers in the HTTP/1.1 or HTTP/2 Trailer field. I’ll investigate further to see if this can be addressed.

@adarshsanjeev adarshsanjeev added this to the 32.0.0 milestone Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants