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

Hotfix/migration removal #13

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 59 additions & 35 deletions aviso-server/admin/aviso_admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,53 +22,77 @@
from aviso_monitoring.udp_server import UdpServer


def main():
# load the configuration
config = Config()
logger.info(f"Running Aviso-admin v.{__version__}")
logger.info(f"aviso_monitoring module v.{monitoring_version}")
logger.info(f"Configuration loaded: {config}")

# instantiate the compactor and cleaner
def setup_compactor_and_cleaner(config):
"""Sets up the compactor and cleaner with scheduling."""
compactor = Compactor(config.compactor)
cleaner = Cleaner(config.cleaner)

# Every day at scheduled time run the compactor
if compactor.enabled:
schedule.every().day.at(config.compactor["scheduled_time"]).do(compactor.run)

# Every day at scheduled time run the cleaner
cleaner = Cleaner(config.cleaner)
if cleaner.enabled:
schedule.every().day.at(config.cleaner["scheduled_time"]).do(cleaner.run)

# create the UDP server
receiver = Receiver()
udp_server = UdpServer(config.monitoring.udp_server, receiver)
udp_server.start()

# schedule reporters
rest_reporter = AvisoRestReporter(config.monitoring, receiver)
if rest_reporter.enabled:
schedule.every(rest_reporter.frequency).minutes.do(rest_reporter.run)
auth_reporter = AvisoAuthReporter(config.monitoring, receiver)
if auth_reporter.enabled:
schedule.every(auth_reporter.frequency).minutes.do(auth_reporter.run)
etcd_reporter = EtcdReporter(config.monitoring, receiver)
if etcd_reporter.enabled:
schedule.every(etcd_reporter.frequency).minutes.do(etcd_reporter.run)

# launch the prometheus reporter, this expose some tlms to /metrics

def setup_udp_server(config, receiver):
"""Initializes and starts the UDP server."""
try:
udp_server = UdpServer(config.monitoring.udp_server, receiver)
udp_server.start()
return udp_server
except Exception as e:
logger.exception("Failed to start UDP Server: %s", e)


def schedule_reporters(config, receiver):
"""Schedules various reporters based on the configuration."""
for reporter_class in [AvisoRestReporter, AvisoAuthReporter, EtcdReporter]:
reporter = reporter_class(config.monitoring, receiver)
if reporter.enabled:
schedule.every(reporter.frequency).minutes.do(reporter.run)


def start_prometheus_reporter(config, receiver):
"""Starts the Prometheus reporter if enabled."""
prometheus_reporter = PrometheusReporter(config.monitoring, receiver)
if prometheus_reporter.enabled:
prometheus_reporter.start()

# Loop so that the scheduling task keeps on running all time.
while True:
# Checks whether a scheduled task is pending to run or not
schedule.run_pending()
time.sleep(30)

def main():
"""Main function to run the application."""
# Load the configuration
config = Config()
logger.info(f"Running Aviso-admin v.{__version__}")
logger.info(f"aviso_monitoring module v.{monitoring_version}")
logger.info(f"Configuration loaded: {config}")

# Set up compactor and cleaner
setup_compactor_and_cleaner(config)

# Create the UDP server
receiver = Receiver()
udp_server = setup_udp_server(config, receiver)

# Schedule reporters
schedule_reporters(config, receiver)

# Start Prometheus reporter
start_prometheus_reporter(config, receiver)

# Main loop for running scheduled tasks
try:
while True:
schedule.run_pending()
time.sleep(30)
except KeyboardInterrupt:
logger.info("Application stopped by user.")
except Exception as e:
logger.exception("Unexpected error occurred: %s", e)
finally:
if udp_server:
udp_server.stop() # Assuming a method to gracefully stop the UDP server
logger.info("Application shutdown.")


# when running directly from this file
if __name__ == "__main__":
main()
178 changes: 0 additions & 178 deletions aviso-server/admin/migration/etcd_migration.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class OpsviewReporter(ABC):
metric_ssl_enabled = False
metric_token_enabled = False
metric_token = ""

def __init__(self, config: Config, msg_receiver=None):
Expand All @@ -34,8 +34,8 @@ def configure_metric_vars(cls, config):
Configures the class attributes based on the provided config.
"""
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
if config.kube_state_metrics["ssl_enabled"]:
cls.metric_ssl_enabled = True
if config.kube_state_metrics["token_enabled"]:
cls.metric_token_enabled = True
cls.metric_token = config.kube_state_metrics["token"]

def ms_authenticate(self, m_server):
Expand Down Expand Up @@ -223,7 +223,7 @@ def retrieve_metrics(cls, metric_servers, req_timeout):
logger.debug(f"Retrieving metrics from {url}...")
headers = {}
try:
if cls.metric_ssl_enabled:
if cls.metric_token_enabled:
headers["Authorization"] = f"Bearer {cls.metric_token}"
resp = requests.get(url, verify=False, timeout=req_timeout, headers=headers)
except Exception as e:
Expand Down
Loading