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

perform credentials check before creating consumer #256

Closed
wants to merge 3 commits into from
Closed

perform credentials check before creating consumer #256

wants to merge 3 commits into from

Conversation

abaruni
Copy link
Contributor

@abaruni abaruni commented Mar 5, 2018

No description provided.

@abaruni
Copy link
Contributor Author

abaruni commented Mar 6, 2018

there are two changes here:

  1. Perform a check of the messagehub credentials (if it is messagehub) and topic. This is to ensure that the authkey and topic provide when the trigger was originally created are still valid. there is the possibility that credentials and/or a topic could be deleted without the trigger being deleted. this leaves around zombie consumers who never stop attempting to connect to a broker. the idea here is to do the check when creating a consumer for an active trigger. if the authkey and topic are valid, then we will create the consumer as usual. if either are invalid. then the consumer will not be created and the trigger will be disabled in the db. if encounter any errors while trying to validate, then we'll retry. if at the end of the alloted retries, we don't succeed in getting either a 200 or 403, then we'll treat it as though we did get a 200. the motivation being that we'll eventually catch it on subsequent deploys. better to err on the side of caution than to mistakenly disable a valid trigger

  2. do not create consumers for disabled triggers

@@ -106,7 +113,7 @@ def run(self):
# running trigger should become disabled
# this should be done regardless of which worker the document claims to be assigned to
logging.info('[{}] Existing running trigger should become disabled'.format(change["id"]))
existingConsumer.disable()
existingConsumer.shutdown()
Copy link
Member

Choose a reason for hiding this comment

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

Need to update doc above that mentions that the consumer should be disabled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

if doc['isMessageHub']:
retries = 0
max_retries = 5
url = '{}/admin/topics'.format(doc['kafka_admin_url'])
Copy link
Member

Choose a reason for hiding this comment

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

Will the admin URL throttle requests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haven't experienced throttling in my own testing, but i will have to double check on the official answer

consumer.start()
else:
logging.info('[{}] Trigger was determined to be disabled, not starting...'.format(triggerFQN))
logging.info('[{}] Starting consumer...'.format(triggerFQN))
Copy link
Member

Choose a reason for hiding this comment

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

Do these changes affect the other occurrence of the call to __isTriggerDocActive in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. currently we detect a change in the changes feed and check whether that consumer is in our in-memory cache. this is still the case, however, since we will not be creating disabled consumers. the only time we'll hit the code path where we are going from inactive -> active and

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we do have that consumer in memory is when we disable a trigger for reasons like client errors. doing that is something that may likely change in the future. so that whole logic would need reworking

password = doc['password']
topic = doc['topic']

while retries < max_retries:
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we could have a test here for invalid auth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i'm afraid i'm going to have to change a doc in cloudant for that. need to get that figured out

logging.info('Received status code {} for {} while validating authKey. Retrying in {} second(s)'.format(status_code, triggerFQN, sleepyTime))
time.sleep(sleepyTime)
retries += 1

# Create a representation for this trigger, even if it is disabled
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i need to update this comment as well

@dgrove-oss
Copy link
Member

Closing as abandoned

@dgrove-oss dgrove-oss closed this May 26, 2020
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.

None yet

3 participants