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

upbound_uxp: filter one pod per replicaSet (ECOINT-108) #2606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 32 additions & 1 deletion upbound_uxp/datadog_checks/upbound_uxp/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ class UpboundUxpCheck(AgentCheck):
# name mapping requirements
{"go_memstats_heap_alloc_bytes"},
]
# filter only one pod per replica (default is false)
"filter_one_pod_per_replica": false
}
]
```
Expand Down Expand Up @@ -318,6 +320,12 @@ def __init__(self, name, init_config, instances):
if self.metrics_default not in METRICS_DEFAULTS:
self.metrics_default = 'min'

self.filter_one_pod_per_replica = instance.get('filter_one_pod_per_replica')
if self.filter_one_pod_per_replica is None:
self.filter_one_pod_per_replica = False
else:
self._raise_if_type_err(self.filter_one_pod_per_replica, 'filter_one_pod_per_replica', 'bool')

# Determine which exposed metrics to observe and
# feed into DataDog. Note, this will work without
# pod annotations.
Expand All @@ -336,6 +344,7 @@ def __init__(self, name, init_config, instances):
self.metrics_set = self._merge_conf()
if self.verbose:
self.log.debug(self.metrics_set)


super(UpboundUxpCheck, self).__init__(name, init_config, instances)

Expand Down Expand Up @@ -513,7 +522,29 @@ def check(self, instance):
return

port_forward_target = 8080
for pod in pods.items:

# If the feature flag to filter one pod per replica is enabled
if self.filter_one_pod_per_replica:
selected_pods = {}

for pod in pods.items:
# Identify the owner of the pod (Deployment, StatefulSet, etc.)
owner_references = pod.metadata.owner_references
owner_name = None
for owner in owner_references:
if owner.kind == "ReplicaSet":
owner_name = owner.name # The name of the ReplicaSet
break

if owner_name:
if owner_name not in selected_pods:
selected_pods[owner_name] = pod

filtered_pods = list(selected_pods.values())
else:
filtered_pods = pods.items

for pod in filtered_pods:
# Get Pod annotations to overwrite config file and
# default metric set. If no pod annotations are present
# then the upbound_uxp (auto_conf.yaml) config file
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## All options defined here are available to all instances.

Check failure on line 1 in upbound_uxp/datadog_checks/upbound_uxp/data/conf.yaml.example

View workflow job for this annotation

GitHub Actions / run / Validate

File `conf.yaml.example` is not in sync, run "ddev validate config upbound_uxp -s"
#
init_config:

Expand Down Expand Up @@ -53,3 +53,11 @@
# - <INCLUDE_REGEX>
# exclude:
# - <EXCLUDE_REGEX>

## @param filter_one_pod_per_replica - boolean - optional - default: false
## If enabled, only one pod per replica (e.g., ReplicaSet) will be selected for metric collection.
## This helps avoid duplicates when multiple pods are running on the same node.
##
## Default is `false`, meaning all pods will be considered.
#
# filter_one_pod_per_replica: false
Loading