Skip to content

Commit

Permalink
Fix crash due to missing ingress http block
Browse files Browse the repository at this point in the history
It's acceptable although uncommon for an ingress to have a rule and a host,
but no HTTP block for that particular rule.
  • Loading branch information
Ergin Babani committed Jul 18, 2019
1 parent 66ac307 commit b9c98b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions internal/store/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,18 @@ var (
GenerateFunc: wrapIngressFunc(func(i *v1beta1.Ingress) *metric.Family {
ms := []*metric.Metric{}
for _, rule := range i.Spec.Rules {
for _, path := range rule.HTTP.Paths {
if rule.HTTP != nil {
for _, path := range rule.HTTP.Paths {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"host", "path", "service_name", "service_port"},
LabelValues: []string{rule.Host, path.Path, path.Backend.ServiceName, path.Backend.ServicePort.String()},
Value: 1,
})
}
} else {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"host", "path", "service_name", "service_port"},
LabelValues: []string{rule.Host, path.Path, path.Backend.ServiceName, path.Backend.ServicePort.String()},
LabelValues: []string{rule.Host, "", "", ""},
Value: 1,
})
}
Expand Down
4 changes: 4 additions & 0 deletions internal/store/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func TestIngressStore(t *testing.T) {
},
},
},
{
Host: "somehost2",
},
},
},
},
Expand All @@ -148,6 +151,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_metadata_resource_version{namespace="ns4",resource_version="abcdef",ingress="ingress4"} 1
kube_ingress_labels{label_test_4="test-4",namespace="ns4",ingress="ingress4"} 1
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="somehost2",path="",service_name="",service_port=""} 1
kube_ingress_annotations{namespace="ns4",ingress="ingress4",annotation_test_4="test-4"} 1
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_annotations"},
Expand Down

0 comments on commit b9c98b7

Please sign in to comment.