Skip to content

Commit 76e3704

Browse files
DTIN-4234: Black formatting (#1266)
Co-authored-by: ales.novak <[email protected]>
1 parent ecf9915 commit 76e3704

36 files changed

+1040
-617
lines changed

scalyr_agent/builtin_monitors/apache_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"number, at which the Apache status module is served. The URL should end in `/?auto` to "
5050
"indicate that the machine-readable version of the page should be returned.",
5151
default="http://localhost/server-status/?auto",
52-
allow_http=False
52+
allow_http=False,
5353
)
5454
define_config_option(
5555
__monitor__,

scalyr_agent/builtin_monitors/kubernetes_monitor.py

Lines changed: 78 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
KubeletApiException,
7272
K8sApiTemporaryError,
7373
K8sConfigBuilder,
74-
K8sNamespaceFilter, KubernetesCache,
74+
K8sNamespaceFilter,
75+
KubernetesCache,
7576
)
7677
from scalyr_agent.monitor_utils.k8s import (
7778
K8sApiPermanentError,
@@ -296,7 +297,7 @@
296297
"DEPRECATED.",
297298
convert_to=six.text_type,
298299
default="https://kubernetes.default",
299-
allow_http=False
300+
allow_http=False,
300301
)
301302

302303
define_config_option(
@@ -424,7 +425,7 @@
424425
convert_to=six.text_type,
425426
default="https://${host_ip}:10250",
426427
env_aware=True,
427-
allow_http=False
428+
allow_http=False,
428429
)
429430

