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

feat: add kube_node_status_addresses metric #2252

Merged
merged 2 commits into from
Dec 14, 2023
Merged
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
1 change: 1 addition & 0 deletions docs/node-metrics.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
| kube_node_spec_unschedulable | Gauge | Whether a node can schedule new pods | | `node`=<node-address> | STABLE |
| kube_node_spec_taint | Gauge | The taint of a cluster node. | | `node`=&lt;node-address&gt; <br> `key`=&lt;taint-key&gt; <br> `value=`&lt;taint-value&gt; <br> `effect=`&lt;taint-effect&gt; | STABLE |
| kube_node_status_capacity | Gauge | The total amount of resources available for a node | `cpu`=&lt;core&gt; <br> `ephemeral_storage`=&lt;byte&gt; <br> `pods`=&lt;integer&gt; <br> `attachable_volumes_*`=&lt;byte&gt; <br> `hugepages_*`=&lt;byte&gt; <br> `memory`=&lt;byte&gt; | `node`=&lt;node-address&gt; <br> `resource`=&lt;resource-name&gt; <br> `unit`=&lt;resource-unit&gt; | STABLE |
| kube_node_status_addresses | Gauge | The addresses of a node | | `node`=&lt;node-address&gt; <br> `type`=&lt;address-type&gt; <br> `address`=&lt;address-value&gt; | EXPERIMENTAL |
| kube_node_status_allocatable | Gauge | The amount of resources allocatable for pods (after reserving some for system daemons) | `cpu`=&lt;core&gt; <br> `ephemeral_storage`=&lt;byte&gt; <br> `pods`=&lt;integer&gt; <br> `attachable_volumes_*`=&lt;byte&gt; <br> `hugepages_*`=&lt;byte&gt; <br> `memory`=&lt;byte&gt; | `node`=&lt;node-address&gt; <br> `resource`=&lt;resource-name&gt; <br> `unit`=&lt;resource-unit&gt; | STABLE |
| kube_node_status_condition | Gauge | The condition of a cluster node | | `node`=&lt;node-address&gt; <br> `condition`=&lt;node-condition&gt; <br> `status`=&lt;true\|false\|unknown&gt; | STABLE |
| kube_node_created | Gauge | Unix creation timestamp | seconds | `node`=&lt;node-address&gt; | STABLE |
25 changes: 25 additions & 0 deletions internal/store/node.go
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@ func nodeMetricFamilies(allowAnnotationsList, allowLabelsList []string) []genera
createNodeStatusAllocatableFamilyGenerator(),
createNodeStatusCapacityFamilyGenerator(),
createNodeStatusConditionFamilyGenerator(),
createNodeStateAddressFamilyGenerator(),
}
}

@@ -105,6 +106,29 @@ func createNodeCreatedFamilyGenerator() generator.FamilyGenerator {
)
}

func createNodeStateAddressFamilyGenerator() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_node_status_addresses",
"Node address information.",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapNodeFunc(func(n *v1.Node) *metric.Family {
ms := []*metric.Metric{}
for _, address := range n.Status.Addresses {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"type", "address"},
LabelValues: []string{string(address.Type), address.Address},
Value: 1,
})
}
return &metric.Family{
Metrics: ms,
}
}),
)
}

func createNodeInfoFamilyGenerator() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_node_info",
@@ -134,6 +158,7 @@ func createNodeInfoFamilyGenerator() generator.FamilyGenerator {
n.Status.NodeInfo.SystemUUID,
}

// TODO: remove internal_ip in v3, replaced by kube_node_status_addresses
internalIP := ""
for _, address := range n.Status.Addresses {
if address.Type == "InternalIP" {
24 changes: 24 additions & 0 deletions internal/store/node_test.go
Original file line number Diff line number Diff line change
@@ -274,6 +274,30 @@ func TestNodeStore(t *testing.T) {
`,
MetricNames: []string{"kube_node_spec_taint"},
},
{
Obj: &v1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "127.0.0.1",
},
Status: v1.NodeStatus{
Addresses: []v1.NodeAddress{
{Type: "InternalIP", Address: "1.2.3.4"},
{Type: "InternalIP", Address: "fc00::"},
{Type: "ExternalIP", Address: "5.6.7.8"},
{Type: "ExternalIP", Address: "2001:db8::"},
},
},
},
Want: `
# HELP kube_node_status_addresses Node address information.
# TYPE kube_node_status_addresses gauge
kube_node_status_addresses{node="127.0.0.1",type="InternalIP",address="1.2.3.4"} 1
kube_node_status_addresses{node="127.0.0.1",type="InternalIP",address="fc00::"} 1
kube_node_status_addresses{node="127.0.0.1",type="ExternalIP",address="5.6.7.8"} 1
kube_node_status_addresses{node="127.0.0.1",type="ExternalIP",address="2001:db8::"} 1
`,
MetricNames: []string{"kube_node_status_addresses"},
},
}
for i, c := range cases {
c.Func = generator.ComposeMetricGenFuncs(nodeMetricFamilies(nil, nil))