Skip to content

Commit

Permalink
Merge pull request kubernetes#860 from pwittrock/no_cache_versioninfo
Browse files Browse the repository at this point in the history
Always to a live lookup of version info instead of caching.
  • Loading branch information
rjnagal committed Aug 21, 2015
2 parents 5d30b67 + b7bbefd commit 39290ee
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 8 deletions.
21 changes: 18 additions & 3 deletions integration/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"time"

"github.com/google/cadvisor/client"
"github.com/google/cadvisor/client/v2"
"github.com/google/cadvisor/integration/common"
)

Expand Down Expand Up @@ -123,12 +124,14 @@ type ShellActions interface {
type CadvisorActions interface {
// Returns a cAdvisor client to the machine being tested.
Client() *client.Client
ClientV2() *v2.Client
}

type realFramework struct {
hostname HostnameInfo
t *testing.T
cadvisorClient *client.Client
hostname HostnameInfo
t *testing.T
cadvisorClient *client.Client
cadvisorClientV2 *v2.Client

shellActions shellActions
dockerActions dockerActions
Expand Down Expand Up @@ -195,6 +198,18 @@ func (self *realFramework) Client() *client.Client {
return self.cadvisorClient
}

// Gets a v2 client to the cAdvisor being tested.
func (self *realFramework) ClientV2() *v2.Client {
if self.cadvisorClientV2 == nil {
cadvisorClientV2, err := v2.NewClient(self.Hostname().FullHostname())
if err != nil {
self.t.Fatalf("Failed to instantiate the cAdvisor client: %v", err)
}
self.cadvisorClientV2 = cadvisorClientV2
}
return self.cadvisorClientV2
}

func (self dockerActions) RunPause() string {
return self.Run(DockerRunArgs{
Image: "kubernetes/pause",
Expand Down
36 changes: 36 additions & 0 deletions integration/tests/api/attributes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2015 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package api

import (
"testing"

"github.com/google/cadvisor/integration/framework"
"github.com/stretchr/testify/assert"
)

func TestAttributeInformationIsReturned(t *testing.T) {
fm := framework.New(t)
defer fm.Cleanup()

attributes, err := fm.Cadvisor().ClientV2().Attributes()
if err != nil {
t.Fatal(err)
}

vp := `\d+\.\d+\.\d+`
assert.True(t, assert.Regexp(t, vp, attributes.DockerVersion),
"Expected %s to match %s", attributes.DockerVersion, vp)
}
16 changes: 11 additions & 5 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ func New(memoryCache *memory.InMemoryCache, sysfs sysfs.SysFs, maxHousekeepingIn
if err != nil {
return nil, err
}
newManager.versionInfo = *versionInfo
glog.Infof("Version: %+v", newManager.versionInfo)
glog.Infof("Version: %+v", *versionInfo)

newManager.eventHandler = events.NewEventManager(parseEventsStoragePolicy())
return newManager, nil
Expand All @@ -183,7 +182,6 @@ type manager struct {
memoryCache *memory.InMemoryCache
fsInfo fs.FsInfo
machineInfo info.MachineInfo
versionInfo info.VersionInfo
quitChannels []chan error
cadvisorContainer string
inHostNamespace bool
Expand Down Expand Up @@ -658,7 +656,11 @@ func (m *manager) GetMachineInfo() (*info.MachineInfo, error) {
}

func (m *manager) GetVersionInfo() (*info.VersionInfo, error) {
return &m.versionInfo, nil
// TODO: Consider caching this and periodically updating. The VersionInfo may change if
// the docker daemon is started after the cAdvisor client is created. Caching the value
// would be helpful so we would be able to return the last known docker version if
// docker was down at the time of a query.
return getVersionInfo()
}

func (m *manager) Exists(containerName string) bool {
Expand Down Expand Up @@ -1149,8 +1151,12 @@ func (m *manager) DockerInfo() (DockerStatus, error) {
if err != nil {
return DockerStatus{}, err
}
versionInfo, err := m.GetVersionInfo()
if err != nil {
return DockerStatus{}, err
}
out := DockerStatus{}
out.Version = m.versionInfo.DockerVersion
out.Version = versionInfo.DockerVersion
if val, ok := info["KernelVersion"]; ok {
out.KernelVersion = val
}
Expand Down

0 comments on commit 39290ee

Please sign in to comment.