430431
define_config_option(
@@ -2352,7 +2353,6 @@ def _get_containers(
23522353
if not k8s_include_by_default:
23532354
continue
23542355

2355-
23562356
# add this container to the list of results
23572357
result[cid] = {
23582358
"name": cname,
@@ -2534,6 +2534,7 @@ class DockerLog(object):
25342534
"""
25352535
Represents a list of log configs for a container
25362536
"""
2537+
25372538
def __init__(self, cid, stream, log_configs):
25382539
assert len(log_configs) > 0, "log_configs must not be empty"
25392540
self.__cid = cid
@@ -2669,7 +2670,7 @@ def __init__(
26692670
"k8s_cache_init_abort_delay"
26702671
)
26712672

2672-
self.k8s_cache = None # type: Optional[KubernetesCache]
2673+
self.k8s_cache = None # type: Optional[KubernetesCache]
26732674
self.__k8s_config_builder = None
26742675

26752676
self.__node_name = None
@@ -2685,8 +2686,8 @@ def __init__(
26852686
self.__controlled_warmer = controlled_warmer
26862687

26872688
# give this an initial empty value
2688-
self.raw_logs = [] # type: List[DockerLog]
2689-
self.docker_logs = [] # type: List[DockerLog]
2689+
self.raw_logs = [] # type: List[DockerLog]
2690+
self.docker_logs = [] # type: List[DockerLog]
26902691

26912692
self.__stopped = False
26922693

@@ -3066,7 +3067,11 @@ def check_containers(self, run_state):
30663067
limit_key="check-container-pod-info-%s" % cid,
30673068
)
30683069

3069-
namespace = self.k8s_cache.namespace(pod_namespace, current_time=current_time, allow_expired=False)
3070+
namespace = self.k8s_cache.namespace(
3071+
pod_namespace,
3072+
current_time=current_time,
3073+
allow_expired=False,
3074+
)
30703075
# start the container if have a container that wasn't running
30713076
if cid not in self.containers:
30723077
self._logger.log(
@@ -3077,10 +3082,14 @@ def check_containers(self, run_state):
30773082
elif cid in prev_digests or cid in prev_digests_namespaces:
30783083
# container was running and it exists in the previous digest dict, so see if
30793084
# it has changed
3080-
if (pod and prev_digests[cid] != pod.digest) or (namespace and prev_digests_namespaces[cid] != namespace.digest):
3085+
if (pod and prev_digests[cid] != pod.digest) or (
3086+
namespace
3087+
and prev_digests_namespaces[cid] != namespace.digest
3088+
):
30813089
self._logger.log(
30823090
scalyr_logging.DEBUG_LEVEL_1,
3083-
"Pod or namespace digest changed for '%s/%s'" % (namespace.name, info["name"]),
3091+
"Pod or namespace digest changed for '%s/%s'"
3092+
% (namespace.name, info["name"]),
30843093
)
30853094
changed[cid] = info
30863095

@@ -3128,8 +3137,12 @@ def check_containers(self, run_state):
31283137
"updating config for '%s'" % info["name"],
31293138
)
31303139

3131-
logger.log_configs = self.__log_watcher.update_log_configs_on_path(
3132-
info["log_path"], self.__module.module_name, new_configs
3140+
logger.log_configs = (
3141+
self.__log_watcher.update_log_configs_on_path(
3142+
info["log_path"],
3143+
self.__module.module_name,
3144+
new_configs,
3145+
)
31333146
)
31343147
else:
31353148
self._logger.log(
@@ -3194,9 +3207,11 @@ def __start_docker_logs(self, docker_logs):
31943207
if self.__log_watcher:
31953208
updated_log_configs = []
31963209
for log_config in log.log_configs:
3197-
updated_log_configs.append(self.__log_watcher.add_log_config(
3198-
self.__module.module_name, log_config, force_add=True
3199-
))
3210+
updated_log_configs.append(
3211+
self.__log_watcher.add_log_config(
3212+
self.__module.module_name, log_config, force_add=True
3213+
)
3214+
)
32003215
log.log_configs = updated_log_configs
32013216

32023217
self.raw_logs.append(log)
@@ -3510,26 +3525,47 @@ def __get_log_config_for_container(self, cid, info, k8s_cache, base_attributes):
35103525

35113526
self._logger.log(
35123527
scalyr_logging.DEBUG_LEVEL_0,
3513-
"log_config_for_container Checking for teams in annotations for container %s(%s), pod %s, namespace %s. Container annotations = %s, Pod annotations = %s, Namespace annotations = %s " \
3514-
% (info["name"], short_cid, pod_name, pod_namespace, container_annotations, all_annotations, namespace_annotations)
3528+
"log_config_for_container Checking for teams in annotations for container %s(%s), pod %s, namespace %s. Container annotations = %s, Pod annotations = %s, Namespace annotations = %s "
3529+
% (
3530+
info["name"],
3531+
short_cid,
3532+
pod_name,
3533+
pod_namespace,
3534+
container_annotations,
3535+
all_annotations,
3536+
namespace_annotations,
3537+
),
35153538
)
35163539

35173540
if container_annotations or all_annotations or namespace_annotations:
3518-
api_keys = self.__container_api_keys_from_annotations(k8s_cache, pod_namespace, container_annotations, "container", info["name"])
3541+
api_keys = self.__container_api_keys_from_annotations(
3542+
k8s_cache,
3543+
pod_namespace,
3544+
container_annotations,
3545+
"container",
3546+
info["name"],
3547+
)
35193548
if not api_keys:
3520-
api_keys = self.__container_api_keys_from_annotations(k8s_cache, pod_namespace, all_annotations, "pod", info["name"])
3549+
api_keys = self.__container_api_keys_from_annotations(
3550+
k8s_cache, pod_namespace, all_annotations, "pod", info["name"]
3551+
)
35213552
if not api_keys:
3522-
api_keys = self.__container_api_keys_from_annotations(k8s_cache, pod_namespace, namespace_annotations, "namespace", info["name"])
3553+
api_keys = self.__container_api_keys_from_annotations(
3554+
k8s_cache,
3555+
pod_namespace,
3556+
namespace_annotations,
3557+
"namespace",
3558+
info["name"],
3559+
)
35233560
if api_keys:
35243561
# Multiple matching api keys will result in multiple log configs, which will differ in the api_key field only.
3525-
results = [
3526-
{**result, "api_key": api_key}
3527-
for api_key in api_keys
3528-
]
3562+
results = [{**result, "api_key": api_key} for api_key in api_keys]
35293563

35303564
return results
35313565

3532-
def __container_api_keys_from_annotations(self, k8s_cache, namespace, annotations, annotation_kind, container_name):
3566+
def __container_api_keys_from_annotations(
3567+
self, k8s_cache, namespace, annotations, annotation_kind, container_name
3568+
):
35333569
def fetch_secret(name):
35343570
if not name:
35353571
return None
@@ -3546,48 +3582,45 @@ def fetch_secret(name):
35463582
)
35473583

35483584
self._logger.warning(
3549-
"Failed to fetch secret '%s/%s', ignoring."
3550-
% (namespace, name),
3585+
"Failed to fetch secret '%s/%s', ignoring." % (namespace, name),
35513586
limit_once_per_x_secs=300,
35523587
limit_key="k8s-fetch-secret-%s/%s" % (namespace, name),
35533588
)
35543589

35553590
def get_secret_api_key(secret):
35563591
if not secret:
35573592
return None
3558-
api_key = base64.b64decode(secret.data.get("scalyr-api-key")).decode("utf-8")
3593+
api_key = base64.b64decode(secret.data.get("scalyr-api-key")).decode(
3594+
"utf-8"
3595+
)
35593596

35603597
if not api_key:
35613598
self._logger.warning(
35623599
"Secret '%s/%s' does not contain a scalyr-api-key field, ingoring."
35633600
% (namespace, secret.name),
35643601
limit_once_per_x_secs=300,
3565-
limit_key="k8s-fetch-secret-%s" % secret.name
3602+
limit_key="k8s-fetch-secret-%s" % secret.name,
35663603
)
35673604

35683605
return api_key
35693606

3570-
secrets_names = [
3571-
team.get("secret")
3572-
for team in annotations.get("teams", [])
3573-
]
3607+
secrets_names = [team.get("secret") for team in annotations.get("teams", [])]
35743608

3575-
secrets = [
3576-
secret
3577-
for secret in map(fetch_secret, secrets_names)
3578-
if secret
3579-
]
3609+
secrets = [secret for secret in map(fetch_secret, secrets_names) if secret]
35803610

3581-
api_keys = [
3582-
api_key
3583-
for api_key in map(get_secret_api_key, secrets)
3584-
if api_key
3585-
]
3611+
api_keys = [api_key for api_key in map(get_secret_api_key, secrets) if api_key]
35863612

35873613
self._logger.log(
35883614
scalyr_logging.DEBUG_LEVEL_0,
3589-
"log_config_for_container From %s annotations of container %s and namespace %s, got %d non-empty api keys, %d secrets for secret names %s" \
3590-
% (annotation_kind, container_name, namespace, len(api_keys), len(secrets), ",".join(secrets_names))
3615+
"log_config_for_container From %s annotations of container %s and namespace %s, got %d non-empty api keys, %d secrets for secret names %s"
3616+
% (
3617+
annotation_kind,
3618+
container_name,
3619+
namespace,
3620+
len(api_keys),
3621+
len(secrets),
3622+
",".join(secrets_names),
3623+
),
35913624
)
35923625

35933626
return api_keys

scalyr_agent/builtin_monitors/kubernetes_openmetrics_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
convert_to=six.text_type,
255255
default="https://${host_ip}:10250",
256256
env_aware=True,
257-
allow_http=False
257+
allow_http=False,
258258
)
259259

260260
# Monitor specific options

scalyr_agent/builtin_monitors/mysql_monitor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ def _connect(self):
459459
self._cursor = None
460460
self._logger.error("Database connect failed: %s" % me)
461461
except Exception as ex:
462-
self._logger.error("Exception trying to connect occured: %s" % ex, exc_info=ex)
462+
self._logger.error(
463+
"Exception trying to connect occured: %s" % ex, exc_info=ex
464+
)
463465
raise Exception("Exception trying to connect: %s" % ex)
464466

465467
def _close(self):
@@ -1314,7 +1316,7 @@ def _connect_to_db(self):
13141316
"Error establishing database connection: %s" % (six.text_type(e)),
13151317
limit_once_per_x_secs=300,
13161318
limit_key="mysql_connect_to_db",
1317-
exc_info=e
1319+
exc_info=e,
13181320
)
13191321

13201322
def gather_sample(self):

scalyr_agent/builtin_monitors/nginx_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"Always `scalyr_agent.builtin_monitors.nginx_monitor`",
3232
convert_to=six.text_type,
3333
required_option=True,
34-
allow_http=False
34+
allow_http=False,
3535
)
3636
define_config_option(
3737
__monitor__,

scalyr_agent/builtin_monitors/openmetrics_monitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"url",
130130
"URL to the OpenMetrics / Prometheus API endpoint (e.g. https://my.host:8080/metrics).",
131131
convert_to=six.text_type,
132-
allow_http=False
132+
allow_http=False,
133133
)
134134

135135
define_config_option(

0 commit comments

Comments
 (0)