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

SNOW-1357377 Add request Id in all streaming ingest APIs #759

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,23 @@ public HttpGet generateHistoryRangeRequest(
*/
public HttpPost generateStreamingIngestPostRequest(
String payload, String endPoint, String message) {
LOGGER.debug("Generate Snowpipe streaming request: endpoint={}, payload={}", endPoint, payload);
final String requestId = UUID.randomUUID().toString();
Copy link
Contributor

Choose a reason for hiding this comment

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

My assumption is that the request id will remain the same with retry?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thats true!

LOGGER.debug(
"Generate Snowpipe streaming request: endpoint={}, payload={}, requestId={}",
endPoint,
payload,
requestId);
// Make the corresponding URI
URI uri = null;
try {
uri =
new URIBuilder().setScheme(scheme).setHost(host).setPort(port).setPath(endPoint).build();
new URIBuilder()
.setScheme(scheme)
.setHost(host)
.setPort(port)
.setPath(endPoint)
.setParameter(REQUEST_ID, requestId)
.build();
} catch (URISyntaxException e) {
throw new SFException(e, ErrorCode.BUILD_REQUEST_FAILURE, message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ ChannelsStatusResponse getChannelsStatus(
.collect(Collectors.toList());
request.setChannels(requestDTOs);
request.setRole(this.role);
request.setRequestId(this.flushService.getClientPrefix() + "_" + counter.getAndIncrement());
Copy link
Contributor

Choose a reason for hiding this comment

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

We should remove request_id in the request as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you mean in the POJO?

Copy link
Contributor

@sfc-gh-tzhang sfc-gh-tzhang Jun 12, 2024

Choose a reason for hiding this comment

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

Yes, in the request class


String payload = objectMapper.writeValueAsString(request);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package net.snowflake.ingest.streaming.internal;

import static java.time.ZoneOffset.UTC;
import static net.snowflake.ingest.utils.Constants.ACCOUNT_URL;
import static net.snowflake.ingest.utils.Constants.OPEN_CHANNEL_ENDPOINT;
import static net.snowflake.ingest.utils.Constants.PRIVATE_KEY;
import static net.snowflake.ingest.utils.Constants.RESPONSE_SUCCESS;
import static net.snowflake.ingest.utils.Constants.ROLE;
import static net.snowflake.ingest.utils.Constants.USER;
import static net.snowflake.ingest.utils.Constants.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

no star import

import static org.mockito.ArgumentMatchers.argThat;

import java.security.KeyPair;
Expand Down Expand Up @@ -313,8 +308,14 @@ public void testOpenChannelPostRequest() throws Exception {
requestBuilder.generateStreamingIngestPostRequest(
payload, OPEN_CHANNEL_ENDPOINT, "open channel");

Assert.assertEquals(
String.format("%s%s", urlStr, OPEN_CHANNEL_ENDPOINT), request.getRequestLine().getUri());
String expectedUrlPattern =
String.format("%s%s", urlStr, OPEN_CHANNEL_ENDPOINT) + "(\\?requestId=[a-f0-9\\-]{36})?";

Assert.assertTrue(
String.format(
"Expected URL to match pattern: %s but was: %s",
expectedUrlPattern, request.getRequestLine().getUri()),
request.getRequestLine().getUri().matches(expectedUrlPattern));
Assert.assertNotNull(request.getFirstHeader(HttpHeaders.USER_AGENT));
Assert.assertNotNull(request.getFirstHeader(HttpHeaders.AUTHORIZATION));
Assert.assertEquals("POST", request.getMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,6 @@ public void testGetChannelsStatusWithRequest() throws Exception {
ChannelsStatusRequest.ChannelStatusRequestDTO dto =
new ChannelsStatusRequest.ChannelStatusRequestDTO(channel);
ChannelsStatusRequest request = new ChannelsStatusRequest();
request.setRequestId("null_0");
request.setChannels(Collections.singletonList(dto));
ChannelsStatusResponse result = client.getChannelsStatus(Collections.singletonList(channel));
Assert.assertEquals(response.getMessage(), result.getMessage());
Expand Down Expand Up @@ -547,9 +546,15 @@ public void testRegisterBlobRequestCreationSuccess() throws Exception {
HttpPost request =
requestBuilder.generateStreamingIngestPostRequest(
payload, REGISTER_BLOB_ENDPOINT, "register blob");
String expectedUrlPattern =
String.format("%s%s", urlStr, REGISTER_BLOB_ENDPOINT) + "(\\?requestId=[a-f0-9\\-]{36})?";

Assert.assertTrue(
String.format(
"Expected URL to match pattern: %s but was: %s",
expectedUrlPattern, request.getRequestLine().getUri()),
request.getRequestLine().getUri().matches(expectedUrlPattern));

Assert.assertEquals(
String.format("%s%s", urlStr, REGISTER_BLOB_ENDPOINT), request.getRequestLine().getUri());
Assert.assertNotNull(request.getFirstHeader(HttpHeaders.USER_AGENT));
Assert.assertNotNull(request.getFirstHeader(HttpHeaders.AUTHORIZATION));
Assert.assertEquals("POST", request.getMethod());
Expand Down Expand Up @@ -1432,7 +1437,6 @@ public void testGetLatestCommittedOffsetTokens() throws Exception {
ChannelsStatusRequest.ChannelStatusRequestDTO dto =
new ChannelsStatusRequest.ChannelStatusRequestDTO(channel);
ChannelsStatusRequest request = new ChannelsStatusRequest();
request.setRequestId("null_0");
request.setChannels(Collections.singletonList(dto));
Map<String, String> result =
client.getLatestCommittedOffsetTokens(Collections.singletonList(channel));
Expand Down
Loading