Skip to content

Commit 242cea3

Browse files
committed
Fix return blank string when Service is nil
1 parent d7a079e commit 242cea3

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/store/ingress.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ func ingressMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
147147
LabelValues: []string{rule.Host, path.Path, path.Backend.Service.Name, strconv.Itoa(int(path.Backend.Service.Port.Number))},
148148
Value: 1,
149149
})
150+
} else {
151+
ms = append(ms, &metric.Metric{
152+
LabelKeys: []string{"host", "path", "service_name", "service_port"},
153+
LabelValues: []string{rule.Host, path.Path, "<none>", "<none>"},
154+
Value: 1,
155+
})
150156
}
151157
}
152158
}

internal/store/ingress_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package store
1919
import (
2020
"testing"
2121

22+
v1 "k8s.io/api/core/v1"
2223
networkingv1 "k8s.io/api/networking/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425

@@ -144,6 +145,15 @@ func TestIngressStore(t *testing.T) {
144145
},
145146
},
146147
},
148+
{
149+
Path: "/somepath2",
150+
Backend: networkingv1.IngressBackend{
151+
Resource: &v1.TypedLocalObjectReference{
152+
Kind: "somekind",
153+
Name: "somename",
154+
},
155+
},
156+
},
147157
},
148158
},
149159
},
@@ -159,6 +169,7 @@ func TestIngressStore(t *testing.T) {
159169
kube_ingress_created{namespace="ns4",ingress="ingress4"} 1.501569018e+09
160170
kube_ingress_labels{namespace="ns4",ingress="ingress4"} 1
161171
kube_ingress_path{namespace="ns4",ingress="ingress4",host="somehost",path="/somepath",service_name="someservice",service_port="1234"} 1
172+
kube_ingress_path{namespace="ns4",ingress="ingress4",host="somehost",path="/somepath2",service_name="<none>",service_port="<none>"} 1
162173
`,
163174
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
164175
},

0 commit comments

Comments
 (0)