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

refactor(backends/datadog): avoid useless call to Datadog API #356

Merged
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
7 changes: 5 additions & 2 deletions slo_generator/backends/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import datadog

from slo_generator import utils

LOGGER = logging.getLogger(__name__)
logging.getLogger("datadog.api").setLevel(logging.ERROR)

Expand Down Expand Up @@ -124,8 +126,9 @@ def query_slo(self, timestamp, window, slo_config):
"""
slo_id = slo_config["spec"]["service_level_indicator"]["slo_id"]
from_ts = timestamp - window
slo_data = self.client.ServiceLevelObjective.get(id=slo_id)
LOGGER.debug(f"SLO data: {slo_id} | Result: {pprint.pformat(slo_data)}")
if utils.is_debug_enabled():
slo_data = self.client.ServiceLevelObjective.get(id=slo_id)
LOGGER.debug(f"SLO data: {slo_id} | Result: {pprint.pformat(slo_data)}")
data = self.client.ServiceLevelObjective.history(
id=slo_id,
from_ts=from_ts,
Expand Down
7 changes: 6 additions & 1 deletion slo_generator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,14 @@ def replace_env_vars(content, ctx) -> str:
return data


def is_debug_enabled():
"""Check if DEBUG mode is enabled."""
return DEBUG == 1


def setup_logging():
"""Setup logging for the CLI."""
if DEBUG == 1:
if is_debug_enabled():
print(f"DEBUG mode is enabled. DEBUG={DEBUG}")
level = logging.DEBUG
format_str = "%(name)s - %(levelname)s - %(message)s"
Expand Down