Drop leading path of KUBECTL.EXE if it shows up in User-Agent.
Kubernetes-commit: 4cff7c3d30f4f6b4377d52ec29ec4866f1d28bb9
This commit is contained in:
parent
662942f8b8
commit
6c87ad1f20
|
|
@ -109,9 +109,14 @@ func InstrumentRouteFunc(verb, resource string, routeFunc restful.RouteFunction)
|
|||
}
|
||||
|
||||
func cleanUserAgent(ua string) string {
|
||||
// We collapse all "web browser"-type user agents into one "browser" to reduce metric cardinality.
|
||||
if strings.HasPrefix(ua, "Mozilla/") {
|
||||
return "Browser"
|
||||
}
|
||||
// If an old "kubectl.exe" has passed us its full path, we discard the path portion.
|
||||
if exeIdx := strings.LastIndex(strings.ToLower(ua), "kubectl.exe"); exeIdx != -1 {
|
||||
return ua[exeIdx:]
|
||||
}
|
||||
return ua
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,14 @@ func TestCleanUserAgent(t *testing.T) {
|
|||
In: "kubectl/v1.2.4",
|
||||
Out: "kubectl/v1.2.4",
|
||||
},
|
||||
{
|
||||
In: `C:\Users\Kubernetes\kubectl.exe/v1.5.4`,
|
||||
Out: "kubectl.exe/v1.5.4",
|
||||
},
|
||||
{
|
||||
In: `C:\Program Files\kubectl.exe/v1.5.4`,
|
||||
Out: "kubectl.exe/v1.5.4",
|
||||
},
|
||||
} {
|
||||
if cleanUserAgent(tc.In) != tc.Out {
|
||||
t.Errorf("Failed to clean User-Agent: %s", tc.In)
|
||||
|
|
|
|||
Loading…
Reference in New Issue