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

Log reconnects #244

Merged
merged 21 commits into from
Mar 25, 2020
Merged

Log reconnects #244

merged 21 commits into from
Mar 25, 2020

Conversation

wasabigeek
Copy link
Contributor

Attempt to fix #213

@wasabigeek
Copy link
Contributor Author

@dblock I only just noticed #229, would this issue/PR still be relevant?

@dblock
Copy link
Collaborator

dblock commented Mar 22, 2020

It's related/similar. This PR is good though, let's finish it!

I'd like to change connected to connected_at, and make it consistent as an attribute like logger, save the timestamp when the reconnect happens. This will allow us to track reconnects after reconnects instead of just 2 states.

Optional, if possible, when the bot goes offline let's log its uptime using this info. Do note that initialize shouldn't set connected_at because that's not an actual connection yet, you want to do that after the bot actually connects.

@wasabigeek
Copy link
Contributor Author

wasabigeek commented Mar 23, 2020

Optional, if possible, when the bot goes offline let's log its uptime using this info

To clarify, uptime = time when App#stop! is called - time when slack confirmed that bot was first connected? Or is there a more accurate measure?

@dblock
Copy link
Collaborator

dblock commented Mar 23, 2020

Optional, if possible, when the bot goes offline let's log its uptime using this info

To clarify, uptime = time when App#stop! is called - time when slack confirmed that bot was first connected? Or is there a more accurate measure?

Ideally you want the time difference between confirmation (callback) of connect and disconnect. Also, make sure to read https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/ :)

@wasabigeek
Copy link
Contributor Author

wasabigeek commented Mar 23, 2020

So time of reconnect - time of last (re)connect? (edit: just read the article, TIL, will take note of that! Conceptually this representation is still helpful for me) Still somewhat an approximation if I understood correctly (since we have to wait for the hook to be called), is that ok?

I realise I read your comment wrongly. Struggling to find out the time of disconnect - is there an event I can listen to (is goodbye the one to look for)? As far as I understood all the detection of a disconnect is in the Client library. Unless an approximation is fine (i.e. time of reconnect - time of last (re)connect)

@dblock
Copy link
Collaborator

dblock commented Mar 23, 2020

I think approximation is fine, but maybe later feel free to raise an event from the client library if it's not already there when the bot detects a disconnect. It would be good to "know" how long it took to reconnect, plus it can be hours, where we'll be reporting wrong "uptime". So I guess we shouldn't call it uptime, but just time since last successful connection.

@wasabigeek
Copy link
Contributor Author

Do you think "Successfully ... after #{connected_at - self.connected_at}s" would be a bit confusing, since it's not clear that the time is from last connection till this reconnection? (I would have interpreted it as the time from initiating the current connection to the confirmation of that connection)

log = ["Successfully #{@connected_at ? 'reconnected' : 'connected'} team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com"]

connected_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
log << "after #{connected_at - self.connected_at} seconds" if self.connected_at
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I round this to, say, 6 decimal places?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would round it up to 1 or 2 decimals and just stick an s at the end of it to keep it short.


def initialize(logger)
self.logger = logger
end

def call(client, _data)
return unless client && client.team
logger.info "Successfully connected team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com."
log = ["Successfully #{@connected_at ? 'reconnected' : 'connected'} team #{client.team.name} (#{client.team.id}) to https://#{client.team.domain}.slack.com"]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here's a neat trick I use for this:

log = [
 "Successfull ... ",
 connected_at ? ... : nil,
 ...
].compact.join(" ")

Maybe nicer?

@wasabigeek wasabigeek requested a review from dblock March 25, 2020 12:11
@dblock dblock merged commit 4ae24a0 into slack-ruby:master Mar 25, 2020
@dblock
Copy link
Collaborator

dblock commented Mar 25, 2020

Merged, thank you.

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.

Display different language when the bot is reconnected
2 participants