Merge pull request #15755 from zhengguoyong/del_capatical_packagename_for_cadvisorApi2
Auto commit by PR queue bot
This commit is contained in:
@@ -25,16 +25,16 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
)
|
||||
|
||||
type ContainerInfoGetter interface {
|
||||
// GetContainerInfo returns information about a container.
|
||||
GetContainerInfo(host, podID, containerID string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||
GetContainerInfo(host, podID, containerID string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
|
||||
// GetRootInfo returns information about the root container on a machine.
|
||||
GetRootInfo(host string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
|
||||
GetRootInfo(host string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error)
|
||||
// GetMachineInfo returns the machine's information like number of cores, memory capacity.
|
||||
GetMachineInfo(host string) (*cadvisorApi.MachineInfo, error)
|
||||
GetMachineInfo(host string) (*cadvisorapi.MachineInfo, error)
|
||||
}
|
||||
|
||||
type HTTPContainerInfoGetter struct {
|
||||
@@ -42,7 +42,7 @@ type HTTPContainerInfoGetter struct {
|
||||
Port int
|
||||
}
|
||||
|
||||
func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorApi.MachineInfo, error) {
|
||||
func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorapi.MachineInfo, error) {
|
||||
request, err := http.NewRequest(
|
||||
"GET",
|
||||
fmt.Sprintf("http://%v/spec",
|
||||
@@ -63,7 +63,7 @@ func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorApi.M
|
||||
return nil, fmt.Errorf("trying to get machine spec from %v; received status %v",
|
||||
host, response.Status)
|
||||
}
|
||||
var minfo cadvisorApi.MachineInfo
|
||||
var minfo cadvisorapi.MachineInfo
|
||||
err = json.NewDecoder(response.Body).Decode(&minfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -71,7 +71,7 @@ func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorApi.M
|
||||
return &minfo, nil
|
||||
}
|
||||
|
||||
func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||
func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
var body io.Reader
|
||||
if req != nil {
|
||||
content, err := json.Marshal(req)
|
||||
@@ -102,7 +102,7 @@ func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *ca
|
||||
return nil, fmt.Errorf("trying to get info for %v from %v; received status %v",
|
||||
path, host, response.Status)
|
||||
}
|
||||
var cinfo cadvisorApi.ContainerInfo
|
||||
var cinfo cadvisorapi.ContainerInfo
|
||||
err = json.NewDecoder(response.Body).Decode(&cinfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -110,7 +110,7 @@ func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *ca
|
||||
return &cinfo, nil
|
||||
}
|
||||
|
||||
func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||
func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return self.getContainerInfo(
|
||||
host,
|
||||
fmt.Sprintf("%v/%v", podID, containerID),
|
||||
@@ -118,6 +118,6 @@ func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID s
|
||||
)
|
||||
}
|
||||
|
||||
func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
|
||||
func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *cadvisorapi.ContainerInfoRequest) (*cadvisorapi.ContainerInfo, error) {
|
||||
return self.getContainerInfo(host, "", req)
|
||||
}
|
||||
|
@@ -28,13 +28,13 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cadvisorApi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorApiTest "github.com/google/cadvisor/info/v1/test"
|
||||
cadvisorapi "github.com/google/cadvisor/info/v1"
|
||||
cadvisorapitest "github.com/google/cadvisor/info/v1/test"
|
||||
)
|
||||
|
||||
func testHTTPContainerInfoGetter(
|
||||
req *cadvisorApi.ContainerInfoRequest,
|
||||
cinfo *cadvisorApi.ContainerInfo,
|
||||
req *cadvisorapi.ContainerInfoRequest,
|
||||
cinfo *cadvisorapi.ContainerInfo,
|
||||
podID string,
|
||||
containerID string,
|
||||
status int,
|
||||
@@ -53,7 +53,7 @@ func testHTTPContainerInfoGetter(
|
||||
expectedPath, r.URL.Path)
|
||||
}
|
||||
|
||||
var receivedReq cadvisorApi.ContainerInfoRequest
|
||||
var receivedReq cadvisorapi.ContainerInfoRequest
|
||||
err := json.NewDecoder(r.Body).Decode(&receivedReq)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -87,7 +87,7 @@ func testHTTPContainerInfoGetter(
|
||||
Port: port,
|
||||
}
|
||||
|
||||
var receivedContainerInfo *cadvisorApi.ContainerInfo
|
||||
var receivedContainerInfo *cadvisorapi.ContainerInfo
|
||||
if len(podID) > 0 && len(containerID) > 0 {
|
||||
receivedContainerInfo, err = containerInfoGetter.GetContainerInfo(parts[0], podID, containerID, req)
|
||||
} else {
|
||||
@@ -109,10 +109,10 @@ func testHTTPContainerInfoGetter(
|
||||
}
|
||||
|
||||
func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
|
||||
req := &cadvisorApi.ContainerInfoRequest{
|
||||
req := &cadvisorapi.ContainerInfoRequest{
|
||||
NumStats: 10,
|
||||
}
|
||||
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||
cinfo := cadvisorapitest.GenerateRandomContainerInfo(
|
||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||
2, // Number of cores
|
||||
req,
|
||||
@@ -122,10 +122,10 @@ func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
|
||||
req := &cadvisorApi.ContainerInfoRequest{
|
||||
req := &cadvisorapi.ContainerInfoRequest{
|
||||
NumStats: 10,
|
||||
}
|
||||
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||
cinfo := cadvisorapitest.GenerateRandomContainerInfo(
|
||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||
2, // Number of cores
|
||||
req,
|
||||
@@ -135,10 +135,10 @@ func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
|
||||
req := &cadvisorApi.ContainerInfoRequest{
|
||||
req := &cadvisorapi.ContainerInfoRequest{
|
||||
NumStats: 10,
|
||||
}
|
||||
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||
cinfo := cadvisorapitest.GenerateRandomContainerInfo(
|
||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||
2, // Number of cores
|
||||
req,
|
||||
@@ -148,10 +148,10 @@ func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
|
||||
req := &cadvisorApi.ContainerInfoRequest{
|
||||
req := &cadvisorapi.ContainerInfoRequest{
|
||||
NumStats: 10,
|
||||
}
|
||||
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
|
||||
cinfo := cadvisorapitest.GenerateRandomContainerInfo(
|
||||
"dockerIDWhichWillNotBeChecked", // docker ID
|
||||
2, // Number of cores
|
||||
req,
|
||||
@@ -161,7 +161,7 @@ func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHTTPGetMachineInfo(t *testing.T) {
|
||||
mspec := &cadvisorApi.MachineInfo{
|
||||
mspec := &cadvisorapi.MachineInfo{
|
||||
NumCores: 4,
|
||||
MemoryCapacity: 2048,
|
||||
}
|
||||
|
Reference in New Issue
Block a user