Commit a77450ec authored by Lantao Liu's avatar Lantao Liu

Add mountpoint as CRI image filesystem storage identifier.

parent c37b5d75
...@@ -1103,18 +1103,18 @@ message UInt64Value { ...@@ -1103,18 +1103,18 @@ message UInt64Value {
uint64 value = 1; uint64 value = 1;
} }
// StorageIdentifier uniquely identify the storage.. // FilesystemIdentifier uniquely identify the filesystem.
message StorageIdentifier{ message FilesystemIdentifier{
// UUID of the device. // Mountpoint of a filesystem.
string uuid = 1; string mountpoint = 1;
} }
// FilesystemUsage provides the filesystem usage information. // FilesystemUsage provides the filesystem usage information.
message FilesystemUsage { message FilesystemUsage {
// Timestamp in nanoseconds at which the information were collected. Must be > 0. // Timestamp in nanoseconds at which the information were collected. Must be > 0.
int64 timestamp = 1; int64 timestamp = 1;
// The underlying storage of the filesystem. // The unique identifier of the filesystem.
StorageIdentifier storage_id = 2; FilesystemIdentifier fs_id = 2;
// UsedBytes represents the bytes used for images on the filesystem. // UsedBytes represents the bytes used for images on the filesystem.
// This may differ from the total bytes used on the filesystem and may not // This may differ from the total bytes used on the filesystem and may not
// equal CapacityBytes - AvailableBytes. // equal CapacityBytes - AvailableBytes.
......
...@@ -77,6 +77,6 @@ func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.Eve ...@@ -77,6 +77,6 @@ func (cu *cadvisorUnsupported) WatchEvents(request *events.Request) (*events.Eve
return nil, unsupportedErr return nil, unsupportedErr
} }
func (c *cadvisorUnsupported) GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error) { func (cu *cadvisorUnsupported) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
return cadvisorapiv2.FsInfo{}, nil return cadvisorapiv2.FsInfo{}, nil
} }
...@@ -77,6 +77,6 @@ func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventCha ...@@ -77,6 +77,6 @@ func (cu *cadvisorClient) WatchEvents(request *events.Request) (*events.EventCha
return &events.EventChannel{}, nil return &events.EventChannel{}, nil
} }
func (c *cadvisorClient) GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error) { func (cu *cadvisorClient) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
return cadvisorapiv2.FsInfo{}, nil return cadvisorapiv2.FsInfo{}, nil
} }
...@@ -76,6 +76,6 @@ func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error ...@@ -76,6 +76,6 @@ func (c *Fake) WatchEvents(request *events.Request) (*events.EventChannel, error
return new(events.EventChannel), nil return new(events.EventChannel), nil
} }
func (c *Fake) GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error) { func (c *Fake) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
return cadvisorapiv2.FsInfo{}, nil return cadvisorapiv2.FsInfo{}, nil
} }
...@@ -84,7 +84,7 @@ func (c *Mock) WatchEvents(request *events.Request) (*events.EventChannel, error ...@@ -84,7 +84,7 @@ func (c *Mock) WatchEvents(request *events.Request) (*events.EventChannel, error
return args.Get(0).(*events.EventChannel), args.Error(1) return args.Get(0).(*events.EventChannel), args.Error(1)
} }
func (c *Mock) GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error) { func (c *Mock) GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error) {
args := c.Called(uuid) args := c.Called(path)
return args.Get(0).(cadvisorapiv2.FsInfo), args.Error(1) return args.Get(0).(cadvisorapiv2.FsInfo), args.Error(1)
} }
...@@ -42,9 +42,8 @@ type Interface interface { ...@@ -42,9 +42,8 @@ type Interface interface {
// Get events streamed through passedChannel that fit the request. // Get events streamed through passedChannel that fit the request.
WatchEvents(request *events.Request) (*events.EventChannel, error) WatchEvents(request *events.Request) (*events.EventChannel, error)
// GetFsInfoByFsUUID returns the stats of the filesystem with the specified // Get filesystem information for the filesystem that contains the given file.
// uuid. GetDirFsInfo(path string) (cadvisorapiv2.FsInfo, error)
GetFsInfoByFsUUID(uuid string) (cadvisorapiv2.FsInfo, error)
} }
// ImageFsInfoProvider informs cAdvisor how to find imagefs for container images. // ImageFsInfoProvider informs cAdvisor how to find imagefs for container images.
......
...@@ -95,10 +95,10 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) { ...@@ -95,10 +95,10 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
podSandboxMap[s.Id] = s podSandboxMap[s.Id] = s
} }
// uuidToFsInfo is a map from filesystem UUID to its stats. This will be // fsIDtoInfo is a map from filesystem id to its stats. This will be used
// used as a cache to avoid querying cAdvisor for the filesystem stats with // as a cache to avoid querying cAdvisor for the filesystem stats with the
// the same UUID many times. // same filesystem id many times.
uuidToFsInfo := make(map[runtimeapi.StorageIdentifier]*cadvisorapiv2.FsInfo) fsIDtoInfo := make(map[runtimeapi.FilesystemIdentifier]*cadvisorapiv2.FsInfo)
// sandboxIDToPodStats is a temporary map from sandbox ID to its pod stats. // sandboxIDToPodStats is a temporary map from sandbox ID to its pod stats.
sandboxIDToPodStats := make(map[string]*statsapi.PodStats) sandboxIDToPodStats := make(map[string]*statsapi.PodStats)
...@@ -149,7 +149,7 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) { ...@@ -149,7 +149,7 @@ func (p *criStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
} }
sandboxIDToPodStats[podSandboxID] = ps sandboxIDToPodStats[podSandboxID] = ps
} }
cs := p.makeContainerStats(stats, container, &rootFsInfo, uuidToFsInfo) cs := p.makeContainerStats(stats, container, &rootFsInfo, fsIDtoInfo)
// If cadvisor stats is available for the container, use it to populate // If cadvisor stats is available for the container, use it to populate
// container stats // container stats
caStats, caFound := caInfos[containerID] caStats, caFound := caInfos[containerID]
...@@ -186,11 +186,11 @@ func (p *criStatsProvider) ImageFsStats() (*statsapi.FsStats, error) { ...@@ -186,11 +186,11 @@ func (p *criStatsProvider) ImageFsStats() (*statsapi.FsStats, error) {
UsedBytes: &fs.UsedBytes.Value, UsedBytes: &fs.UsedBytes.Value,
InodesUsed: &fs.InodesUsed.Value, InodesUsed: &fs.InodesUsed.Value,
} }
imageFsInfo := p.getFsInfo(fs.StorageId) imageFsInfo := p.getFsInfo(fs.GetFsId())
if imageFsInfo != nil { if imageFsInfo != nil {
// The image filesystem UUID is unknown to the local node or // The image filesystem id is unknown to the local node or there's
// there's an error on retrieving the stats. In these cases, we // an error on retrieving the stats. In these cases, we omit those
// omit those stats and return the best-effort partial result. See // stats and return the best-effort partial result. See
// https://github.com/kubernetes/heapster/issues/1793. // https://github.com/kubernetes/heapster/issues/1793.
s.AvailableBytes = &imageFsInfo.Available s.AvailableBytes = &imageFsInfo.Available
s.CapacityBytes = &imageFsInfo.Capacity s.CapacityBytes = &imageFsInfo.Capacity
...@@ -211,7 +211,7 @@ func (p *criStatsProvider) ImageFsDevice() (string, error) { ...@@ -211,7 +211,7 @@ func (p *criStatsProvider) ImageFsDevice() (string, error) {
return "", err return "", err
} }
for _, fs := range resp { for _, fs := range resp {
fsInfo := p.getFsInfo(fs.GetStorageId()) fsInfo := p.getFsInfo(fs.GetFsId())
if fsInfo != nil { if fsInfo != nil {
return fsInfo.Device, nil return fsInfo.Device, nil
} }
...@@ -220,16 +220,17 @@ func (p *criStatsProvider) ImageFsDevice() (string, error) { ...@@ -220,16 +220,17 @@ func (p *criStatsProvider) ImageFsDevice() (string, error) {
} }
// getFsInfo returns the information of the filesystem with the specified // getFsInfo returns the information of the filesystem with the specified
// storageID. If any error occurs, this function logs the error and returns // fsID. If any error occurs, this function logs the error and returns
// nil. // nil.
func (p *criStatsProvider) getFsInfo(storageID *runtimeapi.StorageIdentifier) *cadvisorapiv2.FsInfo { func (p *criStatsProvider) getFsInfo(fsID *runtimeapi.FilesystemIdentifier) *cadvisorapiv2.FsInfo {
if storageID == nil { if fsID == nil {
glog.V(2).Infof("Failed to get filesystem info: storageID is nil.") glog.V(2).Infof("Failed to get filesystem info: fsID is nil.")
return nil return nil
} }
fsInfo, err := p.cadvisor.GetFsInfoByFsUUID(storageID.Uuid) mountpoint := fsID.GetMountpoint()
fsInfo, err := p.cadvisor.GetDirFsInfo(mountpoint)
if err != nil { if err != nil {
msg := fmt.Sprintf("Failed to get the info of the filesystem with id %q: %v.", storageID.Uuid, err) msg := fmt.Sprintf("Failed to get the info of the filesystem with mountpoint %q: %v.", mountpoint, err)
if err == cadvisorfs.ErrNoSuchDevice { if err == cadvisorfs.ErrNoSuchDevice {
glog.V(2).Info(msg) glog.V(2).Info(msg)
} else { } else {
...@@ -275,7 +276,7 @@ func (p *criStatsProvider) makeContainerStats( ...@@ -275,7 +276,7 @@ func (p *criStatsProvider) makeContainerStats(
stats *runtimeapi.ContainerStats, stats *runtimeapi.ContainerStats,
container *runtimeapi.Container, container *runtimeapi.Container,
rootFsInfo *cadvisorapiv2.FsInfo, rootFsInfo *cadvisorapiv2.FsInfo,
uuidToFsInfo map[runtimeapi.StorageIdentifier]*cadvisorapiv2.FsInfo, fsIDtoInfo map[runtimeapi.FilesystemIdentifier]*cadvisorapiv2.FsInfo,
) *statsapi.ContainerStats { ) *statsapi.ContainerStats {
result := &statsapi.ContainerStats{ result := &statsapi.ContainerStats{
Name: stats.Attributes.Metadata.Name, Name: stats.Attributes.Metadata.Name,
...@@ -324,16 +325,16 @@ func (p *criStatsProvider) makeContainerStats( ...@@ -324,16 +325,16 @@ func (p *criStatsProvider) makeContainerStats(
result.Rootfs.InodesUsed = &stats.WritableLayer.InodesUsed.Value result.Rootfs.InodesUsed = &stats.WritableLayer.InodesUsed.Value
} }
} }
storageID := stats.GetWritableLayer().GetStorageId() fsID := stats.GetWritableLayer().GetFsId()
if storageID != nil { if fsID != nil {
imageFsInfo, found := uuidToFsInfo[*storageID] imageFsInfo, found := fsIDtoInfo[*fsID]
if !found { if !found {
imageFsInfo = p.getFsInfo(storageID) imageFsInfo = p.getFsInfo(fsID)
uuidToFsInfo[*storageID] = imageFsInfo fsIDtoInfo[*fsID] = imageFsInfo
} }
if imageFsInfo != nil { if imageFsInfo != nil {
// The image filesystem UUID is unknown to the local node or there's an // The image filesystem id is unknown to the local node or there's
// error on retrieving the stats. In these cases, we omit those stats // an error on retrieving the stats. In these cases, we omit those stats
// and return the best-effort partial result. See // and return the best-effort partial result. See
// https://github.com/kubernetes/heapster/issues/1793. // https://github.com/kubernetes/heapster/issues/1793.
result.Rootfs.AvailableBytes = &imageFsInfo.Available result.Rootfs.AvailableBytes = &imageFsInfo.Available
......
...@@ -63,26 +63,26 @@ func TestCRIListPodStats(t *testing.T) { ...@@ -63,26 +63,26 @@ func TestCRIListPodStats(t *testing.T) {
) )
var ( var (
imageFsStorageUUID = "imagefs-storage-uuid" imageFsMountpoint = "/test/mount/point"
unknownStorageUUID = "unknown-storage-uuid" unknownMountpoint = "/unknown/mount/point"
imageFsInfo = getTestFsInfo(2000) imageFsInfo = getTestFsInfo(2000)
rootFsInfo = getTestFsInfo(1000) rootFsInfo = getTestFsInfo(1000)
sandbox0 = makeFakePodSandbox("sandbox0-name", "sandbox0-uid", "sandbox0-ns") sandbox0 = makeFakePodSandbox("sandbox0-name", "sandbox0-uid", "sandbox0-ns")
container0 = makeFakeContainer(sandbox0, cName0, 0, false) container0 = makeFakeContainer(sandbox0, cName0, 0, false)
containerStats0 = makeFakeContainerStats(container0, imageFsStorageUUID) containerStats0 = makeFakeContainerStats(container0, imageFsMountpoint)
container1 = makeFakeContainer(sandbox0, cName1, 0, false) container1 = makeFakeContainer(sandbox0, cName1, 0, false)
containerStats1 = makeFakeContainerStats(container1, unknownStorageUUID) containerStats1 = makeFakeContainerStats(container1, unknownMountpoint)
sandbox1 = makeFakePodSandbox("sandbox1-name", "sandbox1-uid", "sandbox1-ns") sandbox1 = makeFakePodSandbox("sandbox1-name", "sandbox1-uid", "sandbox1-ns")
container2 = makeFakeContainer(sandbox1, cName2, 0, false) container2 = makeFakeContainer(sandbox1, cName2, 0, false)
containerStats2 = makeFakeContainerStats(container2, imageFsStorageUUID) containerStats2 = makeFakeContainerStats(container2, imageFsMountpoint)
sandbox2 = makeFakePodSandbox("sandbox2-name", "sandbox2-uid", "sandbox2-ns") sandbox2 = makeFakePodSandbox("sandbox2-name", "sandbox2-uid", "sandbox2-ns")
container3 = makeFakeContainer(sandbox2, cName3, 0, true) container3 = makeFakeContainer(sandbox2, cName3, 0, true)
containerStats3 = makeFakeContainerStats(container3, imageFsStorageUUID) containerStats3 = makeFakeContainerStats(container3, imageFsMountpoint)
container4 = makeFakeContainer(sandbox2, cName3, 1, false) container4 = makeFakeContainer(sandbox2, cName3, 1, false)
containerStats4 = makeFakeContainerStats(container4, imageFsStorageUUID) containerStats4 = makeFakeContainerStats(container4, imageFsMountpoint)
) )
var ( var (
...@@ -116,8 +116,8 @@ func TestCRIListPodStats(t *testing.T) { ...@@ -116,8 +116,8 @@ func TestCRIListPodStats(t *testing.T) {
mockCadvisor. mockCadvisor.
On("ContainerInfoV2", "/", options).Return(infos, nil). On("ContainerInfoV2", "/", options).Return(infos, nil).
On("RootFsInfo").Return(rootFsInfo, nil). On("RootFsInfo").Return(rootFsInfo, nil).
On("GetFsInfoByFsUUID", imageFsStorageUUID).Return(imageFsInfo, nil). On("GetDirFsInfo", imageFsMountpoint).Return(imageFsInfo, nil).
On("GetFsInfoByFsUUID", unknownStorageUUID).Return(cadvisorapiv2.FsInfo{}, cadvisorfs.ErrNoSuchDevice) On("GetDirFsInfo", unknownMountpoint).Return(cadvisorapiv2.FsInfo{}, cadvisorfs.ErrNoSuchDevice)
fakeRuntimeService.SetFakeSandboxes([]*critest.FakePodSandbox{ fakeRuntimeService.SetFakeSandboxes([]*critest.FakePodSandbox{
sandbox0, sandbox1, sandbox2, sandbox0, sandbox1, sandbox2,
}) })
...@@ -209,9 +209,9 @@ func TestCRIListPodStats(t *testing.T) { ...@@ -209,9 +209,9 @@ func TestCRIListPodStats(t *testing.T) {
func TestCRIImagesFsStats(t *testing.T) { func TestCRIImagesFsStats(t *testing.T) {
var ( var (
imageFsStorageUUID = "imagefs-storage-uuid" imageFsMountpoint = "/test/mount/point"
imageFsInfo = getTestFsInfo(2000) imageFsInfo = getTestFsInfo(2000)
imageFsUsage = makeFakeImageFsUsage(imageFsStorageUUID) imageFsUsage = makeFakeImageFsUsage(imageFsMountpoint)
) )
var ( var (
mockCadvisor = new(cadvisortest.Mock) mockCadvisor = new(cadvisortest.Mock)
...@@ -222,7 +222,7 @@ func TestCRIImagesFsStats(t *testing.T) { ...@@ -222,7 +222,7 @@ func TestCRIImagesFsStats(t *testing.T) {
fakeImageService = critest.NewFakeImageService() fakeImageService = critest.NewFakeImageService()
) )
mockCadvisor.On("GetFsInfoByFsUUID", imageFsStorageUUID).Return(imageFsInfo, nil) mockCadvisor.On("GetDirFsInfo", imageFsMountpoint).Return(imageFsInfo, nil)
fakeImageService.SetFakeFilesystemUsage([]*runtimeapi.FilesystemUsage{ fakeImageService.SetFakeFilesystemUsage([]*runtimeapi.FilesystemUsage{
imageFsUsage, imageFsUsage,
}) })
...@@ -292,7 +292,7 @@ func makeFakeContainer(sandbox *critest.FakePodSandbox, name string, attempt uin ...@@ -292,7 +292,7 @@ func makeFakeContainer(sandbox *critest.FakePodSandbox, name string, attempt uin
return c return c
} }
func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string) *runtimeapi.ContainerStats { func makeFakeContainerStats(container *critest.FakeContainer, imageFsMountpoint string) *runtimeapi.ContainerStats {
containerStats := &runtimeapi.ContainerStats{ containerStats := &runtimeapi.ContainerStats{
Attributes: &runtimeapi.ContainerAttributes{ Attributes: &runtimeapi.ContainerAttributes{
Id: container.ContainerStatus.Id, Id: container.ContainerStatus.Id,
...@@ -300,7 +300,7 @@ func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string ...@@ -300,7 +300,7 @@ func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string
}, },
WritableLayer: &runtimeapi.FilesystemUsage{ WritableLayer: &runtimeapi.FilesystemUsage{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
StorageId: &runtimeapi.StorageIdentifier{Uuid: imageFsUUID}, FsId: &runtimeapi.FilesystemIdentifier{Mountpoint: imageFsMountpoint},
UsedBytes: &runtimeapi.UInt64Value{Value: rand.Uint64() / 100}, UsedBytes: &runtimeapi.UInt64Value{Value: rand.Uint64() / 100},
InodesUsed: &runtimeapi.UInt64Value{Value: rand.Uint64() / 100}, InodesUsed: &runtimeapi.UInt64Value{Value: rand.Uint64() / 100},
}, },
...@@ -321,10 +321,10 @@ func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string ...@@ -321,10 +321,10 @@ func makeFakeContainerStats(container *critest.FakeContainer, imageFsUUID string
return containerStats return containerStats
} }
func makeFakeImageFsUsage(fsUUID string) *runtimeapi.FilesystemUsage { func makeFakeImageFsUsage(fsMountpoint string) *runtimeapi.FilesystemUsage {
return &runtimeapi.FilesystemUsage{ return &runtimeapi.FilesystemUsage{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
StorageId: &runtimeapi.StorageIdentifier{Uuid: fsUUID}, FsId: &runtimeapi.FilesystemIdentifier{Mountpoint: fsMountpoint},
UsedBytes: &runtimeapi.UInt64Value{Value: rand.Uint64()}, UsedBytes: &runtimeapi.UInt64Value{Value: rand.Uint64()},
InodesUsed: &runtimeapi.UInt64Value{Value: rand.Uint64()}, InodesUsed: &runtimeapi.UInt64Value{Value: rand.Uint64()},
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment