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
78547d9a
Commit
78547d9a
authored
Jan 05, 2015
by
Dawn Chen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3194 from vishh/stats
Update "/stats" endpoint on kubelet.
parents
4e417b98
3ef9e404
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
11 deletions
+39
-11
server.go
pkg/kubelet/server.go
+6
-8
server_test.go
pkg/kubelet/server_test.go
+33
-3
No files found.
pkg/kubelet/server.go
View file @
78547d9a
...
@@ -325,7 +325,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
...
@@ -325,7 +325,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// serveStats implements stats logic.
// serveStats implements stats logic.
func
(
s
*
Server
)
serveStats
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
func
(
s
*
Server
)
serveStats
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
// /stats/<podfullname>/<containerName> or /stats/<podfullname>/<uuid>/<containerName>
// /stats/<podfullname>/<containerName> or /stats/<
namespace>/<
podfullname>/<uuid>/<containerName>
components
:=
strings
.
Split
(
strings
.
TrimPrefix
(
path
.
Clean
(
req
.
URL
.
Path
),
"/"
),
"/"
)
components
:=
strings
.
Split
(
strings
.
TrimPrefix
(
path
.
Clean
(
req
.
URL
.
Path
),
"/"
),
"/"
)
var
stats
*
info
.
ContainerInfo
var
stats
*
info
.
ContainerInfo
var
err
error
var
err
error
...
@@ -347,23 +347,21 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
...
@@ -347,23 +347,21 @@ func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
// Backward compatibility without uuid information
// Backward compatibility without uuid information
podFullName
:=
GetPodFullName
(
&
api
.
BoundPod
{
podFullName
:=
GetPodFullName
(
&
api
.
BoundPod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
components
[
1
],
Name
:
components
[
1
],
// TODO: I am broken
Namespace
:
api
.
NamespaceDefault
,
Namespace
:
api
.
NamespaceDefault
,
Annotations
:
map
[
string
]
string
{
ConfigSourceAnnotationKey
:
"etcd"
},
Annotations
:
map
[
string
]
string
{
ConfigSourceAnnotationKey
:
"etcd"
},
},
},
})
})
stats
,
err
=
s
.
host
.
GetContainerInfo
(
podFullName
,
""
,
components
[
2
],
&
query
)
stats
,
err
=
s
.
host
.
GetContainerInfo
(
podFullName
,
""
,
components
[
2
],
&
query
)
case
4
:
case
5
:
podFullName
:=
GetPodFullName
(
&
api
.
BoundPod
{
podFullName
:=
GetPodFullName
(
&
api
.
BoundPod
{
ObjectMeta
:
api
.
ObjectMeta
{
ObjectMeta
:
api
.
ObjectMeta
{
Name
:
components
[
1
],
Name
:
components
[
2
],
// TODO: I am broken
Namespace
:
components
[
1
],
Namespace
:
""
,
Annotations
:
map
[
string
]
string
{
ConfigSourceAnnotationKey
:
"etcd"
},
Annotations
:
map
[
string
]
string
{
ConfigSourceAnnotationKey
:
"etcd"
},
},
},
})
})
stats
,
err
=
s
.
host
.
GetContainerInfo
(
podFullName
,
components
[
2
],
components
[
2
],
&
query
)
stats
,
err
=
s
.
host
.
GetContainerInfo
(
podFullName
,
components
[
3
],
components
[
4
],
&
query
)
default
:
default
:
http
.
Error
(
w
,
"unknown resource."
,
http
.
StatusNotFound
)
http
.
Error
(
w
,
"unknown resource."
,
http
.
StatusNotFound
)
return
return
...
...
pkg/kubelet/server_test.go
View file @
78547d9a
...
@@ -34,7 +34,7 @@ import (
...
@@ -34,7 +34,7 @@ import (
type
fakeKubelet
struct
{
type
fakeKubelet
struct
{
infoFunc
func
(
name
string
)
(
api
.
PodInfo
,
error
)
infoFunc
func
(
name
string
)
(
api
.
PodInfo
,
error
)
containerInfoFunc
func
(
podFullName
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
containerInfoFunc
func
(
podFullName
,
uid
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
rootInfoFunc
func
(
query
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
rootInfoFunc
func
(
query
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
machineInfoFunc
func
()
(
*
info
.
MachineInfo
,
error
)
machineInfoFunc
func
()
(
*
info
.
MachineInfo
,
error
)
boundPodsFunc
func
()
([]
api
.
BoundPod
,
error
)
boundPodsFunc
func
()
([]
api
.
BoundPod
,
error
)
...
@@ -48,7 +48,7 @@ func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
...
@@ -48,7 +48,7 @@ func (fk *fakeKubelet) GetPodInfo(name, uuid string) (api.PodInfo, error) {
}
}
func
(
fk
*
fakeKubelet
)
GetContainerInfo
(
podFullName
,
uuid
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
func
(
fk
*
fakeKubelet
)
GetContainerInfo
(
podFullName
,
uuid
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
return
fk
.
containerInfoFunc
(
podFullName
,
containerName
,
req
)
return
fk
.
containerInfoFunc
(
podFullName
,
uuid
,
containerName
,
req
)
}
}
func
(
fk
*
fakeKubelet
)
GetRootInfo
(
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
func
(
fk
*
fakeKubelet
)
GetRootInfo
(
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
...
@@ -144,7 +144,7 @@ func TestContainerInfo(t *testing.T) {
...
@@ -144,7 +144,7 @@ func TestContainerInfo(t *testing.T) {
podID
:=
"somepod"
podID
:=
"somepod"
expectedPodID
:=
"somepod"
+
".default.etcd"
expectedPodID
:=
"somepod"
+
".default.etcd"
expectedContainerName
:=
"goodcontainer"
expectedContainerName
:=
"goodcontainer"
fw
.
fakeKubelet
.
containerInfoFunc
=
func
(
podID
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
fw
.
fakeKubelet
.
containerInfoFunc
=
func
(
podID
,
uid
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
if
podID
!=
expectedPodID
||
containerName
!=
expectedContainerName
{
if
podID
!=
expectedPodID
||
containerName
!=
expectedContainerName
{
return
nil
,
fmt
.
Errorf
(
"bad podID or containerName: podID=%v; containerName=%v"
,
podID
,
containerName
)
return
nil
,
fmt
.
Errorf
(
"bad podID or containerName: podID=%v; containerName=%v"
,
podID
,
containerName
)
}
}
...
@@ -166,6 +166,36 @@ func TestContainerInfo(t *testing.T) {
...
@@ -166,6 +166,36 @@ func TestContainerInfo(t *testing.T) {
}
}
}
}
func
TestContainerInfoWithUidNamespace
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
expectedInfo
:=
&
info
.
ContainerInfo
{}
podID
:=
"somepod"
expectedNamespace
:=
"custom"
expectedPodID
:=
"somepod"
+
"."
+
expectedNamespace
+
".etcd"
expectedContainerName
:=
"goodcontainer"
expectedUid
:=
"9b01b80f-8fb4-11e4-95ab-4200af06647"
fw
.
fakeKubelet
.
containerInfoFunc
=
func
(
podID
,
uid
,
containerName
string
,
req
*
info
.
ContainerInfoRequest
)
(
*
info
.
ContainerInfo
,
error
)
{
if
podID
!=
expectedPodID
||
uid
!=
expectedUid
||
containerName
!=
expectedContainerName
{
return
nil
,
fmt
.
Errorf
(
"bad podID or uid or containerName: podID=%v; uid=%v; containerName=%v"
,
podID
,
uid
,
containerName
)
}
return
expectedInfo
,
nil
}
resp
,
err
:=
http
.
Get
(
fw
.
testHTTPServer
.
URL
+
fmt
.
Sprintf
(
"/stats/%v/%v/%v/%v"
,
expectedNamespace
,
podID
,
expectedUid
,
expectedContainerName
))
if
err
!=
nil
{
t
.
Fatalf
(
"Got error GETing: %v"
,
err
)
}
defer
resp
.
Body
.
Close
()
var
receivedInfo
info
.
ContainerInfo
err
=
json
.
NewDecoder
(
resp
.
Body
)
.
Decode
(
&
receivedInfo
)
if
err
!=
nil
{
t
.
Fatalf
(
"received invalid json data: %v"
,
err
)
}
if
!
reflect
.
DeepEqual
(
&
receivedInfo
,
expectedInfo
)
{
t
.
Errorf
(
"received wrong data: %#v"
,
receivedInfo
)
}
}
func
TestRootInfo
(
t
*
testing
.
T
)
{
func
TestRootInfo
(
t
*
testing
.
T
)
{
fw
:=
newServerTest
()
fw
:=
newServerTest
()
expectedInfo
:=
&
info
.
ContainerInfo
{}
expectedInfo
:=
&
info
.
ContainerInfo
{}
...
...
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