Commit 079dc0d7 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #44421 from mml/windows

Automatic merge from submit-queue (batch tested with PRs 44362, 44421, 44468, 43878, 44480) Drop leading path of KUBECTL.EXE if it shows up in User-Agent. Partial fix for #44419 Release note: kube-apiserver now drops unneeded path information if an older version of Windows kubectl sends it.
parents d1a6090b 4cff7c3d
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment