MCPcopy
hub / github.com/google/cadvisor / TestDockerFilesystemStats

Function TestDockerFilesystemStats

integration/tests/api/docker_test.go:324–402  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

322}
323
324func TestDockerFilesystemStats(t *testing.T) {
325 fm := framework.New(t)
326 defer fm.Cleanup()
327
328 storageDriver := fm.Docker().StorageDriver()
329 if storageDriver == framework.DeviceMapper {
330 // Filesystem stats not supported with devicemapper, yet
331 return
332 }
333
334 const (
335 ddUsage = uint64(1 << 3) // 1 KB
336 sleepDuration = 10 * time.Second
337 )
338 // Wait for the container to show up.
339 // FIXME: Tests should be bundled and run on the remote host instead of being run over ssh.
340 // Escaping bash over ssh is ugly.
341 // Once github issue 1130 is fixed, this logic can be removed.
342 dockerCmd := fmt.Sprintf("dd if=/dev/zero of=/file count=2 bs=%d & ping google.com", ddUsage)
343 if fm.Hostname().Host != "localhost" {
344 dockerCmd = fmt.Sprintf("'%s'", dockerCmd)
345 }
346 containerID := fm.Docker().RunBusybox("/bin/sh", "-c", dockerCmd)
347 waitForContainer(containerID, fm)
348 request := &v2.RequestOptions{
349 IdType: v2.TypeDocker,
350 Count: 1,
351 }
352 needsBaseUsageCheck := false
353 switch storageDriver {
354 case framework.Aufs, framework.Overlay, framework.Overlay2, framework.DeviceMapper:
355 needsBaseUsageCheck = true
356 }
357 pass := false
358 // We need to wait for the `dd` operation to complete.
359 for i := 0; i < 10; i++ {
360 containerInfo, err := fm.Cadvisor().ClientV2().Stats(containerID, request)
361 if err != nil {
362 t.Logf("%v stats unavailable - %v", time.Now().String(), err)
363 t.Logf("retrying after %s...", sleepDuration.String())
364 time.Sleep(sleepDuration)
365
366 continue
367 }
368 require.Equal(t, len(containerInfo), 1)
369 var info v2.ContainerInfo
370 // There is only one container in containerInfo. Since it is a map with unknown key,
371 // use the value blindly.
372 for _, cInfo := range containerInfo {
373 info = cInfo
374 }
375 sanityCheckV2(containerID, info, t)
376
377 require.NotNil(t, info.Stats[0], "got info: %+v", info)
378 require.NotNil(t, info.Stats[0].Filesystem, "got info: %+v", info)
379 require.NotNil(t, info.Stats[0].Filesystem.TotalUsageBytes, "got info: %+v", info.Stats[0].Filesystem)
380 if *info.Stats[0].Filesystem.TotalUsageBytes >= ddUsage {
381 if !needsBaseUsageCheck {

Callers

nothing calls this directly

Calls 12

NewFunction · 0.92
waitForContainerFunction · 0.85
sanityCheckV2Function · 0.85
StatsMethod · 0.80
CleanupMethod · 0.65
StorageDriverMethod · 0.65
DockerMethod · 0.65
HostnameMethod · 0.65
RunBusyboxMethod · 0.65
ClientV2Method · 0.65
CadvisorMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…