-
Notifications
You must be signed in to change notification settings - Fork 110
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
feat: Support multiple destinations for a healthcheck #2704
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||
import logging | ||||
import os | ||||
import subprocess | ||||
import re | ||||
|
||||
app = Flask(__name__) | ||||
|
||||
|
@@ -14,11 +15,20 @@ def str_to_bool(value): | |||
'yes' | ||||
} | ||||
|
||||
def get_list_of_destinations(): | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just have 2 questions:
P.S. It's just a questions, it doesn't mean that we need to do asap, we will just discuss it |
||||
found_destinations = [] | ||||
regex = r"^SC4S_DEST_SPLUNK_HEC_(.*)_URL$" | ||||
|
||||
for var_key, var_variable in os.environ.items(): | ||||
if re.search(regex, var_key): | ||||
found_destinations.append(var_variable) | ||||
return set(found_destinations) | ||||
|
||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be imported from:
But a dot in "conf.d" is causing an import issue. Something to think about later I guess |
||||
class Config: | ||||
SC4S_DEST_SPLUNK_HEC_DEFAULT_URL = os.getenv('SC4S_DEST_SPLUNK_HEC_DEFAULT_URL') | ||||
HEALTHCHECK_PORT = int(os.getenv('SC4S_LISTEN_STATUS_PORT', '8080')) | ||||
CHECK_QUEUE_SIZE = str_to_bool(os.getenv('HEALTHCHECK_CHECK_QUEUE_SIZE', "false")) | ||||
MAX_QUEUE_SIZE = int(os.getenv('HEALTHCHECK_MAX_QUEUE_SIZE', '10000')) | ||||
DESTINATIONS = get_list_of_destinations() | ||||
|
||||
logging.basicConfig( | ||||
format=f"%(asctime)s - healthcheck.py - %(levelname)s - %(message)s", | ||||
|
@@ -48,11 +58,11 @@ def check_syslog_ng_health() -> bool: | |||
return False | ||||
|
||||
def check_queue_size( | ||||
sc4s_dest_splunk_hec_default=Config.SC4S_DEST_SPLUNK_HEC_DEFAULT_URL, | ||||
sc4s_dest_splunk_hec_destinations=Config.DESTINATIONS, | ||||
max_queue_size=Config.MAX_QUEUE_SIZE | ||||
) -> bool: | ||||
"""Check syslog-ng queue size and compare it against the configured maximum limit.""" | ||||
if not sc4s_dest_splunk_hec_default: | ||||
if not sc4s_dest_splunk_hec_destinations: | ||||
logger.error( | ||||
"SC4S_DEST_SPLUNK_HEC_DEFAULT_URL not configured. " | ||||
"Ensure the default HEC destination is set, or disable HEALTHCHECK_CHECK_QUEUE_SIZE." | ||||
|
@@ -71,15 +81,22 @@ def check_queue_size( | |||
return False | ||||
|
||||
stats = result.stdout.splitlines() | ||||
destination_stat = next( | ||||
(s for s in stats if ";queued;" in s and sc4s_dest_splunk_hec_default in s), | ||||
None | ||||
) | ||||
if not destination_stat: | ||||
logger.error("No matching queue stats found for the destination URL.") | ||||
return False | ||||
|
||||
queue_size = int(destination_stat.split(";")[-1]) | ||||
queue_sizes_all_destinations = [] | ||||
|
||||
for destination in sc4s_dest_splunk_hec_destinations: | ||||
destination_stat = next( | ||||
(s for s in stats if ";queued;" in s and destination in s), | ||||
None | ||||
) | ||||
|
||||
if not destination_stat: | ||||
logger.error(f"No matching queue stats found for the destination URL {destination}.") | ||||
return False | ||||
|
||||
queue_sizes_all_destinations.append(int(destination_stat.split(";")[-1])) | ||||
|
||||
queue_size = max(queue_sizes_all_destinations) | ||||
if queue_size > max_queue_size: | ||||
logger.warning( | ||||
f"Queue size {queue_size} exceeds the maximum limit of {max_queue_size}." | ||||
|
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.
This is fixed in: #2690 , but we need it for workflow to work properly