Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 13, 2023
1 parent a99dea8 commit f9e93d1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
4 changes: 3 additions & 1 deletion UnleashClient/api/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def get_feature_toggles(
:return: (Feature flags, etag) if successful, ({},'') if not
"""
try:
backoff_strategy = backoff_strategy or BackoffStrategy() # TODO creating it here doesn't make sense
backoff_strategy = (
backoff_strategy or BackoffStrategy()
) # TODO creating it here doesn't make sense
if not backoff_strategy.performAction():
backoff_strategy.skipped()
return {}, ""
Expand Down
2 changes: 1 addition & 1 deletion UnleashClient/api/metrics.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json

import requests
from UnleashClient.api.backoff import BackoffStrategy

from UnleashClient.api.backoff import BackoffStrategy
from UnleashClient.constants import APPLICATION_HEADERS, METRICS_URL
from UnleashClient.utils import LOGGER, log_resp_info

Expand Down
13 changes: 10 additions & 3 deletions UnleashClient/periodic_tasks/send_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def aggregate_and_send_metrics(
backoff_strategy: Optional[BackoffStrategy] = None,
) -> None:
feature_stats_list = []
backoff_strategy = backoff_strategy or BackoffStrategy() # TODO creating it here doesn't make sense
backoff_strategy = (
backoff_strategy or BackoffStrategy()
) # TODO creating it here doesn't make sense
if not backoff_strategy.performAction():
backoff_strategy.skipped()
return {}, ""

for feature_name in features.keys():
if not (features[feature_name].yes_count or features[feature_name].no_count):
continue
Expand Down Expand Up @@ -53,7 +55,12 @@ def aggregate_and_send_metrics(

if feature_stats_list:
send_metrics(
url, metrics_request, custom_headers, custom_options, request_timeout, backoff_strategy
url,
metrics_request,
custom_headers,
custom_options,
request_timeout,
backoff_strategy,
)
# TODO should we do if send_metrics then update cache? We're also updating in the case of an exception
cache.set(METRIC_LAST_SENT_TIME, datetime.now(timezone.utc))
Expand Down
9 changes: 7 additions & 2 deletions tests/unit_tests/api/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import responses
from pytest import mark, param
from requests import ConnectionError
from UnleashClient.api.backoff import BackoffStrategy

from tests.utilities.mocks.mock_metrics import MOCK_METRICS_REQUEST
from tests.utilities.testing_constants import (
Expand All @@ -11,6 +10,7 @@
URL,
)
from UnleashClient.api import send_metrics
from UnleashClient.api.backoff import BackoffStrategy
from UnleashClient.constants import METRICS_URL

FULL_METRICS_URL = URL + METRICS_URL
Expand All @@ -34,7 +34,12 @@ def test_send_metrics(payload, status, expected):
responses.add(responses.POST, FULL_METRICS_URL, **payload, status=status)

result = send_metrics(
URL, MOCK_METRICS_REQUEST, CUSTOM_HEADERS, CUSTOM_OPTIONS, REQUEST_TIMEOUT, BackoffStrategy()
URL,
MOCK_METRICS_REQUEST,
CUSTOM_HEADERS,
CUSTOM_OPTIONS,
REQUEST_TIMEOUT,
BackoffStrategy(),
)

assert len(responses.calls) == 1
Expand Down

0 comments on commit f9e93d1

Please sign in to comment.