Skip to content

Commit

Permalink
Merge pull request #1841 from evir35/1660-do-not-expose-ingress-path-…
Browse files Browse the repository at this point in the history
…metric-when-service-is-nil

Do not expose ingress path metric when service is nil
  • Loading branch information
k8s-ci-robot committed Sep 23, 2022
2 parents bef31e3 + 7f453f0 commit 12402a5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/store/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,19 @@ func ingressMetricFamilies(allowAnnotationsList, allowLabelsList []string) []gen
for _, rule := range i.Spec.Rules {
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.Service.Name, strconv.Itoa(int(path.Backend.Service.Port.Number))},
Value: 1,
})
if path.Backend.Service != nil {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"host", "path", "service_name", "service_port"},
LabelValues: []string{rule.Host, path.Path, path.Backend.Service.Name, strconv.Itoa(int(path.Backend.Service.Port.Number))},
Value: 1,
})
} else {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"host", "path", "service_name", "service_port"},
LabelValues: []string{rule.Host, path.Path, "", ""},
Value: 1,
})
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions internal/store/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package store
import (
"testing"

v1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -144,6 +145,15 @@ func TestIngressStore(t *testing.T) {
},
},
},
{
Path: "/somepath2",
Backend: networkingv1.IngressBackend{
Resource: &v1.TypedLocalObjectReference{
Kind: "somekind",
Name: "somename",
},
},
},
},
},
},
Expand All @@ -159,6 +169,7 @@ func TestIngressStore(t *testing.T) {
kube_ingress_created{namespace="ns4",ingress="ingress4"} 1.501569018e+09
kube_ingress_labels{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="somehost",path="/somepath2",service_name="",service_port=""} 1
`,
MetricNames: []string{"kube_ingress_info", "kube_ingress_metadata_resource_version", "kube_ingress_created", "kube_ingress_labels", "kube_ingress_path", "kube_ingress_tls"},
},
Expand Down

0 comments on commit 12402a5

Please sign in to comment.