def is_excluded(self, cid, pod_uid=None): """ Queries the agent6 container filter interface. It retrieves container name + image from the podlist, so static pod filtering is not supported. Result is cached between calls to avoid the python-go switching cost for prometheus metrics (will be called once per metric) :param cid: container id :param pod_uid: pod UID for static pod detection :return: bool """ if not cid: return True if cid in self.cache: return self.cache[cid] if pod_uid and pod_uid in self.static_pod_uids: self.cache[cid] = False return False if cid not in self.containers: # Filter out metrics not coming from a container (system slices) self.cache[cid] = True return True ctr = self.containers[cid] if not ("name" in ctr and "image" in ctr): # Filter out invalid containers self.cache[cid] = True return True excluded = is_excluded(ctr.get("name"), ctr.get("image")) self.cache[cid] = excluded return excluded
def check(self, instance): for c in containers: excluded = is_excluded(c[0], c[1]) if excluded != c[2]: self.warning("Error, got {} for {}".format(excluded, c))