Skip to content

Commit b502258

Browse files
authored
Release 2.2.15 (#1271)
1 parent 76e3704 commit b502258

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+638
-1045
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
Scalyr Agent 2 Changes By Release
22
=================================
33

4+
## 2.2.15 "Jain" - May 20, 2024
5+
<!---
6+
Packaged by Ales Novak <[email protected]> on May 20, 2024 00:00 -0800
7+
--->
8+
9+
Features:
10+
Ability to ignore k8s labels (https://github.com/scalyr/scalyr-agent-2/issues/1213).
11+
A user can now define glob filters for including and excluding container and controller labels in logs.
12+
For label to be included it needs to match one of the globs in k8s_label_include_globs and none of the globs in k8s_label_exclude_globs.
13+
14+
From documentation:
15+
| k8s_label_include_globs | Optional, (defaults to ['*']). Specifies a list of K8s labels to be added to logs. |
16+
| k8s_label_exclude_globs | Optional, (defaults to []]). Specifies a list of K8s labels to be ignored and not added to logs. |
17+
18+
Follows the same logic as label_include_globs and label_exclude_globs from the docker_monitor.
19+
420
## 2.2.14 "Tycho" - May 6, 2024
521
<!---
622
Packaged by Ales Novak <[email protected]> on May 6, 2024 00:00 -0800

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.14
1+
2.2.15

k8s/default-namespace/scalyr-agent-2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
envFrom:
5151
- configMapRef:
5252
name: scalyr-config
53-
image: scalyr/scalyr-k8s-agent:2.2.14
53+
image: scalyr/scalyr-k8s-agent:2.2.15
5454
imagePullPolicy: Always
5555
name: scalyr-agent
5656
securityContext:

k8s/no-kustomize/scalyr-agent-2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ spec:
5050
envFrom:
5151
- configMapRef:
5252
name: scalyr-config
53-
image: scalyr/scalyr-k8s-agent:2.2.14
53+
image: scalyr/scalyr-k8s-agent:2.2.15
5454
imagePullPolicy: Always
5555
name: scalyr-agent
5656
securityContext:

k8s/scalyr-agent-2-envfrom.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ spec:
4949
envFrom:
5050
- configMapRef:
5151
name: scalyr-config
52-
image: scalyr/scalyr-k8s-agent:2.2.14
52+
image: scalyr/scalyr-k8s-agent:2.2.15
5353
imagePullPolicy: Always
5454
name: scalyr-agent
5555
securityContext:

k8s/scalyr-agent-2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ spec:
4949
envFrom:
5050
- configMapRef:
5151
name: scalyr-config
52-
image: scalyr/scalyr-k8s-agent:2.2.14
52+
image: scalyr/scalyr-k8s-agent:2.2.15
5353
imagePullPolicy: Always
5454
name: scalyr-agent
5555
securityContext:

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: 45 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@
7171
KubeletApiException,
7272
K8sApiTemporaryError,
7373
K8sConfigBuilder,
74-
K8sNamespaceFilter,
75-
KubernetesCache,
74+
K8sNamespaceFilter, KubernetesCache,
7675
)
7776
from scalyr_agent.monitor_utils.k8s import (
7877
K8sApiPermanentError,
@@ -297,7 +296,7 @@
297296
"DEPRECATED.",
298297
convert_to=six.text_type,
299298
default="https://kubernetes.default",
300-
allow_http=False,
299+
allow_http=False
301300
)
302301

303302
define_config_option(
@@ -425,7 +424,7 @@
425424
convert_to=six.text_type,
426425
default="https://${host_ip}:10250",
427426
env_aware=True,
428-
allow_http=False,
427+
allow_http=False
429428
)
430429

