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

PROD-39429 PART-2 Make REST API(/channels/status) call which acts as Channel Exi… #737

Closed

Conversation

sfc-gh-japatel
Copy link
Collaborator

@sfc-gh-japatel sfc-gh-japatel commented Oct 26, 2023

…stence Checker

What

  • A skeleton code, to find out whether a Streaming Channel exists for a table.
  • This is a backdoor way to get Channel Status (If client sequencers match) and to find out if a channel exists without opening a channel or without needing to have a StreamingIngestChannel Object
  • It has a lot of repeated code from Ingest SDK.
  • We would want to move away from KC code to ingest SDK. More on that will come later SNOW-951262

Why

  • We could have always opened a new Channel, find offsetToken and assign it to oldChannel.
  • But this has a risk of opening a new channel everytime and we would want to go away from that. This could also have a lot of channels on table and we could reach a limit.
  • Doing show channels iliike '<channelName>' in table <tableName> is an expensive operation and is not optimal and also doesnt get away from opening a channel.
  • This will also help us to have our future code (PR no 3, more on it later) backward compatible.

If interested, take a look at this algorithm: (Internal employees only)

Tests

Added tests.

@sfc-gh-japatel sfc-gh-japatel changed the title PART-2 Make REST API(/channels/status) call which acts as Channel Exi… PROD-39429 PART-2 Make REST API(/channels/status) call which acts as Channel Exi… Oct 26, 2023
@sfc-gh-japatel sfc-gh-japatel changed the base branch from master to japatel-PROD-39429-revert-param-name October 26, 2023 05:54
Base automatically changed from japatel-PROD-39429-revert-param-name to master October 26, 2023 17:40
@sfc-gh-japatel sfc-gh-japatel force-pushed the japatel-PROD-39429-http-client-get-status branch from 84e089d to 638bcc3 Compare October 26, 2023 17:48
@sfc-gh-japatel sfc-gh-japatel force-pushed the japatel-PROD-39429-http-client-get-status branch from 638bcc3 to ca5b448 Compare October 26, 2023 17:49
private static final KCLogger LOGGER =
new KCLogger(StreamingChannelExistenceChecker.class.getName());

private static final String DEBUG_PREFIX = "Channel Existence Checker - Kafka Connector";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
private static final String DEBUG_PREFIX = "Channel Existence Checker - Kafka Connector";
private static final String DEBUG_PREFIX = "StreamingChannelExistenceChecker";

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ack!


try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, not needed!


ChannelExistenceCheckerResponse channelExistenceCheckerResponse;
try (CloseableHttpResponse closeableHttpResponse = httpClient.execute(request)) {

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra line

Comment on lines +145 to +146
LOGGER.warn(
"Null response obtained in {} for channel:{}", CHANNEL_STATUS_ENDPOINT, channelName);
Copy link
Contributor

Choose a reason for hiding this comment

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

why we need a log if we're going to throw?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to know which channel name had this issue.

.equals(SUCCESS.getStatusCode())) {
// We check two status codes, one for invalid client sequencers and one for a valid client
// Sequencer
LOGGER.debug(String.format("%s Channel:%s does exist", DEBUG_PREFIX, channelName));
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate with above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's Does and doesn't for channel.

"{} Error Getting a valid response for ChannelName:{} error:{}",
DEBUG_PREFIX,
channelName,
e.getMessage());
Copy link
Contributor

Choose a reason for hiding this comment

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

any issue with returning here instead of thrown an error?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's ok, being unable to get a channel basically means it doesnt exist. We should add that behavior to the javadoc though: @return True if it exists, false if it doesn't or failed to get status

* @param channelName Name of Channel to Check for Existence
* @return True if it exists, false if it doesn't.
*/
public boolean checkChannelExistence(final String channelName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: checkChannelExists so that it's easier to intuit that returning TRUE means the channel exists

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

makes sense, will do!

"{} Error Getting a valid response for ChannelName:{} error:{}",
DEBUG_PREFIX,
channelName,
e.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that's ok, being unable to get a channel basically means it doesnt exist. We should add that behavior to the javadoc though: @return True if it exists, false if it doesn't or failed to get status

switch (statusLine.getStatusCode()) {
// If we have a 503, BACKOFF
case HttpStatus.SC_SERVICE_UNAVAILABLE:
throw new BackOffException();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to retry for this BackOffException? We don't retry in checkChannelExistance

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, I copied this function from sdk and I do see we dont have retries in channelexistence, I plan to add retries, but let me check this..

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.

3 participants