Skip to content

Commit

Permalink
Replace average scaling ratio with min scaling ratio for perf aggregated
Browse files Browse the repository at this point in the history
Signed-off-by: Katarzyna Kujawa <katarzyna.kujawa@intel.com>
  • Loading branch information
katarzyna-z committed Jul 9, 2020
1 parent d370486 commit 821ed4b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 18 deletions.
2 changes: 1 addition & 1 deletion docs/runtime_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Core perf events can be exposed on Prometheus endpoint per CPU or aggregated by
- `--disable_metrics="percpu"` - core perf events are aggregated
- `--disable_metrics=""` - core perf events are exposed per CPU.

Aggregated form of core perf events significantly decrease volume of data. For aggregated form of core perf events scaling ratio (`container_perf_metric_scaling ratio`) indicates average scaling ratio for specific event.
Aggregated form of core perf events significantly decrease volume of data. For aggregated form of core perf events scaling ratio (`container_perf_metric_scaling ratio`) indicates the lowest value of scaling ratio for specific event to show the worst precision.

### Perf subsystem introduction

Expand Down
25 changes: 13 additions & 12 deletions metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1586,7 +1586,7 @@ func NewPrometheusCollector(i infoProvider, f ContainerLabelsFunc, includedMetri
valueType: prometheus.GaugeValue,
extraLabels: []string{"cpu", "event"},
getValues: func(s *info.ContainerStats) metricValues {
return getAvgCoreScalingRatio(s)
return getMinCoreScalingRatio(s)
},
}}...)
}
Expand Down Expand Up @@ -1954,22 +1954,23 @@ func getAggregatedCorePerfEvents(s *info.ContainerStats) metricValues {
return values
}

func getAvgCoreScalingRatio(s *info.ContainerStats) metricValues {
func getMinCoreScalingRatio(s *info.ContainerStats) metricValues {
values := make(metricValues, 0)
perfEventStatAgg := make(map[string][]float64)
// collect scaling ratios for event
perfEventStatMin := make(map[string]float64)
// search for minimal value of scalin ratio for specific event
for _, perfStat := range s.PerfStats {
perfEventStatAgg[perfStat.Name] = append(perfEventStatAgg[perfStat.Name], perfStat.ScalingRatio)
}
// calculate average scaling ratio
for perfEvent, perfScalingRatio := range perfEventStatAgg {
sumScalingRatio := 0.0
for _, scalingRatio := range perfScalingRatio {
sumScalingRatio += scalingRatio
if _, ok := perfEventStatMin[perfStat.Name]; !ok {
// found a new event
perfEventStatMin[perfStat.Name] = perfStat.ScalingRatio
} else if perfStat.ScalingRatio < perfEventStatMin[perfStat.Name] {
// found a lower value of scaling ration so replace the minimal value
perfEventStatMin[perfStat.Name] = perfStat.ScalingRatio
}
}

for perfEvent, perfScalingRatio := range perfEventStatMin {
values = append(values, metricValue{
value: sumScalingRatio / float64(len(perfScalingRatio)),
value: perfScalingRatio,
labels: []string{"", perfEvent},
timestamp: s.Timestamp,
})
Expand Down
34 changes: 31 additions & 3 deletions metrics/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ func TestGetPerCpuCorePerfEvents(t *testing.T) {
}
metricVals := getPerCPUCorePerfEvents(containerStats)
assert.Equal(t, 4, len(metricVals))
values := []float64{}
for _, metric := range metricVals {
values = append(values, metric.value)
}
assert.Contains(t, values, 123.0)
assert.Contains(t, values, 456.0)
assert.Contains(t, values, 321.0)
assert.Contains(t, values, 789.0)
}

func TestGetPerCpuCoreScalingRatio(t *testing.T) {
Expand Down Expand Up @@ -204,9 +212,17 @@ func TestGetPerCpuCoreScalingRatio(t *testing.T) {
}
metricVals := getPerCPUCoreScalingRatio(containerStats)
assert.Equal(t, 4, len(metricVals))
values := []float64{}
for _, metric := range metricVals {
values = append(values, metric.value)
}
assert.Contains(t, values, 1.0)
assert.Contains(t, values, 0.5)
assert.Contains(t, values, 0.7)
assert.Contains(t, values, 0.3)
}

func TestGetCorePerfEventsAggregated(t *testing.T) {
func TestGetAggCorePerfEvents(t *testing.T) {
containerStats := &info.ContainerStats{
Timestamp: time.Unix(1395066367, 0),
PerfStats: []info.PerfStat{
Expand Down Expand Up @@ -238,9 +254,15 @@ func TestGetCorePerfEventsAggregated(t *testing.T) {
}
metricVals := getAggregatedCorePerfEvents(containerStats)
assert.Equal(t, 2, len(metricVals))
values := []float64{}
for _, metric := range metricVals {
values = append(values, metric.value)
}
assert.Contains(t, values, 579.0)
assert.Contains(t, values, 1110.0)
}

func TestGetCoreScalingRatioAverage(t *testing.T) {
func TestGetMinCoreScalingRatio(t *testing.T) {
containerStats := &info.ContainerStats{
Timestamp: time.Unix(1395066367, 0),
PerfStats: []info.PerfStat{
Expand Down Expand Up @@ -270,6 +292,12 @@ func TestGetCoreScalingRatioAverage(t *testing.T) {
},
},
}
metricVals := getAvgCoreScalingRatio(containerStats)
metricVals := getMinCoreScalingRatio(containerStats)
assert.Equal(t, 2, len(metricVals))
values := []float64{}
for _, metric := range metricVals {
values = append(values, metric.value)
}
assert.Contains(t, values, 0.5)
assert.Contains(t, values, 0.3)
}
4 changes: 2 additions & 2 deletions metrics/testdata/prometheus_metrics_perf_aggregated
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cadvisor_version_info{cadvisorRevision="abcdef",cadvisorVersion="0.16.0",dockerV
container_last_seen{container_env_foo_env="prod",container_label_foo_label="bar",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 1.395066363e+09 1395066363000
# HELP container_perf_events_scaling_ratio Perf event metric scaling ratio.
# TYPE container_perf_events_scaling_ratio gauge
container_perf_events_scaling_ratio{container_env_foo_env="prod",container_label_foo_label="bar",cpu="",event="instructions",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 0.75 1395066363000
container_perf_events_scaling_ratio{container_env_foo_env="prod",container_label_foo_label="bar",cpu="",event="instructions_retired",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 0.499999999995 1395066363000
container_perf_events_scaling_ratio{container_env_foo_env="prod",container_label_foo_label="bar",cpu="",event="instructions",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 0.5 1395066363000
container_perf_events_scaling_ratio{container_env_foo_env="prod",container_label_foo_label="bar",cpu="",event="instructions_retired",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 0.33333333333 1395066363000
# HELP container_perf_events_total Perf event metric.
# TYPE container_perf_events_total counter
container_perf_events_total{container_env_foo_env="prod",container_label_foo_label="bar",cpu="",event="instructions",id="testcontainer",image="test",name="testcontaineralias",zone_name="hello"} 579 1395066363000
Expand Down

0 comments on commit 821ed4b

Please sign in to comment.