Ejemplo n.º 1
0
func StorageDriverTestMaxMemoryUsage(driver storage.StorageDriver, t *testing.T) {
	defer driver.Close()
	N := 100
	memTrace := make([]uint64, N)
	cpuTrace := make([]uint64, N)
	for i := 0; i < N; i++ {
		memTrace[i] = uint64(i + 1)
		cpuTrace[i] = uint64(1)
	}

	ref := info.ContainerReference{
		Name: "container",
	}

	trace := buildTrace(cpuTrace, memTrace, 1*time.Second)

	for _, stats := range trace {
		driver.AddStats(ref, stats)
	}

	percentiles, err := driver.Percentiles(ref.Name, []int{50}, []int{50})
	if err != nil {
		t.Errorf("unable to call Percentiles(): %v", err)
	}
	maxUsage := uint64(N)
	if percentiles.MaxMemoryUsage != maxUsage {
		t.Fatalf("Max memory usage should be %v; received %v", maxUsage, percentiles.MaxMemoryUsage)
	}
}
Ejemplo n.º 2
0
func StorageDriverTestPercentiles(driver storage.StorageDriver, t *testing.T) {
	defer driver.Close()
	N := 100
	cpuTrace := make([]uint64, N)
	memTrace := make([]uint64, N)
	for i := 1; i < N+1; i++ {
		cpuTrace[i-1] = uint64(i)
		memTrace[i-1] = uint64(i)
	}

	trace := buildTrace(cpuTrace, memTrace, 1*time.Second)

	ref := info.ContainerReference{
		Name: "container",
	}
	for _, stats := range trace {
		driver.AddStats(ref, stats)
	}
	percentages := []int{
		80,
		90,
		50,
	}
	percentiles, err := driver.Percentiles(ref.Name, percentages, percentages)
	if err != nil {
		t.Fatal(err)
	}
	for _, x := range percentiles.CpuUsagePercentiles {
		for _, y := range percentiles.CpuUsagePercentiles {
			// lower percentage, smaller value
			if x.Percentage < y.Percentage && x.Value > y.Value {
				t.Errorf("%v percent is %v; while %v percent is %v",
					x.Percentage, x.Value, y.Percentage, y.Value)
			}
		}
	}
	for _, x := range percentiles.MemoryUsagePercentiles {
		for _, y := range percentiles.MemoryUsagePercentiles {
			if x.Percentage < y.Percentage && x.Value > y.Value {
				t.Errorf("%v percent is %v; while %v percent is %v",
					x.Percentage, x.Value, y.Percentage, y.Value)
			}
		}
	}
}
Ejemplo n.º 3
0
func StorageDriverTestPercentilesWithoutStats(driver storage.StorageDriver, t *testing.T) {
	defer driver.Close()
	nonExistContainer := "somerandomecontainer"
	percentiles, _ := driver.Percentiles(nonExistContainer, []int{50, 80}, []int{50, 80})
	if percentiles == nil {
		return
	}
	if percentiles.MaxMemoryUsage != 0 {
		t.Errorf("Percentiles() reports max memory usage > 0 when there's no stats.")
	}
	for _, p := range percentiles.CpuUsagePercentiles {
		if p.Value != 0 {
			t.Errorf("Percentiles() reports cpu usage is %v when there's no stats.", p.Value)
		}
	}
	for _, p := range percentiles.MemoryUsagePercentiles {
		if p.Value != 0 {
			t.Errorf("Percentiles() reports memory usage is %v when there's no stats.", p.Value)
		}
	}
}
Ejemplo n.º 4
0
func StorageDriverTestPercentilesWithoutSample(driver storage.StorageDriver, t *testing.T) {
	defer driver.Close()
	trace := buildTrace(
		[]uint64{10},
		[]uint64{10},
		1*time.Second)
	ref := info.ContainerReference{
		Name: "container",
	}
	driver.AddStats(ref, trace[0])
	percentiles, err := driver.Percentiles(
		ref.Name,
		[]int{50},
		[]int{50},
	)
	if err != nil {
		t.Fatal(err)
	}
	if percentiles != nil {
		t.Errorf("There should be no percentiles")
	}
}
Ejemplo n.º 5
0
func StorageDriverTestMaxMemoryUsage(driver storage.StorageDriver, t *testing.T) {
	defer driver.Close()
	N := 100
	memTrace := make([]uint64, N)
	cpuTrace := make([]uint64, N)
	for i := 0; i < N; i++ {
		memTrace[i] = uint64(i + 1)
		cpuTrace[i] = uint64(1)
	}

	ref := info.ContainerReference{
		Name: "container",
	}

	trace := buildTrace(cpuTrace, memTrace, 1*time.Second)

	for _, stats := range trace {
		err := driver.AddStats(ref, stats)
		if err != nil {
			t.Fatalf("unable to add stats: %v", err)
		}
		// set the trace to something else. The stats stored in the
		// storage should not be affected.
		stats.Cpu.Usage.Total = 0
		stats.Cpu.Usage.System = 0
		stats.Cpu.Usage.User = 0
		stats.Memory.Usage = 0
	}

	percentiles, err := driver.Percentiles(ref.Name, []int{50}, []int{50})
	if err != nil {
		t.Errorf("unable to call Percentiles(): %v", err)
	}
	maxUsage := uint64(N)
	if percentiles.MaxMemoryUsage != maxUsage {
		t.Fatalf("Max memory usage should be %v; received %v", maxUsage, percentiles.MaxMemoryUsage)
	}
}