Skip to content
Merged
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
10 changes: 10 additions & 0 deletions constructor/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@ func podLabels(metrics []*model.MetricValues, pods map[string]*model.Instance) {
cluster = m.Labels["label_stackgres_io_cluster_name"]
role = m.Labels["label_role"]
manager = model.ClusterManagerStackGres
// Altinity clickhouse-operator: one StatefulSet per replica, so the
// replicas are joined by the installation name. Keeper pods of an
// installation may carry its chi label too; they form their own cluster.
case m.Labels["label_clickhouse_keeper_altinity_com_chk"] != "":
cluster = m.Labels["label_clickhouse_keeper_altinity_com_chk"]
case m.Labels["label_clickhouse_altinity_com_chi"] != "":
cluster = m.Labels["label_clickhouse_altinity_com_chi"]
// OpenSearch operator: one StatefulSet per node pool (job pods have no node pool).
case m.Labels["label_opensearch_org_opensearch_cluster"] != "" && m.Labels["label_opensearch_org_opensearch_nodepool"] != "":
cluster = m.Labels["label_opensearch_org_opensearch_cluster"]
case m.Labels["label_app_kubernetes_io_managed_by"] == "percona-server-mongodb-operator":
cluster = m.Labels["label_app_kubernetes_io_instance"]
manager = model.ClusterManagerPerconaMongoDB
Expand Down
60 changes: 60 additions & 0 deletions constructor/k8s_cluster_labels_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package constructor

import (
"testing"

"github.com/coroot/coroot/model"
"github.com/coroot/coroot/timeseries"
)

func TestPodLabelsOperatorClusters(t *testing.T) {
values := timeseries.New(0, 2, 15)
values.Set(0, 1)
values.Set(15, 1)

cases := []struct {
name string
labels model.Labels
cluster string
}{
{
name: "clickhouse replica",
labels: model.Labels{"label_clickhouse_altinity_com_chi": "ch"},
cluster: "ch",
},
{
name: "clickhouse keeper carrying the installation label",
labels: model.Labels{
"label_clickhouse_keeper_altinity_com_chk": "ch-k",
"label_clickhouse_altinity_com_chi": "ch",
},
cluster: "ch-k",
},
{
name: "opensearch node",
labels: model.Labels{
"label_opensearch_org_opensearch_cluster": "search",
"label_opensearch_org_opensearch_nodepool": "nodes",
},
cluster: "search",
},
{
name: "opensearch job pod (no node pool)",
labels: model.Labels{"label_opensearch_org_opensearch_cluster": "search"},
cluster: "",
},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
instance := &model.Instance{}
labels := model.Labels{"uid": "u1"}
for k, v := range c.labels {
labels[k] = v
}
podLabels([]*model.MetricValues{{Labels: labels, Values: values}}, map[string]*model.Instance{"u1": instance})
if got := instance.ClusterName.Value(); got != c.cluster {
t.Fatalf("cluster = %q, want %q", got, c.cluster)
}
})
}
}
2 changes: 2 additions & 0 deletions constructor/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ var QUERIES = []Query{
"label_app_kubernetes_io_name",
"label_app_kubernetes_io_component", "label_app_kubernetes_io_part_of",
"label_valkey_io_cluster",
"label_clickhouse_altinity_com_chi", "label_clickhouse_keeper_altinity_com_chk",
"label_opensearch_org_opensearch_cluster", "label_opensearch_org_opensearch_nodepool",
),
qPod("kube_pod_status_phase", `kube_pod_status_phase > 0`, "phase"),
qPod("kube_pod_status_ready", `kube_pod_status_ready{condition="true"}`),
Expand Down
Loading