Skip to content

Commit

Permalink
Merge pull request #877 from abursavich/node-roles
Browse files Browse the repository at this point in the history
store: add kube_node_role metric
  • Loading branch information
k8s-ci-robot authored Sep 5, 2019
2 parents a947300 + 347ec08 commit 087e74f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/node-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
| ---------- | ----------- | ----------- | ----------- |
| kube_node_info | Gauge | `node`=&lt;node-address&gt; <br> `kernel_version`=&lt;kernel-version&gt; <br> `os_image`=&lt;os-image-name&gt; <br> `container_runtime_version`=&lt;container-runtime-and-version-combination&gt; <br> `kubelet_version`=&lt;kubelet-version&gt; <br> `kubeproxy_version`=&lt;kubeproxy-version&gt; <br> `provider_id`=&lt;provider-id&gt; | STABLE |
| kube_node_labels | Gauge | `node`=&lt;node-address&gt; <br> `label_NODE_LABEL`=&lt;NODE_LABEL&gt; | STABLE |
| kube_node_role | Gauge | `node`=&lt;node-address&gt; <br> `role`=&lt;NODE_ROLE&gt; | EXPERIMENTAL |
| kube_node_spec_unschedulable | Gauge | `node`=&lt;node-address&gt;|
| kube_node_spec_taint | Gauge | `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_phase| Gauge | `node`=&lt;node-address&gt; <br> `phase`=&lt;Pending\|Running\|Terminated&gt; | DEPRECATED |
Expand Down
23 changes: 23 additions & 0 deletions internal/store/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package store

import (
"strings"

"k8s.io/kube-state-metrics/pkg/constant"
"k8s.io/kube-state-metrics/pkg/metric"

Expand Down Expand Up @@ -100,6 +102,27 @@ var (
}
}),
},
{
Name: "kube_node_role",
Type: metric.Gauge,
Help: "The role of a cluster node.",
GenerateFunc: wrapNodeFunc(func(n *v1.Node) *metric.Family {
const prefix = "node-role.kubernetes.io/"
ms := []*metric.Metric{}
for lbl := range n.Labels {
if strings.HasPrefix(lbl, prefix) {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"role"},
LabelValues: []string{strings.TrimPrefix(lbl, prefix)},
Value: float64(1),
})
}
}
return &metric.Family{
Metrics: ms,
}
}),
},
{
Name: "kube_node_spec_unschedulable",
Type: metric.Gauge,
Expand Down
23 changes: 20 additions & 3 deletions internal/store/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestNodeStore(t *testing.T) {
Name: "127.0.0.1",
CreationTimestamp: metav1.Time{Time: time.Unix(1500000000, 0)},
Labels: map[string]string{
"type": "master",
"node-role.kubernetes.io/master": "",
},
},
Spec: v1.NodeSpec{
Expand Down Expand Up @@ -105,6 +105,7 @@ func TestNodeStore(t *testing.T) {
# HELP kube_node_created Unix creation timestamp
# HELP kube_node_info Information about a cluster node.
# HELP kube_node_labels Kubernetes labels converted to Prometheus labels.
# HELP kube_node_role The role of a cluster node.
# HELP kube_node_spec_unschedulable Whether a node can schedule new pods.
# HELP kube_node_status_allocatable The allocatable for different resources of a node that are available for scheduling.
# HELP kube_node_status_allocatable_cpu_cores The CPU resources of a node that are available for scheduling.
Expand All @@ -117,6 +118,7 @@ func TestNodeStore(t *testing.T) {
# TYPE kube_node_created gauge
# TYPE kube_node_info gauge
# TYPE kube_node_labels gauge
# TYPE kube_node_role gauge
# TYPE kube_node_spec_unschedulable gauge
# TYPE kube_node_status_allocatable gauge
# TYPE kube_node_status_allocatable_cpu_cores gauge
Expand All @@ -128,7 +130,8 @@ func TestNodeStore(t *testing.T) {
# TYPE kube_node_status_capacity_pods gauge
kube_node_created{node="127.0.0.1"} 1.5e+09
kube_node_info{container_runtime_version="rkt",kernel_version="kernel",kubelet_version="kubelet",kubeproxy_version="kubeproxy",node="127.0.0.1",os_image="osimage",provider_id="provider://i-randomidentifier"} 1
kube_node_labels{label_type="master",node="127.0.0.1"} 1
kube_node_labels{label_node_role_kubernetes_io_master="",node="127.0.0.1"} 1
kube_node_role{node="127.0.0.1",role="master"} 1
kube_node_spec_unschedulable{node="127.0.0.1"} 1
kube_node_status_allocatable_cpu_cores{node="127.0.0.1"} 3
kube_node_status_allocatable_memory_bytes{node="127.0.0.1"} 1e+09
Expand All @@ -149,7 +152,21 @@ func TestNodeStore(t *testing.T) {
kube_node_status_capacity{node="127.0.0.1",resource="pods",unit="integer"} 1000
kube_node_status_capacity{node="127.0.0.1",resource="storage",unit="byte"} 3e+09
`,
MetricNames: []string{"kube_node_status_capacity", "kube_node_status_capacity_pods", "kube_node_status_capacity_memory_bytes", "kube_node_status_capacity_cpu_cores", "kube_node_status_allocatable", "kube_node_status_allocatable_pods", "kube_node_status_allocatable_memory_bytes", "kube_node_status_allocatable_cpu_cores", "kube_node_spec_unschedulable", "kube_node_labels", "kube_node_info", "kube_node_created"},
MetricNames: []string{
"kube_node_status_capacity",
"kube_node_status_capacity_pods",
"kube_node_status_capacity_memory_bytes",
"kube_node_status_capacity_cpu_cores",
"kube_node_status_allocatable",
"kube_node_status_allocatable_pods",
"kube_node_status_allocatable_memory_bytes",
"kube_node_status_allocatable_cpu_cores",
"kube_node_spec_unschedulable",
"kube_node_labels",
"kube_node_role",
"kube_node_info",
"kube_node_created",
},
},
// Verify phase enumerations.
{
Expand Down

0 comments on commit 087e74f

Please sign in to comment.