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_ingress_status metric #2433

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/metrics/service/ingress-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
| kube_ingress_metadata_resource_version | Gauge | | `ingress`=&lt;ingress-name&gt; <br> `namespace`=&lt;ingress-namespace&gt; | EXPERIMENTAL |
| kube_ingress_path | Gauge | | `ingress`=&lt;ingress-name&gt; <br> `namespace`=&lt;ingress-namespace&gt; <br> `host`=&lt;ingress-host&gt; <br> `path`=&lt;ingress-path&gt; <br><i> If path served by Service Backend</i> <br> `service_name`=&lt;service name for the path&gt; <br> `service_port`=&lt;service port for the path&gt;<br><i> If path served by Resource Backend</i><br> `resource_api_group`=&lt;resource backend api group&gt; <br> `resource_kind`=&lt;resource backend kind&gt; <br> `resource_name`=&lt;resource backend name&gt; | STABLE |
| kube_ingress_tls | Gauge | | `ingress`=&lt;ingress-name&gt; <br> `namespace`=&lt;ingress-namespace&gt; <br> `tls_host`=&lt;tls hostname&gt; <br> `secret`=&lt;tls secret name&gt; | STABLE |
| kube_ingress_status | Gauge | | `ingress`=&lt;ingress-name&gt; <br> `namespace`=&lt;ingress-namespace&gt; <br> `hostname`=&lt;hostname&gt; <br> `port`=&lt;port&gt; <br> `protocol`=&lt;protocol&gt; | EXPERIMENTAL |
22 changes: 22 additions & 0 deletions internal/store/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,28 @@ func ingressMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
}
}),
),
*generator.NewFamilyGeneratorWithStability(
"kube_ingress_status",
Copy link
Member

@mrueg mrueg Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"kube_ingress_status",
"kube_ingress_status",

I'm a bit torn on this name.
Maybe:
kube_ingress_status_loadbalancer (just wondering if additional fields get added to _status this might be difficult to include)

"Ingress status.",
metric.Gauge,
basemetrics.ALPHA,
"",
wrapIngressFunc(func(i *networkingv1.Ingress) *metric.Family {
ms := []*metric.Metric{}
for _, ingress := range i.Status.LoadBalancer.Ingress {
for _, port := range ingress.Ports {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"hostname", "port", "protocol"},
LabelValues: []string{ingress.Hostname, strconv.Itoa(int(port.Port)), string(port.Protocol)},
Value: 1,
})
}
}
return &metric.Family{
Metrics: ms,
}
}),
),
}
}

Expand Down
49 changes: 43 additions & 6 deletions internal/store/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ func TestIngressStore(t *testing.T) {
# HELP kube_ingress_metadata_resource_version Resource version representing a specific version of ingress.
# HELP kube_ingress_path [STABLE] Ingress host, paths and backend service information.
# HELP kube_ingress_tls [STABLE] Ingress TLS host and secret information.
# HELP kube_ingress_status Ingress status.
# TYPE kube_ingress_created gauge
# TYPE kube_ingress_info gauge
# TYPE kube_ingress_labels gauge
# TYPE kube_ingress_metadata_resource_version gauge
# TYPE kube_ingress_path gauge
# TYPE kube_ingress_tls gauge
# TYPE kube_ingress_status gauge
`
cases := []generateMetricsTestCase{
{
Expand Down Expand Up @@ -97,7 +99,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_created{namespace="ns2",ingress="ingress2"} 1.501569018e+09
kube_ingress_metadata_resource_version{namespace="ns2",ingress="ingress2"} 123456
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
{
Obj: &networkingv1.Ingress{
Expand All @@ -113,7 +115,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_info{namespace="ns3",ingress="ingress3",ingressclass="_default"} 1
kube_ingress_created{namespace="ns3",ingress="ingress3"} 1.501569018e+09
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
{
Obj: &networkingv1.Ingress{
Expand Down Expand Up @@ -167,7 +169,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_path{namespace="ns4",ingress="ingress4",host="somehost",path="/somepath",service_name="someservice",service_port="1234"} 1
kube_ingress_path{namespace="ns4",ingress="ingress4",host="somehost",path="/somepath2",resource_api_group="",resource_kind="somekind",resource_name="somename"} 1
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
{
Obj: &networkingv1.Ingress{
Expand All @@ -193,7 +195,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_tls{namespace="ns5",ingress="ingress5",tls_host="somehost1",secret="somesecret"} 1
kube_ingress_tls{namespace="ns5",ingress="ingress5",tls_host="somehost2",secret="somesecret"} 1
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
{
Obj: &networkingv1.Ingress{
Expand All @@ -212,7 +214,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_created{namespace="ns6",ingress="ingress6"} 1.501569018e+09
kube_ingress_metadata_resource_version{namespace="ns6",ingress="ingress6"} 123456
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
{
Obj: &networkingv1.Ingress{
Expand All @@ -231,7 +233,42 @@ func TestIngressStore(t *testing.T) {
kube_ingress_created{namespace="ns7",ingress="ingress7"} 1.501569018e+09
kube_ingress_metadata_resource_version{namespace="ns7",ingress="ingress7"} 123456
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
{
Obj: &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "ingress8",
Namespace: "ns8",
CreationTimestamp: metav1StartTime,
ResourceVersion: "123456",
},
Status: networkingv1.IngressStatus{
LoadBalancer: networkingv1.IngressLoadBalancerStatus{
Ingress: []networkingv1.IngressLoadBalancerIngress{
{

IP: "1.2.3.4",
Hostname: "www.example.com",
Ports: []networkingv1.IngressPortStatus{
{
Port: 8888,
Protocol: "TCP",
Error: nil,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we expose this error somehow as well?

I assume it can potentially cause high cardinality, but it will be interesting to know if there's an error on the IngressPortStatus?

},
},
},
},
},
},
},
Want: metadata + `
kube_ingress_created{namespace="ns8",ingress="ingress8"} 1.501569018e+09
kube_ingress_info{namespace="ns8",ingress="ingress8",ingressclass="_default"} 1
kube_ingress_metadata_resource_version{namespace="ns8",ingress="ingress8"} 123456
kube_ingress_status{namespace="ns8",ingress="ingress8",hostname="www.example.com",port="8888",protocol="TCP"} 1
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls", "kube_ingress_status"},
},
}
for i, c := range cases {
Expand Down