-
Notifications
You must be signed in to change notification settings - Fork 12
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
ART-9026 add new api for check schedule #135
Open
Ximinhan
wants to merge
2
commits into
openshift-eng:master
Choose a base branch
from
Ximinhan:art-9026-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FROM registry.redhat.io/ubi9/ubi-minimal:latest | ||
RUN microdnf install -y python pip && python3 -m pip install --upgrade pip && pip3 install slack_sdk requests | ||
COPY check_schedule.py /check_schedule.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import os | ||
import requests | ||
from typing import Optional | ||
import time | ||
from slack_sdk import WebClient | ||
|
||
slack_token = os.environ.get('SLACK_TOKEN', None) | ||
API_ENDPOINT = "https://art-dash-server-art-dashboard-server.apps.artc2023.pc3z.p1.openshiftapps.com/api/v1" | ||
|
||
|
||
def post_slack_message(message: str, thread_ts: Optional[str] = None,): | ||
response = WebClient(token=slack_token).chat_postMessage( | ||
channel="#forum-ocp-release", | ||
text=message, | ||
thread_ts=thread_ts, username="art-release-bot", link_names=True, attachments=[], icon_emoji=":dancing_robot:", reply_broadcast=False) | ||
return response | ||
|
||
|
||
release_status = requests.get(f"{API_ENDPOINT}/release_status").json() | ||
if release_status['alert'] != []: | ||
response = post_slack_message(' \n'.join([msg['status'] for msg in release_status['alert']])) | ||
print(f"message posted in https://redhat-internal.slack.com/archives/{response['channel']}/p{response['ts'].replace('.', '')}") | ||
if release_status['unshipped'] != []: | ||
post_slack_message("start monitoring advisory not in shipped live status, interval set to 1 hour ...", thread_ts=response['ts']) | ||
while release_status['unshipped'] != []: | ||
for item in release_status['unshipped']: | ||
# check ad status | ||
advisory_status_response = requests.get(f"{API_ENDPOINT}/advisory_activites/?advisory={item['advisory']}").json() | ||
errata_activity = advisory_status_response['data'] | ||
if len(errata_activity) > 0: | ||
advisory_status = errata_activity[-1]['attributes']['added'] | ||
else: | ||
advisory_status = "NEW_FILES" | ||
if advisory_status == "SHIPPED_LIVE" or advisory_status == "DROPPED_NO_SHIP": | ||
release_status['unshipped'].remove(item) | ||
post_slack_message(f"{item['note']} status changed to {advisory_status}", thread_ts=response['ts']) | ||
# sleep 1 hours | ||
print(f"sleeping 1 hours due to {release_status['unshipped']}") | ||
time.sleep(3600) | ||
post_slack_message("All advisory now in shipped live status, stop monitoring", thread_ts=response['ts']) | ||
else: | ||
print("No alert", [msg['status'] for msg in release_status['message']]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I know why this scheduled job is here and not in aos-cd-jobs along with the other scheduled jobs? Unless there is a good reason, I would really like it to be in aos-cd-jobs
https://github.com/openshift-eng/aos-cd-jobs/tree/master/scheduled-jobs/scanning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Different from the Jenkins job, this is a script that will build into the image. I used to think that moving this part to art-tools/art-cluster/pipelines, may be the right place along with task and job config. But consider we may set up a trigger to the image build when a new commit happens in the docker file repo. I think the art-tools repo updates more frequently than the art-dashboard-server repo and the script is more bonded with the server API so put it here. When the API is changed, it can be in the same PR and commit and the cluster only will rebuild once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand from the code, the new API endpoint serves the data from errata unmodified, so we do not need to redeploy art-dash-server as well. The purpose of the Dockerfile is only to run this script right? This can be achieved with Jenkins, by setting up a periodic job. That is also where similar jobs are running.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if I didn't miss anything, I don't see any need for a Dockerfile here, and we can achieve the result that you intended by separating out the
check_schedule.py
code to aos-cd-jobsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true and false, the dockerfile only for run the script is true and we need to redeploy the server to provide service for the API. I would like to try the cron job in art cluster instead of using the jenkins scheduled job. the art-dash-server plays a role has permission to connect errata and response filtered output to the requester, which makes the "job" side very light and shaped with efficiency without extra init step.