-
Notifications
You must be signed in to change notification settings - Fork 34
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
Adding azdoPrRepoName as metadata in FluxCD alert #74
Closed
Closed
Changes from all commits
Commits
Show all changes
3 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
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
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
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 |
---|---|---|
@@ -1,72 +1,72 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
import dataclasses | ||
import json | ||
import logging | ||
import os | ||
import os.path | ||
from urllib.parse import urlparse | ||
import requests | ||
SUBSCRIBERS_DIR = '/subscribers' | ||
# An endpoint that handles unprocessed JSON forwarded from notifications. | ||
class RawSubscriber: | ||
def __init__(self, url_endpoint): | ||
self._url_endpoint = url_endpoint | ||
def post_commit_status(self, commit_status): | ||
json_data = dataclasses.asdict(commit_status) | ||
logging.debug("Sending raw json to subscriber: " + json.dumps(json_data)) | ||
response = requests.post(url=self._url_endpoint, json=json_data) | ||
response.raise_for_status() | ||
class RawSubscriberFactory: | ||
@staticmethod | ||
def new_raw_subscribers() -> list[RawSubscriber]: | ||
logging.debug("Adding configured subscribers...") | ||
subscribers = RawSubscriberFactory._read_subscribers() | ||
logging.debug(f'{len(subscribers)} subscribers added.') | ||
return subscribers | ||
@staticmethod | ||
def _read_subscribers(): | ||
subscribers = [] | ||
try: | ||
subscriber_files = os.listdir(SUBSCRIBERS_DIR) | ||
except FileNotFoundError: | ||
logging.error("Subscriber config not found. Defaulting to no subscribers.") | ||
return subscribers | ||
if not subscriber_files: | ||
return subscribers | ||
for subscriber_file in subscriber_files: | ||
subscriber_file = os.path.join(SUBSCRIBERS_DIR, subscriber_file) | ||
if not os.path.isfile(subscriber_file): | ||
continue | ||
try: | ||
with open(subscriber_file, 'r') as subscriber_fh: | ||
url = subscriber_fh.readline() | ||
try: | ||
urlparse(url) | ||
except ValueError: | ||
logging.error(f"URL is invalid, subscriber has not been added: {url}") | ||
continue | ||
subscriber = RawSubscriber(url) | ||
subscribers.append(subscriber) | ||
logging.info(f"Added subscriber {subscriber_file} with endpoint {url}") | ||
except OSError: | ||
logging.error(f"Error opening subscriber config at {subscriber_file}") | ||
continue | ||
return subscribers | ||
|
||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
import dataclasses | ||
import json | ||
import logging | ||
import os | ||
import os.path | ||
from urllib.parse import urlparse | ||
import requests | ||
|
||
SUBSCRIBERS_DIR = '/subscribers' | ||
|
||
|
||
# An endpoint that handles unprocessed JSON forwarded from notifications. | ||
class RawSubscriber: | ||
def __init__(self, url_endpoint): | ||
self._url_endpoint = url_endpoint | ||
|
||
def post_commit_status(self, commit_status): | ||
json_data = dataclasses.asdict(commit_status) | ||
logging.debug("Sending raw json to subscriber: " + json.dumps(json_data)) | ||
response = requests.post(url=self._url_endpoint, json=json_data) | ||
response.raise_for_status() | ||
|
||
|
||
class RawSubscriberFactory: | ||
@staticmethod | ||
def new_raw_subscribers() -> list[RawSubscriber]: | ||
logging.debug("Adding configured subscribers...") | ||
subscribers = RawSubscriberFactory._read_subscribers() | ||
logging.debug(f'{len(subscribers)} subscribers added.') | ||
|
||
return subscribers | ||
|
||
@staticmethod | ||
def _read_subscribers(): | ||
subscribers = [] | ||
|
||
try: | ||
subscriber_files = os.listdir(SUBSCRIBERS_DIR) | ||
except FileNotFoundError: | ||
logging.error("Subscriber config not found. Defaulting to no subscribers.") | ||
return subscribers | ||
if not subscriber_files: | ||
return subscribers | ||
|
||
for subscriber_file in subscriber_files: | ||
subscriber_file = os.path.join(SUBSCRIBERS_DIR, subscriber_file) | ||
if not os.path.isfile(subscriber_file): | ||
continue | ||
|
||
try: | ||
with open(subscriber_file, 'r') as subscriber_fh: | ||
url = subscriber_fh.readline() | ||
|
||
try: | ||
urlparse(url) | ||
except ValueError: | ||
logging.error(f"URL is invalid, subscriber has not been added: {url}") | ||
continue | ||
|
||
subscriber = RawSubscriber(url) | ||
|
||
subscribers.append(subscriber) | ||
logging.info(f"Added subscriber {subscriber_file} with endpoint {url}") | ||
except OSError: | ||
logging.error(f"Error opening subscriber config at {subscriber_file}") | ||
continue | ||
|
||
return subscribers |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Flask==2.3 | ||
gunicorn==20.0.4 | ||
requests | ||
timeloop | ||
Flask==2.3 | ||
gunicorn==20.0.4 | ||
requests | ||
timeloop | ||
python-dateutil |
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.
The GitOps connector instance is shared across threads. It is very possible that another thread, initiated by an alert configured for the different application/repo, will override these self settings. So the message from thread 1 will go to the repo from thread 2.
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.
Besides forwarding the alerts to AZDO, GitOps connector detects abandoned/rejected PRs to the GitOps repo and notifies the agentless waiting task to fail, so the whole promotional flow gets failed. This logic is implemented on top of having a single repo.
IMO, if we want to support multiple applications, we have the options: