Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions info/v2/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ type Percentiles struct {
Ninety uint64 `json:"ninety"`
// 95th percentile over the collected sample.
NinetyFive uint64 `json:"ninetyfive"`
// Number of samples used to calculate these percentiles.
Count uint64 `json:"count"`
}

type Usage struct {
Expand Down
3 changes: 3 additions & 0 deletions summary/percentiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func (r *resource) AddSample(val uint64) {
Fifty: val,
Ninety: val,
NinetyFive: val,
Count: 1,
}
r.Add(sample)
}
Expand All @@ -121,6 +122,8 @@ func (r *resource) GetAllPercentiles() info.Percentiles {
p.Fifty = r.samples.GetPercentile(0.5)
p.Ninety = r.samples.GetPercentile(0.9)
p.NinetyFive = r.samples.GetPercentile(0.95)
// len(samples) is equal to count stored in mean.
p.Count = r.mean.count
p.Present = true
return p
}
Expand Down
9 changes: 9 additions & 0 deletions summary/percentiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func TestAggregates(t *testing.T) {
Fifty: 1000,
Ninety: 1000,
NinetyFive: 1000,
// Since cpu is calculated between samples, we lose 1 sample.
Count: N - 2,
}
if usage.Cpu != cpuExpected {
t.Errorf("cpu stats are %+v. Expected %+v", usage.Cpu, cpuExpected)
Expand All @@ -95,6 +97,7 @@ func TestAggregates(t *testing.T) {
Fifty: 50 * 1024,
Ninety: 90 * 1024,
NinetyFive: 95 * 1024,
Count: N - 1,
}
if usage.Memory != memExpected {
t.Errorf("memory stats are mean %+v. Expected %+v", usage.Memory, memExpected)
Expand Down Expand Up @@ -133,6 +136,8 @@ func TestSamplesCloseInTimeIgnored(t *testing.T) {
Fifty: 1000,
Ninety: 1000,
NinetyFive: 1000,
// Since cpu is calculated between samples, we lose 1 sample.
Count: N - 2,
}
if usage.Cpu != cpuExpected {
t.Errorf("cpu stats are %+v. Expected %+v", usage.Cpu, cpuExpected)
Expand All @@ -144,6 +149,7 @@ func TestSamplesCloseInTimeIgnored(t *testing.T) {
Fifty: 50 * 1024,
Ninety: 90 * 1024,
NinetyFive: 95 * 1024,
Count: N - 1,
}
if usage.Memory != memExpected {
t.Errorf("memory stats are mean %+v. Expected %+v", usage.Memory, memExpected)
Expand Down Expand Up @@ -184,6 +190,8 @@ func TestDerivedStats(t *testing.T) {
Fifty: 50 * Nanosecond,
Ninety: 90 * Nanosecond,
NinetyFive: 95 * Nanosecond,
// GetDerivedPercentiles calculates directly from samples, hence we don't lose any samples.
Count: N - 1,
}
if usage.Cpu != cpuExpected {
t.Errorf("cpu stats are %+v. Expected %+v", usage.Cpu, cpuExpected)
Expand All @@ -195,6 +203,7 @@ func TestDerivedStats(t *testing.T) {
Fifty: 50 * 1024,
Ninety: 90 * 1024,
NinetyFive: 95 * 1024,
Count: N - 1,
}
if usage.Memory != memExpected {
t.Errorf("memory stats are mean %+v. Expected %+v", usage.Memory, memExpected)
Expand Down