Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(infra-monitoring): use proper metric names corresponding to entities to be counted (#12130)

Nikhil Mantri20e13f66e0f5
diff --git a/pkg/modules/inframonitoring/implinframonitoring/clusters_constants.go b/pkg/modules/inframonitoring/implinframonitoring/clusters_constants.go
index 919eb1f2be..7908ac7372 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/clusters_constants.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/clusters_constants.go
@@ -1,8 +1,6 @@
package implinframonitoring
import (
- "slices"
-
"github.com/SigNoz/signoz/pkg/types/inframonitoringtypes"
"github.com/SigNoz/signoz/pkg/types/metrictypes"
qbtypes "github.com/SigNoz/signoz/pkg/types/querybuildertypes/querybuildertypesv5"
@@ -51,11 +49,45 @@ var clusterCountAttrKeys = []string{
}
// clusterMetricNamesListForCounts is the metric universe for per-cluster distinct
-// counts. It unions the pod universe (carries namespace + workload owner labels)
-// with the cluster/node universe (carries k8s.node.name), so a single query can
-// count nodes, namespaces, and workloads per cluster. Overlapping pod
-// phase/status metrics are left in — harmless in a metric_name IN (...) list.
-var clusterMetricNamesListForCounts = slices.Concat(podsTableMetricNamesList, clustersTableMetricNamesList)
+// counts.
+var clusterMetricNamesListForCounts = []string{
+ // for nodes lookup
+ "k8s.node.cpu.usage",
+ "k8s.node.allocatable_cpu",
+ "k8s.node.memory.working_set",
+ "k8s.node.allocatable_memory",
+ "k8s.node.condition_ready",
+
+ // for daemonsets lookup
+ "k8s.daemonset.desired_scheduled_nodes",
+ "k8s.daemonset.current_scheduled_nodes",
+ "k8s.daemonset.ready_nodes",
+ "k8s.daemonset.misscheduled_nodes",
+
+ // for deployments lookup
+ "k8s.deployment.desired",
+ "k8s.deployment.available",
+
+ // for jobs lookup
+ "k8s.job.active_pods",
+ "k8s.job.failed_pods",
+ "k8s.job.successful_pods",
+ "k8s.job.desired_successful_pods",
+
+ // for statefulsets lookup
+ "k8s.statefulset.desired_pods",
+ "k8s.statefulset.current_pods",
+
+ // for namespaces and general lookup for all
+ "k8s.pod.cpu.usage",
+ "k8s.pod.cpu_request_utilization",
+ "k8s.pod.cpu_limit_utilization",
+ "k8s.pod.memory.working_set",
+ "k8s.pod.memory_request_utilization",
+ "k8s.pod.memory_limit_utilization",
+ "k8s.pod.phase",
+ "k8s.pod.status_reason",
+}
var orderByToClustersQueryNames = map[string][]string{
inframonitoringtypes.ClustersOrderByCPU: {"A"},
diff --git a/pkg/modules/inframonitoring/implinframonitoring/module.go b/pkg/modules/inframonitoring/implinframonitoring/module.go
index 95ba493fcc..6fb44222af 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/module.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/module.go
@@ -654,7 +654,7 @@ func (m *module) ListNamespaces(ctx context.Context, orgID valuer.UUID, req *inf
})
g.Go(func() error {
var err error
- resourceCounts, err = m.getPerGroupDistinctCounts(gCtx, orgID, req.Start, req.End, req.Filter, req.GroupBy, pageGroups, namespaceCountAttrKeys, namespacesTableMetricNamesList)
+ resourceCounts, err = m.getPerGroupDistinctCounts(gCtx, orgID, req.Start, req.End, req.Filter, req.GroupBy, pageGroups, namespaceCountAttrKeys, namespacesMetricNamesListForCounts)
return err
})
diff --git a/pkg/modules/inframonitoring/implinframonitoring/namespaces_constants.go b/pkg/modules/inframonitoring/implinframonitoring/namespaces_constants.go
index 7719eaacbc..630759e42f 100644
--- a/pkg/modules/inframonitoring/implinframonitoring/namespaces_constants.go
+++ b/pkg/modules/inframonitoring/implinframonitoring/namespaces_constants.go
@@ -27,6 +27,38 @@ var namespacesTableMetricNamesList = []string{
"k8s.container.status.reason",
}
+var namespacesMetricNamesListForCounts = []string{
+ // for daemonsets lookup
+ "k8s.daemonset.desired_scheduled_nodes",
+ "k8s.daemonset.current_scheduled_nodes",
+ "k8s.daemonset.ready_nodes",
+ "k8s.daemonset.misscheduled_nodes",
+
+ // for deployments lookup
+ "k8s.deployment.desired",
+ "k8s.deployment.available",
+
+ // for jobs lookup
+ "k8s.job.active_pods",
+ "k8s.job.failed_pods",
+ "k8s.job.successful_pods",
+ "k8s.job.desired_successful_pods",
+
+ // for statefulsets lookup
+ "k8s.statefulset.desired_pods",
+ "k8s.statefulset.current_pods",
+
+ // for general lookup for all
+ "k8s.pod.cpu.usage",
+ "k8s.pod.cpu_request_utilization",
+ "k8s.pod.cpu_limit_utilization",
+ "k8s.pod.memory.working_set",
+ "k8s.pod.memory_request_utilization",
+ "k8s.pod.memory_limit_utilization",
+ "k8s.pod.phase",
+ "k8s.pod.status_reason",
+}
+
var namespaceAttrKeysForMetadata = []string{
"k8s.namespace.name",
"k8s.cluster.name",
diff --git a/tests/integration/testdata/inframonitoring/clusters_value_accuracy.jsonl b/tests/integration/testdata/inframonitoring/clusters_value_accuracy.jsonl
index b14ba1f752..4b36405627 100644
--- a/tests/integration/testdata/inframonitoring/clusters_value_accuracy.jsonl
+++ b/tests/integration/testdata/inframonitoring/clusters_value_accuracy.jsonl
@@ -91,3 +91,9 @@
{"metric_name":"k8s.pod.phase","labels":{"k8s.pod.uid":"acc-c2-n3-p-uid","k8s.pod.name":"acc-c2-n3-p","k8s.namespace.name":"ns-y","k8s.node.name":"acc-c2-n3","k8s.cluster.name":"acc-cluster-2","k8s.job.name":"job-b"},"timestamp":"2025-01-10T10:00:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false}
{"metric_name":"k8s.pod.phase","labels":{"k8s.pod.uid":"acc-c2-n3-p-uid","k8s.pod.name":"acc-c2-n3-p","k8s.namespace.name":"ns-y","k8s.node.name":"acc-c2-n3","k8s.cluster.name":"acc-cluster-2","k8s.job.name":"job-b"},"timestamp":"2025-01-10T10:02:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false}
{"metric_name":"k8s.pod.phase","labels":{"k8s.pod.uid":"acc-c2-n3-p-uid","k8s.pod.name":"acc-c2-n3-p","k8s.namespace.name":"ns-y","k8s.node.name":"acc-c2-n3","k8s.cluster.name":"acc-cluster-2","k8s.job.name":"job-b"},"timestamp":"2025-01-10T10:04:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false}
+{"metric_name": "k8s.daemonset.ready_nodes", "labels": {"k8s.daemonset.name": "ds-orphan", "k8s.namespace.name": "ns-x", "k8s.cluster.name": "acc-cluster-1"}, "timestamp": "2025-01-10T10:00:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.daemonset.ready_nodes", "labels": {"k8s.daemonset.name": "ds-orphan", "k8s.namespace.name": "ns-x", "k8s.cluster.name": "acc-cluster-1"}, "timestamp": "2025-01-10T10:02:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.daemonset.ready_nodes", "labels": {"k8s.daemonset.name": "ds-orphan", "k8s.namespace.name": "ns-x", "k8s.cluster.name": "acc-cluster-1"}, "timestamp": "2025-01-10T10:04:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.job.active_pods", "labels": {"k8s.job.name": "job-orphan", "k8s.namespace.name": "ns-x", "k8s.cluster.name": "acc-cluster-1"}, "timestamp": "2025-01-10T10:00:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.job.active_pods", "labels": {"k8s.job.name": "job-orphan", "k8s.namespace.name": "ns-x", "k8s.cluster.name": "acc-cluster-1"}, "timestamp": "2025-01-10T10:02:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.job.active_pods", "labels": {"k8s.job.name": "job-orphan", "k8s.namespace.name": "ns-x", "k8s.cluster.name": "acc-cluster-1"}, "timestamp": "2025-01-10T10:04:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
diff --git a/tests/integration/testdata/inframonitoring/clusters_value_accuracy_expected.json b/tests/integration/testdata/inframonitoring/clusters_value_accuracy_expected.json
index 9605621f46..fc5049df4e 100644
--- a/tests/integration/testdata/inframonitoring/clusters_value_accuracy_expected.json
+++ b/tests/integration/testdata/inframonitoring/clusters_value_accuracy_expected.json
@@ -21,8 +21,8 @@
"nodes": 2,
"namespaces": 2,
"deployments": 2,
- "daemonSets": 0,
- "jobs": 0,
+ "daemonSets": 1,
+ "jobs": 1,
"statefulSets": 1
}
},
diff --git a/tests/integration/testdata/inframonitoring/namespaces_value_accuracy.jsonl b/tests/integration/testdata/inframonitoring/namespaces_value_accuracy.jsonl
index 538a932eb0..fec93ca952 100644
--- a/tests/integration/testdata/inframonitoring/namespaces_value_accuracy.jsonl
+++ b/tests/integration/testdata/inframonitoring/namespaces_value_accuracy.jsonl
@@ -43,3 +43,9 @@
{"metric_name":"k8s.pod.phase","labels":{"k8s.pod.uid":"acc-p2c-uid","k8s.pod.name":"acc-p2c","k8s.namespace.name":"acc-ns-2","k8s.cluster.name":"cluster-y","k8s.job.name":"batch"},"timestamp":"2025-01-10T10:00:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false}
{"metric_name":"k8s.pod.phase","labels":{"k8s.pod.uid":"acc-p2c-uid","k8s.pod.name":"acc-p2c","k8s.namespace.name":"acc-ns-2","k8s.cluster.name":"cluster-y","k8s.job.name":"batch"},"timestamp":"2025-01-10T10:02:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false}
{"metric_name":"k8s.pod.phase","labels":{"k8s.pod.uid":"acc-p2c-uid","k8s.pod.name":"acc-p2c","k8s.namespace.name":"acc-ns-2","k8s.cluster.name":"cluster-y","k8s.job.name":"batch"},"timestamp":"2025-01-10T10:04:00+00:00","value":2,"temporality":"Unspecified","type_":"Gauge","is_monotonic":false}
+{"metric_name": "k8s.daemonset.ready_nodes", "labels": {"k8s.daemonset.name": "ds-orphan", "k8s.namespace.name": "acc-ns-1", "k8s.cluster.name": "cluster-x"}, "timestamp": "2025-01-10T10:00:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.daemonset.ready_nodes", "labels": {"k8s.daemonset.name": "ds-orphan", "k8s.namespace.name": "acc-ns-1", "k8s.cluster.name": "cluster-x"}, "timestamp": "2025-01-10T10:02:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.daemonset.ready_nodes", "labels": {"k8s.daemonset.name": "ds-orphan", "k8s.namespace.name": "acc-ns-1", "k8s.cluster.name": "cluster-x"}, "timestamp": "2025-01-10T10:04:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.job.active_pods", "labels": {"k8s.job.name": "job-orphan", "k8s.namespace.name": "acc-ns-1", "k8s.cluster.name": "cluster-x"}, "timestamp": "2025-01-10T10:00:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.job.active_pods", "labels": {"k8s.job.name": "job-orphan", "k8s.namespace.name": "acc-ns-1", "k8s.cluster.name": "cluster-x"}, "timestamp": "2025-01-10T10:02:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
+{"metric_name": "k8s.job.active_pods", "labels": {"k8s.job.name": "job-orphan", "k8s.namespace.name": "acc-ns-1", "k8s.cluster.name": "cluster-x"}, "timestamp": "2025-01-10T10:04:00+00:00", "value": 1, "temporality": "Unspecified", "type_": "Gauge", "is_monotonic": false}
diff --git a/tests/integration/testdata/inframonitoring/namespaces_value_accuracy_expected.json b/tests/integration/testdata/inframonitoring/namespaces_value_accuracy_expected.json
index 3d9e93e2d1..bcd683b1ad 100644
--- a/tests/integration/testdata/inframonitoring/namespaces_value_accuracy_expected.json
+++ b/tests/integration/testdata/inframonitoring/namespaces_value_accuracy_expected.json
@@ -5,7 +5,7 @@
"namespaceCPU": 1.0,
"namespaceMemory": 200000000.0,
"podCountsByPhase": {"pending": 0, "running": 2, "succeeded": 0, "failed": 0, "unknown": 0},
- "counts": {"deployments": 2, "daemonSets": 0, "jobs": 0, "statefulSets": 0}
+ "counts": {"deployments": 2, "daemonSets": 1, "jobs": 1, "statefulSets": 0}
},
{
"namespaceName": "acc-ns-2",