431430
define_config_option(
@@ -2353,6 +2352,7 @@ def _get_containers(
23532352
if not k8s_include_by_default:
23542353
continue
23552354

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

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

26762675
self.__node_name = None
@@ -2686,8 +2685,8 @@ def __init__(
26862685
self.__controlled_warmer = controlled_warmer
26872686

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

26922691
self.__stopped = False
26932692

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

3070-
namespace = self.k8s_cache.namespace(
3071-
pod_namespace,
3072-
current_time=current_time,
3073-
allow_expired=False,
3074-
)
3069+
namespace = self.k8s_cache.namespace(pod_namespace, current_time=current_time, allow_expired=False)
30753070
# start the container if have a container that wasn't running
30763071
if cid not in self.containers:
30773072
self._logger.log(
@@ -3082,14 +3077,10 @@ def check_containers(self, run_state):
30823077
elif cid in prev_digests or cid in prev_digests_namespaces:
30833078
# container was running and it exists in the previous digest dict, so see if
30843079
# it has changed
3085-
if (pod and prev_digests[cid] != pod.digest) or (
3086-
namespace
3087-
and prev_digests_namespaces[cid] != namespace.digest
3088-
):
3080+
if (pod and prev_digests[cid] != pod.digest) or (namespace and prev_digests_namespaces[cid] != namespace.digest):
30893081
self._logger.log(
30903082
scalyr_logging.DEBUG_LEVEL_1,
3091-
"Pod or namespace digest changed for '%s/%s'"
3092-
% (namespace.name, info["name"]),
3083+
"Pod or namespace digest changed for '%s/%s'" % (namespace.name, info["name"]),
30933084
)
30943085
changed[cid] = info
30953086

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

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-
)
3131+
logger.log_configs = self.__log_watcher.update_log_configs_on_path(
3132+
info["log_path"], self.__module.module_name, new_configs
31463133
)
31473134
else:
31483135
self._logger.log(
@@ -3207,11 +3194,9 @@ def __start_docker_logs(self, docker_logs):
32073194
if self.__log_watcher:
32083195
updated_log_configs = []
32093196
for log_config in log.log_configs:
3210-
updated_log_configs.append(
3211-
self.__log_watcher.add_log_config(
3212-
self.__module.module_name, log_config, force_add=True
3213-
)
3214-
)
3197+
updated_log_configs.append(self.__log_watcher.add_log_config(
3198+
self.__module.module_name, log_config, force_add=True
3199+
))
32153200
log.log_configs = updated_log_configs
32163201

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

35263511
self._logger.log(
35273512
scalyr_logging.DEBUG_LEVEL_0,
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-
),
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)
35383515
)
35393516

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

35643530
return results
35653531

3566-
def __container_api_keys_from_annotations(
3567-
self, k8s_cache, namespace, annotations, annotation_kind, container_name
3568-
):
3532+
def __container_api_keys_from_annotations(self, k8s_cache, namespace, annotations, annotation_kind, container_name):
35693533
def fetch_secret(name):
35703534
if not name:
35713535
return None
@@ -3582,45 +3546,48 @@ def fetch_secret(name):
35823546
)
35833547

35843548
self._logger.warning(
3585-
"Failed to fetch secret '%s/%s', ignoring." % (namespace, name),
3549+
"Failed to fetch secret '%s/%s', ignoring."
3550+
% (namespace, name),
35863551
limit_once_per_x_secs=300,
35873552
limit_key="k8s-fetch-secret-%s/%s" % (namespace, name),
35883553
)
35893554

35903555
def get_secret_api_key(secret):
35913556
if not secret:
35923557
return None
3593-
api_key = base64.b64decode(secret.data.get("scalyr-api-key")).decode(
3594-
"utf-8"
3595-
)
3558+
api_key = base64.b64decode(secret.data.get("scalyr-api-key")).decode("utf-8")
35963559

35973560
if not api_key:
35983561
self._logger.warning(
35993562
"Secret '%s/%s' does not contain a scalyr-api-key field, ingoring."
36003563
% (namespace, secret.name),
36013564
limit_once_per_x_secs=300,
3602-
limit_key="k8s-fetch-secret-%s" % secret.name,
3565+
limit_key="k8s-fetch-secret-%s" % secret.name
36033566
)
36043567

36053568
return api_key
36063569

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

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

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

36133587
self._logger.log(
36143588
scalyr_logging.DEBUG_LEVEL_0,
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-
),
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))
36243591
)
36253592

36263593
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: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,7 @@ 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(
463-
"Exception trying to connect occured: %s" % ex, exc_info=ex
464-
)
462+
self._logger.error("Exception trying to connect occured: %s" % ex, exc_info=ex)
465463
raise Exception("Exception trying to connect: %s" % ex)
466464

467465
def _close(self):
@@ -1316,7 +1314,7 @@ def _connect_to_db(self):
13161314
"Error establishing database connection: %s" % (six.text_type(e)),
13171315
limit_once_per_x_secs=300,
13181316
limit_key="mysql_connect_to_db",
1319-
exc_info=e,
1317+
exc_info=e
13201318
)
13211319

13221320
def gather_sample(self):

0 commit comments

Comments
 (0)