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

Convert Slack Communication from RTM to WebSocket #693

Merged
merged 16 commits into from
Sep 14, 2022

Conversation

huseyinbabal
Copy link
Contributor

@huseyinbabal huseyinbabal commented Aug 17, 2022

Description

Changes proposed in this pull request:

  • Enabled socket mode and deprecated RTM
  • Slack App-Level Token is injected into botkube docker image
  • Added makefile entry for generating tester image for Apple M1

Related issue(s)

Fixes #631

Testing

Note: Since socketmode should be enabled on the slack app, I created new app (BotKubeV2) in CI Workspace, you can see it here. Please refer app page to get bot token and app token. bot token is already visible as you are familiar with current notation. For app level token, scroll down on app overview page and generate token as shown below.
Screen Shot 2022-08-24 at 18 52 55
Screen Shot 2022-08-24 at 18 53 12

The integration tests fails as it uses outdated settings from main. I tested that locally:

1. Environment setup

export SLACK_TESTER_APP_TOKEN="xoxb-..."
export SLACK_BOT_TOKEN="xoxb-..."
export SLACK_APP_TOKEN="xapp-..."
export IMAGE_REPOSITORY="kubeshop/pr/botkube"
export IMAGE_TAG="693-PR"
export TEST_IMAGE_REPOSITORY="kubeshop/pr/botkube-test"
export PR_NUMBER=693

export SLACK_TESTER_APP_TOKEN="xoxb-..." # Notice that this is the token for tester app
export SLACK_BOT_TOKEN="xoxb-..."
export SLACK_APP_TOKEN="xapp-1..."

# The image generated on PR build cannot be used since ldflags update also is in workflow files, so during pr build, slack app level token is not injected into docker image. I built my images locally, once you build yours, please update following env params according to your values, or you can use mine as follows.

export IMAGE_REPOSITORY="huseyinbabal/botkube"
export IMAGE_TAG="v9.99.26-dev"
export IMAGE_REGISTRY="docker.io"

# Tester image is not working on apple m1, I added a make file command for that `make container-image-test-single`. You can build your tester image or use mine as follows.
export TEST_IMAGE_REPOSITORY="huseyinbabal/botkube-test"
export TEST_IMAGE_TAG="v9.99.9-dev"
export TEST_IMAGE_REGISTRY="docker.io"
export PR_NUMBER=693

2. Install Botkube

helm install botkube --namespace botkube ./helm/botkube --wait --create-namespace \
    -f ./helm/botkube/e2e-test-values.yaml \
    --set settings.log.level="debug" \
	--set communications.default-group.slack.token="${SLACK_BOT_TOKEN}" \
    --set image.registry="${IMAGE_REGISTRY}" \
    --set image.repository="${IMAGE_REPOSITORY}" \
    --set image.tag="${IMAGE_TAG}" \
    --set e2eTest.image.registry="${TEST_IMAGE_REGISTRY}" \
    --set e2eTest.image.repository="${TEST_IMAGE_REPOSITORY}" \
    --set e2eTest.image.tag="${TEST_IMAGE_TAG}" \
    --set e2eTest.slack.testerAppToken="${SLACK_TESTER_APP_TOKEN}" \
	--set e2eTest.slack.botName="botkubev2" \
    --set e2eTest.slack.additionalContextMessage="Pull request: ${PR_NUMBER} - https://github.com/kubeshop/botkube/pull/${PR_NUMBER}"

3. Test

helm test botkube --namespace botkube --timeout=10m  --logs

4. Check Logs

kubectl logs -n botkube botkube-e2e-test -f

You can verify test results in our official CI workspace here

@huseyinbabal huseyinbabal force-pushed the slack-rtm-to-ws branch 2 times, most recently from 51ea505 to cb99b8b Compare August 24, 2022 08:29
@huseyinbabal huseyinbabal marked this pull request as ready for review August 24, 2022 16:00
@huseyinbabal
Copy link
Contributor Author

Will rebase and resolve conflicts after I got approvals

Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

Left a couple of comments, but they're not blockers.

The comment regarding websockets was a left as a pure "how does this work now" question.

Thx

@@ -0,0 +1,21 @@
package utils
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious, why did you think we should extract the dumper into its own file?

It's only used in the context of E2E tests and occupied 7 lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I have used it in also debug logs in slack response messages. builtin formatters are not good on printing nested fields all the time.

}()

for {
select {
case <-ctx.Done():
b.log.Info("Shutdown requested. Finishing...")
return rtm.Disconnect()
Copy link
Contributor

Choose a reason for hiding this comment

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

Had a quick look around to understand how disconnects work in the context of websockets.

For my understanding only ... to confirm:
1 - disconnects are not predictable but they are handled by the Slack library.
2 - When we terminate BotKube we're assuming the server will terminate the connection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Really good catch, please see my updated impl. I have used RunContext(ctx) instead of Run(), so that once ctx is done, it will also close connection on websocket.

Copy link
Contributor

@ezodude ezodude Aug 25, 2022

Choose a reason for hiding this comment

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

Easy to miss. I was trying to make sense of it myself having never used the library.

Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

In terms of code review, LGTM.

I'll need to manually test, prob after 0.13.0 release.

@huseyinbabal huseyinbabal marked this pull request as draft August 29, 2022 08:18
@huseyinbabal huseyinbabal marked this pull request as ready for review September 4, 2022 06:30
Copy link
Contributor

@mszostok mszostok left a comment

Choose a reason for hiding this comment

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

I just want to let you know that I tested that as a part of #715 with own Socket Bot and it worked well 👍

I left really minor comments and I leave approving this PR for the first reviewer because I didn't run the e2e test.

.github/workflows/branch-build.yml Outdated Show resolved Hide resolved
hack/goreleaser.sh Show resolved Hide resolved
pkg/bot/slack.go Outdated Show resolved Hide resolved
pkg/utils/utils_test.go Outdated Show resolved Hide resolved
pkg/utils/utils_test.go Outdated Show resolved Hide resolved
hack/goreleaser.sh Outdated Show resolved Hide resolved
@huseyinbabal huseyinbabal requested a review from a team as a code owner September 6, 2022 09:23
@huseyinbabal huseyinbabal added the enhancement New feature or request label Sep 7, 2022
Copy link
Contributor

@ezodude ezodude left a comment

Choose a reason for hiding this comment

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

👍 Confirmed that Helm E2E tests ran successfully.

@huseyinbabal huseyinbabal merged commit 7d51b5c into kubeshop:main Sep 14, 2022
@huseyinbabal huseyinbabal deleted the slack-rtm-to-ws branch September 14, 2022 12:48
@huseyinbabal huseyinbabal added this to the v0.14.0 milestone Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request slack
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch the Slack implementation from RTM to WebSockets
3 participants