Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
4cff7c3d
Commit
4cff7c3d
authored
Apr 11, 2017
by
Matt Liggett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop leading path of KUBECTL.EXE if it shows up in User-Agent.
parent
32600927
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
0 deletions
+13
-0
metrics.go
...ing/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go
+5
-0
metrics_test.go
...rc/k8s.io/apiserver/pkg/endpoints/metrics/metrics_test.go
+8
-0
No files found.
staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics.go
View file @
4cff7c3d
...
@@ -109,9 +109,14 @@ func InstrumentRouteFunc(verb, resource string, routeFunc restful.RouteFunction)
...
@@ -109,9 +109,14 @@ func InstrumentRouteFunc(verb, resource string, routeFunc restful.RouteFunction)
}
}
func
cleanUserAgent
(
ua
string
)
string
{
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/"
)
{
if
strings
.
HasPrefix
(
ua
,
"Mozilla/"
)
{
return
"Browser"
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
return
ua
}
}
...
...
staging/src/k8s.io/apiserver/pkg/endpoints/metrics/metrics_test.go
View file @
4cff7c3d
...
@@ -31,6 +31,14 @@ func TestCleanUserAgent(t *testing.T) {
...
@@ -31,6 +31,14 @@ func TestCleanUserAgent(t *testing.T) {
In
:
"kubectl/v1.2.4"
,
In
:
"kubectl/v1.2.4"
,
Out
:
"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
{
if
cleanUserAgent
(
tc
.
In
)
!=
tc
.
Out
{
t
.
Errorf
(
"Failed to clean User-Agent: %s"
,
tc
.
In
)
t
.
Errorf
(
"Failed to clean User-Agent: %s"
,
tc
.
In
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment