Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add stream pull queries to websocket endpoint #8143

Merged
merged 1 commit into from
Sep 22, 2021

Conversation

vvcephei
Copy link
Member

Finishing out the stream pull query implementation cycle, this adds support
to the websocket endpoint, building on the HTTP/1 and HTTP/2 endpoints.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@vvcephei vvcephei requested a review from a team as a code owner September 16, 2021 20:04
@vvcephei vvcephei self-assigned this Sep 16, 2021
Comment on lines -317 to -322
/**
* Unlike the other queries, stream pull queries are split into create and wait because the three
* API endpoints all need to do different stuff before, in the middle of, and after these two
* phases. One of them actually needs to wait on the pull query in a callback after starting the
* query, so splitting it into two method calls was the most practical choice.
*/
Copy link
Member Author

Choose a reason for hiding this comment

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

I just noticed that this comment has become incorrect.

@@ -133,6 +133,7 @@ public synchronized void subscribe(final Flow.Subscriber<Collection<StreamedRow>
this.queryMetadata = requireNonNull(queryMetadata, "queryMetadata");

queryMetadata.setLimitHandler(this::setDone);
queryMetadata.setCompletionHandler(this::setDone);
Copy link
Member Author

Choose a reason for hiding this comment

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

Hooking in to the new completion callback. It looks like, similar to the HTTP/2 endpoint, limit queries don't print "limit reached", but unlike the HTTP/2 they actually do print "done" instead of just stopping.

It doesn't seem good that we managed to come up with three different ways to indicate the completion of a query in our three different query endpoints... But it's out of scope for this PR.

Comment on lines +301 to +324
final StreamPullQueryMetadata queryMetadata =
ksqlEngine.createStreamPullQuery(
info.securityContext.getServiceContext(),
analysis,
configured,
true
);

localCommands.ifPresent(lc -> lc.write(queryMetadata.getTransientQueryMetadata()));

final PushQuerySubscription subscription =
new PushQuerySubscription(exec,
streamSubscriber,
queryMetadata.getTransientQueryMetadata()
);

log.info(
"Running query {}",
queryMetadata.getTransientQueryMetadata().getQueryId().toString()
);
queryMetadata.getTransientQueryMetadata().start();

streamSubscriber.onSubscribe(subscription);
return;
Copy link
Member Author

Choose a reason for hiding this comment

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

The main part of the implementation. It's very similar to the HTTP/2 implementation.

Copy link
Member

Choose a reason for hiding this comment

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

I have been looking in the code and it seems we don't have a PushQueryPublisherTest like we do for PullQueryPublisherTest. Shouldn't we have one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I noticed that, too. We could add one, but I didn't bother because the publisher is already covered by other tests, and the pull query publisher test looked of dubious value to me.

@@ -344,6 +347,36 @@ public void shouldExecutePushQueryThatReturnsStreamOverWebSocketWithJsonContentT
));
}

@Test
public void shouldExecutePullQueryThatReturnsStreamOverWebSocketWithJsonContentType() {
Copy link
Member Author

Choose a reason for hiding this comment

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

Almost all the code is tested in the other endpoints, so we just have a quick smoke test here.

In the future, I hope we can refactor RQTT into a functional test suite that runs against all the endpoints.

@vvcephei vvcephei force-pushed the add-stream-pull-queries-to-websocket branch from a3d582e to 6291a71 Compare September 20, 2021 14:31
@vvcephei vvcephei changed the base branch from ws-base to master September 20, 2021 14:32
Copy link
Member

@vpapavas vpapavas left a comment

Choose a reason for hiding this comment

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

Thank you @vvcephei! It would be nice to have a PushQueryPublisherTest like we do for pull queries but it's up to you if you want to do that since it's outside the scope of this PR

@vvcephei vvcephei merged commit 57626f3 into master Sep 22, 2021
@vvcephei vvcephei deleted the add-stream-pull-queries-to-websocket branch September 22, 2021 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants