Skip to content

Commit

Permalink
Merge pull request kubernetes#5152 from vmarmol/cadvisor-dep
Browse files Browse the repository at this point in the history
Rename cAdvisor info API to cadvisorApi
  • Loading branch information
vishh committed Mar 7, 2015
2 parents 1866add + 43b469b commit 53ec66c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 75 deletions.
20 changes: 10 additions & 10 deletions pkg/client/containerinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ import (
"net/http"
"strconv"

info "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 *info.ContainerInfoRequest) (*info.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 *info.ContainerInfoRequest) (*info.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) (*info.MachineInfo, error)
GetMachineInfo(host string) (*cadvisorApi.MachineInfo, error)
}

type HTTPContainerInfoGetter struct {
Client *http.Client
Port int
}

func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineInfo, error) {
func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*cadvisorApi.MachineInfo, error) {
request, err := http.NewRequest(
"GET",
fmt.Sprintf("http://%v/spec",
Expand All @@ -63,15 +63,15 @@ func (self *HTTPContainerInfoGetter) GetMachineInfo(host string) (*info.MachineI
return nil, fmt.Errorf("trying to get machine spec from %v; received status %v",
host, response.Status)
}
var minfo info.MachineInfo
var minfo cadvisorApi.MachineInfo
err = json.NewDecoder(response.Body).Decode(&minfo)
if err != nil {
return nil, err
}
return &minfo, nil
}

func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *info.ContainerInfoRequest) (*info.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)
Expand Down Expand Up @@ -102,22 +102,22 @@ func (self *HTTPContainerInfoGetter) getContainerInfo(host, path string, req *in
return nil, fmt.Errorf("trying to get info for %v from %v; received status %v",
path, host, response.Status)
}
var cinfo info.ContainerInfo
var cinfo cadvisorApi.ContainerInfo
err = json.NewDecoder(response.Body).Decode(&cinfo)
if err != nil {
return nil, err
}
return &cinfo, nil
}

func (self *HTTPContainerInfoGetter) GetContainerInfo(host, podID, containerID string, req *info.ContainerInfoRequest) (*info.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),
req,
)
}

func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
func (self *HTTPContainerInfoGetter) GetRootInfo(host string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
return self.getContainerInfo(host, "", req)
}
30 changes: 15 additions & 15 deletions pkg/client/containerinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ import (
"testing"
"time"

info "github.com/google/cadvisor/info/v1"
itest "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 *info.ContainerInfoRequest,
cinfo *info.ContainerInfo,
req *cadvisorApi.ContainerInfoRequest,
cinfo *cadvisorApi.ContainerInfo,
podID string,
containerID string,
status int,
Expand All @@ -53,7 +53,7 @@ func testHTTPContainerInfoGetter(
expectedPath, r.URL.Path)
}

var receivedReq info.ContainerInfoRequest
var receivedReq cadvisorApi.ContainerInfoRequest
err := json.NewDecoder(r.Body).Decode(&receivedReq)
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -87,7 +87,7 @@ func testHTTPContainerInfoGetter(
Port: port,
}

var receivedContainerInfo *info.ContainerInfo
var receivedContainerInfo *cadvisorApi.ContainerInfo
if len(podID) > 0 && len(containerID) > 0 {
receivedContainerInfo, err = containerInfoGetter.GetContainerInfo(parts[0], podID, containerID, req)
} else {
Expand All @@ -109,10 +109,10 @@ func testHTTPContainerInfoGetter(
}

func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
req := &info.ContainerInfoRequest{
req := &cadvisorApi.ContainerInfoRequest{
NumStats: 10,
}
cinfo := itest.GenerateRandomContainerInfo(
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
Expand All @@ -122,10 +122,10 @@ func TestHTTPContainerInfoGetterGetContainerInfoSuccessfully(t *testing.T) {
}

func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
req := &info.ContainerInfoRequest{
req := &cadvisorApi.ContainerInfoRequest{
NumStats: 10,
}
cinfo := itest.GenerateRandomContainerInfo(
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
Expand All @@ -135,10 +135,10 @@ func TestHTTPContainerInfoGetterGetRootInfoSuccessfully(t *testing.T) {
}

func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
req := &info.ContainerInfoRequest{
req := &cadvisorApi.ContainerInfoRequest{
NumStats: 10,
}
cinfo := itest.GenerateRandomContainerInfo(
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
Expand All @@ -148,10 +148,10 @@ func TestHTTPContainerInfoGetterGetContainerInfoWithError(t *testing.T) {
}

func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
req := &info.ContainerInfoRequest{
req := &cadvisorApi.ContainerInfoRequest{
NumStats: 10,
}
cinfo := itest.GenerateRandomContainerInfo(
cinfo := cadvisorApiTest.GenerateRandomContainerInfo(
"dockerIDWhichWillNotBeChecked", // docker ID
2, // Number of cores
req,
Expand All @@ -161,7 +161,7 @@ func TestHTTPContainerInfoGetterGetRootInfoWithError(t *testing.T) {
}

func TestHTTPGetMachineInfo(t *testing.T) {
mspec := &info.MachineInfo{
mspec := &cadvisorApi.MachineInfo{
NumCores: 4,
MemoryCapacity: 2048,
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/kubelet/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
cadvisor "github.com/google/cadvisor/info/v1"
cadvisorApi "github.com/google/cadvisor/info/v1"
)

var (
Expand All @@ -38,16 +38,16 @@ var (

// cadvisorInterface is an abstract interface for testability. It abstracts the interface of "github.com/google/cadvisor/client".Client.
type cadvisorInterface interface {
DockerContainer(name string, req *cadvisor.ContainerInfoRequest) (cadvisor.ContainerInfo, error)
ContainerInfo(name string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error)
MachineInfo() (*cadvisor.MachineInfo, error)
DockerContainer(name string, req *cadvisorApi.ContainerInfoRequest) (cadvisorApi.ContainerInfo, error)
ContainerInfo(name string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
MachineInfo() (*cadvisorApi.MachineInfo, error)
}

// statsFromContainerPath takes a container's absolute path and returns the stats for the
// container. The container's absolute path refers to its hierarchy in the
// cgroup file system. e.g. The root container, which represents the whole
// machine, has path "/"; all docker containers have path "/docker/<docker id>"
func statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
func statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
cinfo, err := cc.ContainerInfo(containerPath, req)
if err != nil {
return nil, err
Expand All @@ -57,7 +57,7 @@ func statsFromContainerPath(cc cadvisorInterface, containerPath string, req *cad

// statsFromDockerContainer takes a Docker container's ID and returns the stats for the
// container.
func statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
func statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
cinfo, err := cc.DockerContainer(containerId, req)
if err != nil {
return nil, err
Expand All @@ -66,7 +66,7 @@ func statsFromDockerContainer(cc cadvisorInterface, containerId string, req *cad
}

// GetContainerInfo returns stats (from Cadvisor) for a container.
func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
cc := kl.GetCadvisorClient()
if cc == nil {
return nil, fmt.Errorf("no cadvisor connection")
Expand All @@ -91,15 +91,15 @@ func (kl *Kubelet) GetContainerInfo(podFullName string, uid types.UID, container
}

// GetRootInfo returns stats (from Cadvisor) of current machine (root container).
func (kl *Kubelet) GetRootInfo(req *cadvisor.ContainerInfoRequest) (*cadvisor.ContainerInfo, error) {
func (kl *Kubelet) GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
cc := kl.GetCadvisorClient()
if cc == nil {
return nil, fmt.Errorf("no cadvisor connection")
}
return statsFromContainerPath(cc, "/", req)
}

func (kl *Kubelet) GetMachineInfo() (*cadvisor.MachineInfo, error) {
func (kl *Kubelet) GetMachineInfo() (*cadvisorApi.MachineInfo, error) {
cc := kl.GetCadvisorClient()
if cc == nil {
return nil, fmt.Errorf("no cadvisor connection")
Expand Down
30 changes: 15 additions & 15 deletions pkg/kubelet/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/fsouza/go-dockerclient"
info "github.com/google/cadvisor/info/v1"
cadvisorApi "github.com/google/cadvisor/info/v1"
"github.com/stretchr/testify/mock"
)

Expand Down Expand Up @@ -1187,34 +1187,34 @@ func (f *errorTestingDockerClient) ListContainers(options docker.ListContainersO
}

// ContainerInfo is a mock implementation of CadvisorInterface.ContainerInfo.
func (c *mockCadvisorClient) ContainerInfo(name string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error) {
func (c *mockCadvisorClient) ContainerInfo(name string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error) {
args := c.Called(name, req)
return args.Get(0).(*info.ContainerInfo), args.Error(1)
return args.Get(0).(*cadvisorApi.ContainerInfo), args.Error(1)
}

// DockerContainer is a mock implementation of CadvisorInterface.DockerContainer.
func (c *mockCadvisorClient) DockerContainer(name string, req *info.ContainerInfoRequest) (info.ContainerInfo, error) {
func (c *mockCadvisorClient) DockerContainer(name string, req *cadvisorApi.ContainerInfoRequest) (cadvisorApi.ContainerInfo, error) {
args := c.Called(name, req)
return args.Get(0).(info.ContainerInfo), args.Error(1)
return args.Get(0).(cadvisorApi.ContainerInfo), args.Error(1)
}

// MachineInfo is a mock implementation of CadvisorInterface.MachineInfo.
func (c *mockCadvisorClient) MachineInfo() (*info.MachineInfo, error) {
func (c *mockCadvisorClient) MachineInfo() (*cadvisorApi.MachineInfo, error) {
args := c.Called()
return args.Get(0).(*info.MachineInfo), args.Error(1)
return args.Get(0).(*cadvisorApi.MachineInfo), args.Error(1)
}

func TestGetContainerInfo(t *testing.T) {
containerID := "ab2cdf"
containerPath := fmt.Sprintf("/docker/%v", containerID)
containerInfo := info.ContainerInfo{
ContainerReference: info.ContainerReference{
containerInfo := cadvisorApi.ContainerInfo{
ContainerReference: cadvisorApi.ContainerReference{
Name: containerPath,
},
}

mockCadvisor := &mockCadvisorClient{}
cadvisorReq := &info.ContainerInfoRequest{}
cadvisorReq := &cadvisorApi.ContainerInfoRequest{}
mockCadvisor.On("DockerContainer", containerID, cadvisorReq).Return(containerInfo, nil)

kubelet, fakeDocker, _ := newTestKubelet(t)
Expand All @@ -1240,15 +1240,15 @@ func TestGetContainerInfo(t *testing.T) {

func TestGetRootInfo(t *testing.T) {
containerPath := "/"
containerInfo := &info.ContainerInfo{
ContainerReference: info.ContainerReference{
containerInfo := &cadvisorApi.ContainerInfo{
ContainerReference: cadvisorApi.ContainerReference{
Name: containerPath,
},
}
fakeDocker := dockertools.FakeDockerClient{}

mockCadvisor := &mockCadvisorClient{}
cadvisorReq := &info.ContainerInfoRequest{}
cadvisorReq := &cadvisorApi.ContainerInfoRequest{}
mockCadvisor.On("ContainerInfo", containerPath, cadvisorReq).Return(containerInfo, nil)

kubelet := Kubelet{
Expand Down Expand Up @@ -1286,9 +1286,9 @@ func TestGetContainerInfoWithoutCadvisor(t *testing.T) {
func TestGetContainerInfoWhenCadvisorFailed(t *testing.T) {
containerID := "ab2cdf"

containerInfo := info.ContainerInfo{}
containerInfo := cadvisorApi.ContainerInfo{}
mockCadvisor := &mockCadvisorClient{}
cadvisorReq := &info.ContainerInfoRequest{}
cadvisorReq := &cadvisorApi.ContainerInfoRequest{}
mockCadvisor.On("DockerContainer", containerID, cadvisorReq).Return(containerInfo, ErrCadvisorApiFailure)

kubelet, fakeDocker, _ := newTestKubelet(t)
Expand Down
12 changes: 6 additions & 6 deletions pkg/kubelet/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/httpstream/spdy"
"github.com/golang/glog"
info "github.com/google/cadvisor/info/v1"
cadvisorApi "github.com/google/cadvisor/info/v1"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -77,10 +77,10 @@ func ListenAndServeKubeletServer(host HostInterface, address net.IP, port uint,
// HostInterface contains all the kubelet methods required by the server.
// For testablitiy.
type HostInterface interface {
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
GetRootInfo(req *info.ContainerInfoRequest) (*info.ContainerInfo, error)
GetContainerInfo(podFullName string, uid types.UID, containerName string, req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
GetRootInfo(req *cadvisorApi.ContainerInfoRequest) (*cadvisorApi.ContainerInfo, error)
GetDockerVersion() ([]uint, error)
GetMachineInfo() (*info.MachineInfo, error)
GetMachineInfo() (*cadvisorApi.MachineInfo, error)
GetBoundPods() ([]api.BoundPod, error)
GetPodByName(namespace, name string) (*api.BoundPod, bool)
GetPodStatus(name string, uid types.UID) (api.PodStatus, error)
Expand Down Expand Up @@ -633,9 +633,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
func (s *Server) serveStats(w http.ResponseWriter, req *http.Request) {
// /stats/<podfullname>/<containerName> or /stats/<namespace>/<podfullname>/<uid>/<containerName>
components := strings.Split(strings.TrimPrefix(path.Clean(req.URL.Path), "/"), "/")
var stats *info.ContainerInfo
var stats *cadvisorApi.ContainerInfo
var err error
var query info.ContainerInfoRequest
var query cadvisorApi.ContainerInfoRequest
err = json.NewDecoder(req.Body).Decode(&query)
if err != nil && err != io.EOF {
s.error(w, err)
Expand Down
Loading

0 comments on commit 53ec66c

Please sign in to comment.