Skip to content

Commit

Permalink
fix(targetallocator): support endpointslice (fixes #2718) (#2720)
Browse files Browse the repository at this point in the history
The standard setup for collecting kubelet metrics, using a service with
no selector to point at each node, results in targets without the
`__meta_kubernetes_endpoint_node_name` label, instead it includes:

```yaml
labels:
  "__meta_kubernetes_endpointslice_address_target_kind": "Node"
  "__meta_kubernetes_endpointslice_address_target_name": "mynode"
```

This update handles this situation.

Signed-off-by: Tristan Colgate-McFarlane <[email protected]>
  • Loading branch information
tcolgate authored Mar 6, 2024
1 parent 3c85a52 commit c8796df
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
11 changes: 10 additions & 1 deletion cmd/otel-allocator/allocation/per_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestAllocationPerNode(t *testing.T) {
// prepare allocator with initial targets and collectors
s, _ := New("per-node", loggerPerNode)

cols := MakeNCollectors(3, 0)
cols := MakeNCollectors(4, 0)
s.SetCollectors(cols)
firstLabels := model.LabelSet{
"test": "test1",
Expand All @@ -45,14 +45,23 @@ func TestAllocationPerNode(t *testing.T) {
thirdLabels := model.LabelSet{
"test": "test3",
}
// endpointslice target kind and name
fourthLabels := model.LabelSet{
"test": "test4",
"__meta_kubernetes_endpointslice_address_target_kind": "Node",
"__meta_kubernetes_endpointslice_address_target_name": "node-3",
}

firstTarget := target.NewItem("sample-name", "0.0.0.0:8000", firstLabels, "")
secondTarget := target.NewItem("sample-name", "0.0.0.0:8000", secondLabels, "")
thirdTarget := target.NewItem("sample-name", "0.0.0.0:8000", thirdLabels, "")
fourthTarget := target.NewItem("sample-name", "0.0.0.0:8000", fourthLabels, "")

targetList := map[string]*target.Item{
firstTarget.Hash(): firstTarget,
secondTarget.Hash(): secondTarget,
thirdTarget.Hash(): thirdTarget,
fourthTarget.Hash(): fourthTarget,
}

// test that targets and collectors are added properly
Expand Down
20 changes: 14 additions & 6 deletions cmd/otel-allocator/target/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ import (
// nodeLabels are labels that are used to identify the node on which the given
// target is residing. To learn more about these labels, please refer to:
// https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config
var nodeLabels = []model.LabelName{
"__meta_kubernetes_pod_node_name",
"__meta_kubernetes_node_name",
"__meta_kubernetes_endpoint_node_name",
}
var (
nodeLabels = []model.LabelName{
"__meta_kubernetes_pod_node_name",
"__meta_kubernetes_node_name",
"__meta_kubernetes_endpoint_node_name",
}
endpointSliceTargetKindLabel model.LabelName = "__meta_kubernetes_endpointslice_address_target_kind"
endpointSliceTargetNameLabel model.LabelName = "__meta_kubernetes_endpointslice_address_target_name"
)

// LinkJSON This package contains common structs and methods that relate to scrape targets.
type LinkJSON struct {
Expand All @@ -55,7 +59,11 @@ func (t *Item) GetNodeName() string {
}
}

return ""
if val := t.Labels[endpointSliceTargetKindLabel]; val != "Node" {
return ""
}

return string(t.Labels[endpointSliceTargetNameLabel])
}

// NewItem Creates a new target item.
Expand Down

0 comments on commit c8796df

Please sign in to comment.