scheduler_perf: refactor to allow arbitrary workloads

Signed-off-by: Adhityaa Chandrasekar <adtac@google.com>
This commit is contained in:
Adhityaa Chandrasekar
2020-07-11 01:13:34 +00:00
parent d159ae3545
commit 71bc9ce9c2
8 changed files with 930 additions and 488 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package benchmark
import (
"context"
"encoding/json"
"flag"
"fmt"
@@ -147,18 +148,18 @@ type metricsCollectorConfig struct {
// metricsCollector collects metrics from legacyregistry.DefaultGatherer.Gather() endpoint.
// Currently only Histrogram metrics are supported.
type metricsCollector struct {
metricsCollectorConfig
*metricsCollectorConfig
labels map[string]string
}
func newMetricsCollector(config metricsCollectorConfig, labels map[string]string) *metricsCollector {
func newMetricsCollector(config *metricsCollectorConfig, labels map[string]string) *metricsCollector {
return &metricsCollector{
metricsCollectorConfig: config,
labels: labels,
}
}
func (*metricsCollector) run(stopCh chan struct{}) {
func (*metricsCollector) run(ctx context.Context) {
// metricCollector doesn't need to start before the tests, so nothing to do here.
}
@@ -231,7 +232,7 @@ func newThroughputCollector(podInformer coreinformers.PodInformer, labels map[st
}
}
func (tc *throughputCollector) run(stopCh chan struct{}) {
func (tc *throughputCollector) run(ctx context.Context) {
podsScheduled, err := getScheduledPods(tc.podInformer, tc.namespaces...)
if err != nil {
klog.Fatalf("%v", err)
@@ -239,8 +240,9 @@ func (tc *throughputCollector) run(stopCh chan struct{}) {
lastScheduledCount := len(podsScheduled)
for {
select {
case <-stopCh:
case <-ctx.Done():
return
// TODO(#94665): use time.Ticker instead
case <-time.After(throughputSampleFrequency):
podsScheduled, err := getScheduledPods(tc.podInformer, tc.namespaces...)
if err != nil {