openshift / svt

Apache License 2.0
123 stars 105 forks source link

add slack webhook to slack integration #758

Closed qiliRedHat closed 1 year ago

qiliRedHat commented 1 year ago

https://issues.redhat.com/browse/OCPQE-15385

qiliRedHat commented 1 year ago

Test 1 slack_enable: False OK

Test 2 slack_enable: True SLACK_API_TOKEN and SLACK_WEBHOOK_URL not provided

2023-05-22 17:52:03,987 - WARNING - Check if SLACK_WEBHOOK_URL environment variable are correctly set. Exception: 'SLACK_WEBHOOK_URL'
2023-05-22 17:52:03,987 - WARNING - Check if SLACK_API_TOKEN environment variable are correctly set. Exception: 'SLACK_API_TOKEN'
2023-05-22 17:52:03,987 - ERROR - Please provide either SLACK_API_TOKEN or SLACK_WEBHOOK_URL environment variable to enable slack integration.
2023-05-22 17:52:03,987 - WARNING - Disable slack integration.

Test 3 (expected to be failed because the SLACK_API_TOKEN is not approvaled now) slack_enable: True SLACK_API_TOKEN provided SLACK_MEMBER provided

2023-05-22 17:51:00,139 - INFO - Both SLACK_API_TOKEN and SLACK_WEBHOOK_URL are set. Slack integration method is set to 'web_api'.
2023-05-22 17:51:00,139 - INFO - Slack client created.
2023-05-22 17:51:00,139 - INFO - => oc --kubeconfig /Users/qili/Downloads/qili-rc8/kubeconfig whoami --show-server
2023-05-22 17:51:00,219 - INFO - oc --kubeconfig /Users/qili/Downloads/qili-rc8/kubeconfig whoami --show-server 
 0 : https://api.qili-rc8.qe-lrc.devcluster.openshift.com:6443

2023-05-22 17:51:00,220 - INFO - => oc --kubeconfig /Users/qili/Downloads/qili-rc8/kubeconfig version
2023-05-22 17:51:01,452 - INFO - oc --kubeconfig /Users/qili/Downloads/qili-rc8/kubeconfig version 
 0 : Client Version: 4.13.0-0.nightly-2023-04-18-005127
Kustomize Version: v4.5.7
Server Version: 4.13.0-rc.8
Kubernetes Version: v1.26.3+b404935

2023-05-22 17:51:02,087 - WARNING - slack web api chat_postMessage had an exception: 'The request to the Slack API failed.
The server responded with: {'ok': False, 'error': 'account_inactive'}
2023-05-22 17:51:02,087 - WARNING - Disable slack integration.

Test 4 slack_enable: True SLACK_API_TOKEN unset SLACK_WEBHOOK_URL provided SLACK_MEMBER provided

2023-05-22 18:17:57,411 - WARNING - Check if SLACK_API_TOKEN environment variable are correctly set. Exception: 'SLACK_API_TOKEN'
2023-05-22 18:17:57,411 - INFO - Slack integration method is 'webhook'.
2023-05-22 18:17:57,418 - INFO - Slack webhook url is configured.

Slack channel notification

[2023-05-22 18:17:58 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  [2023-05-22 18:17:58 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  Reliability-v2 test has started on cluster: https://api.qili-rc8.qe-lrc.devcluster.openshift.com:6443/
Client Version: 4.13.0-0.nightly-2023-04-18-005127
Kustomize Version: v4.5.7
Server Version: 4.13.0-rc.8
Kubernetes Version: v1.26.3+b404935
[6:18](https://redhat-internal.slack.com/archives/C0266JJ4XM5/p1684750686029389)
[2023-05-22 18:18:05 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  Group admin will run tasks with 1 users for forever loops. Adding a jitter of 60s before group test started, wait 600s between loops, wait 10s between tasks.
[6:18](https://redhat-internal.slack.com/archives/C0266JJ4XM5/p1684750686053519)
[2023-05-22 18:18:05 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  Group dev-prod will run tasks with 1 users for forever loops. Adding a jitter of 1200s before group test started, wait 600s between loops, wait 600s between tasks.
[6:18](https://redhat-internal.slack.com/archives/C0266JJ4XM5/p1684750686053539)
[2023-05-22 18:18:05 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  Group dev-cronjob will run tasks with 6 users for forever loops. Adding a jitter of 1200s before group test started, wait 600s between loops, wait 60s between tasks.
[6:18](https://redhat-internal.slack.com/archives/C0266JJ4XM5/p1684750686059649)
[2023-05-22 18:18:05 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  Group dev-test will run tasks with 15 users for forever loops. Adding a jitter of 600s before group test started, wait 60s between loops, wait 10s between tasks.

[2023-05-22 18:18:54 CST] 
[@Qiujie Li - qili](https://redhat-internal.slack.com/team/U01SBLKMZFZ)
,  

 cmd: oc --kubeconfig /Users/qili/qiliRedHat/svt/reliability-v2/kubeconfigs/kubeconfig_testuser-21 new-project --skip-config-write testuser-21-0  failed. Result: Error from server (AlreadyExists): [project.project.openshift.io](http://project.project.openshift.io/) "testuser-21-0" already exists
qiliRedHat commented 1 year ago

@paigerube14 PTAL

paigerube14 commented 1 year ago

/lgtm

qiliRedHat commented 1 year ago

@paigerube14 As the webhook can not orgnize all messages of a single test in a thread, to identify each test when multiple tests are running, I added a uuid to each of the test.

qiliRedHat commented 1 year ago

@paigerube14 Please review again, thanks!

qiliRedHat commented 1 year ago

Updated with latest slack sdk Last test result:

2023-05-24 09:58:58,546 - INFO - Test uuid: c5eb531d-4463-4e3a-b781-a79c82a352d6
2023-05-24 09:58:58,565 - INFO - Relogin job is added with interval: minutes=60.
2023-05-24 09:58:58,565 - WARNING - Check if SLACK_API_TOKEN environment variable are correctly set. Exception: 'SLACK_API_TOKEN'
2023-05-24 09:58:58,565 - INFO - Slack integration method is 'webhook'.
2023-05-24 09:58:58,565 - INFO - Slack webhook url is configured.

Slack message https://redhat-internal.slack.com/archives/C0266JJ4XM5/p1684921204731629

[2023-05-24 09:58:58 UTC] [c5eb531d-4463-4e3a-b781-a79c82a352d6] 
@Qiujie Li - qili
,  Reliability-v2 test has started on cluster: https://api.qili-41218-sno.qe-lrc.devcluster.openshift.com:6443/
Client Version: 4.13.0-0.nightly-2023-02-17-090603
Kustomize Version: v4.5.7
Server Version: 4.12.18
Kubernetes Version: v1.25.8+37a9a08
paigerube14 commented 1 year ago

/lgtm

qiliRedHat commented 1 year ago

@paigerube14 I updated README and squashed the commits.

qiliRedHat commented 1 year ago

@paigerube14 Please help to give it the final review. I kept 2 commits not merged because for the second one https://github.com/openshift/svt/pull/758/commits/617662d3205cc3d4d4ba1d8e030e907a58a61a58 I used it to answer a security question for workaround when 'OCP Reliability' slack app(SLACK_API_TOKEN way) has an outage.

paigerube14 commented 1 year ago

/lgtm