Metrics: Add --metrics-per-undefined-host argument. (#11818)
Signed-off-by: Jon Carl <grounded042@joncarl.com>
This commit is contained in:
parent
93f9f9fbb3
commit
034c3ccad4
11 changed files with 172 additions and 28 deletions
|
|
@ -87,14 +87,15 @@ func TestCollector(t *testing.T) {
|
|||
maxBuckets := uint32(100)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
data []string
|
||||
metrics []string
|
||||
useStatusClasses bool
|
||||
excludeMetrics []string
|
||||
wantBefore string
|
||||
removeIngresses []string
|
||||
wantAfter string
|
||||
name string
|
||||
data []string
|
||||
metrics []string
|
||||
metricsPerUndefinedHost bool
|
||||
useStatusClasses bool
|
||||
excludeMetrics []string
|
||||
wantBefore string
|
||||
removeIngresses []string
|
||||
wantAfter string
|
||||
}{
|
||||
{
|
||||
name: "invalid metric object should not increase prometheus metrics",
|
||||
|
|
@ -591,13 +592,69 @@ func TestCollector(t *testing.T) {
|
|||
nginx_ingress_controller_response_duration_seconds_count{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx"} 1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "metrics with a host should not be dropped when the host is not in the hosts slice but metricsPerUndefinedHost is true",
|
||||
data: []string{`[{
|
||||
"host":"wildcard.testshop.com",
|
||||
"status":"200",
|
||||
"bytesSent":150.0,
|
||||
"method":"GET",
|
||||
"path":"/admin",
|
||||
"requestLength":300.0,
|
||||
"requestTime":60.0,
|
||||
"upstreamLatency":1.0,
|
||||
"upstreamHeaderTime":5.0,
|
||||
"upstreamName":"test-upstream",
|
||||
"upstreamIP":"1.1.1.1:8080",
|
||||
"upstreamResponseTime":200,
|
||||
"upstreamStatus":"220",
|
||||
"namespace":"test-app-production",
|
||||
"ingress":"web-yml",
|
||||
"service":"test-app",
|
||||
"canary":""
|
||||
}]`},
|
||||
excludeMetrics: []string{"response_duration_seconds2", "test.*", "nginx_ingress_.*", "response_duration_secon"},
|
||||
metrics: []string{"nginx_ingress_controller_requests"},
|
||||
metricsPerUndefinedHost: true,
|
||||
useStatusClasses: true,
|
||||
wantBefore: `
|
||||
# HELP nginx_ingress_controller_requests The total number of client requests
|
||||
# TYPE nginx_ingress_controller_requests counter
|
||||
nginx_ingress_controller_requests{canary="",controller_class="ingress",controller_namespace="default",controller_pod="pod",host="wildcard.testshop.com",ingress="web-yml",method="GET",namespace="test-app-production",path="/admin",service="test-app",status="2xx"} 1
|
||||
`,
|
||||
},
|
||||
{
|
||||
name: "metrics with a host should be dropped when the host is not in the hosts slice",
|
||||
data: []string{`[{
|
||||
"host":"wildcard.testshop.com",
|
||||
"status":"200",
|
||||
"bytesSent":150.0,
|
||||
"method":"GET",
|
||||
"path":"/admin",
|
||||
"requestLength":300.0,
|
||||
"requestTime":60.0,
|
||||
"upstreamLatency":1.0,
|
||||
"upstreamHeaderTime":5.0,
|
||||
"upstreamName":"test-upstream",
|
||||
"upstreamIP":"1.1.1.1:8080",
|
||||
"upstreamResponseTime":200,
|
||||
"upstreamStatus":"220",
|
||||
"namespace":"test-app-production",
|
||||
"ingress":"web-yml",
|
||||
"service":"test-app",
|
||||
"canary":""
|
||||
}]`},
|
||||
excludeMetrics: []string{"response_duration_seconds2", "test.*", "nginx_ingress_.*", "response_duration_secon"},
|
||||
metrics: []string{"nginx_ingress_controller_requests"},
|
||||
useStatusClasses: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
registry := prometheus.NewPedanticRegistry()
|
||||
|
||||
sc, err := NewSocketCollector("pod", "default", "ingress", true, c.useStatusClasses, buckets, bucketFactor, maxBuckets, c.excludeMetrics)
|
||||
sc, err := NewSocketCollector("pod", "default", "ingress", true, c.metricsPerUndefinedHost, c.useStatusClasses, buckets, bucketFactor, maxBuckets, c.excludeMetrics)
|
||||
if err != nil {
|
||||
t.Errorf("%v: unexpected error creating new SocketCollector: %v", c.name, err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue