mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-11 22:20:18 +00:00
Add the metric data for different extension points
Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
@@ -53,13 +53,14 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
configFile = "config/performance-config.yaml"
|
||||
createNodesOpcode = "createNodes"
|
||||
createNamespacesOpcode = "createNamespaces"
|
||||
createPodsOpcode = "createPods"
|
||||
createPodSetsOpcode = "createPodSets"
|
||||
churnOpcode = "churn"
|
||||
barrierOpcode = "barrier"
|
||||
configFile = "config/performance-config.yaml"
|
||||
createNodesOpcode = "createNodes"
|
||||
createNamespacesOpcode = "createNamespaces"
|
||||
createPodsOpcode = "createPods"
|
||||
createPodSetsOpcode = "createPodSets"
|
||||
churnOpcode = "churn"
|
||||
barrierOpcode = "barrier"
|
||||
extensionPointsLabelName = "extension_point"
|
||||
|
||||
// Two modes supported in "churn" operator.
|
||||
|
||||
@@ -71,11 +72,13 @@ const (
|
||||
|
||||
var (
|
||||
defaultMetricsCollectorConfig = metricsCollectorConfig{
|
||||
Metrics: []string{
|
||||
"scheduler_scheduling_algorithm_predicate_evaluation_seconds",
|
||||
"scheduler_scheduling_algorithm_priority_evaluation_seconds",
|
||||
"scheduler_e2e_scheduling_duration_seconds",
|
||||
"scheduler_pod_scheduling_duration_seconds",
|
||||
Metrics: map[string]*labelValues{
|
||||
"scheduler_framework_extension_point_duration_seconds": {
|
||||
label: extensionPointsLabelName,
|
||||
values: []string{"Filter", "Score"},
|
||||
},
|
||||
"scheduler_e2e_scheduling_duration_seconds": nil,
|
||||
"scheduler_pod_scheduling_duration_seconds": nil,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@@ -177,9 +177,15 @@ func dataItems2JSONFile(dataItems DataItems, namePrefix string) error {
|
||||
return ioutil.WriteFile(destFile, b, 0644)
|
||||
}
|
||||
|
||||
type labelValues struct {
|
||||
label string
|
||||
values []string
|
||||
}
|
||||
|
||||
// metricsCollectorConfig is the config to be marshalled to YAML config file.
|
||||
// NOTE: The mapping here means only one filter is supported, either value in the list of `values` is able to be collected.
|
||||
type metricsCollectorConfig struct {
|
||||
Metrics []string
|
||||
Metrics map[string]*labelValues
|
||||
}
|
||||
|
||||
// metricsCollector collects metrics from legacyregistry.DefaultGatherer.Gather() endpoint.
|
||||
@@ -202,22 +208,38 @@ func (*metricsCollector) run(ctx context.Context) {
|
||||
|
||||
func (pc *metricsCollector) collect() []DataItem {
|
||||
var dataItems []DataItem
|
||||
for _, metric := range pc.Metrics {
|
||||
dataItem := collectHistogramVec(metric, pc.labels)
|
||||
if dataItem != nil {
|
||||
dataItems = append(dataItems, *dataItem)
|
||||
for name, labelVals := range pc.Metrics {
|
||||
metricFamily, err := testutil.GetMetricFamilyFromGatherer(legacyregistry.DefaultGatherer, name)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return dataItems
|
||||
}
|
||||
// no filter is specified, aggregate all the metrics within the same metricFamily.
|
||||
if labelVals == nil {
|
||||
vec := testutil.GetHistogramVec(metricFamily, nil)
|
||||
dataItem := collectHistogramData(vec, pc.labels, nil, name)
|
||||
if dataItem != nil {
|
||||
dataItems = append(dataItems, *dataItem)
|
||||
}
|
||||
} else {
|
||||
// fetch the metric from metricFamily which match each of the lvMap.
|
||||
for _, value := range labelVals.values {
|
||||
lvMap := map[string]string{labelVals.label: value}
|
||||
vec := testutil.GetHistogramVec(metricFamily, lvMap)
|
||||
dataItem := collectHistogramData(vec, pc.labels, lvMap, name)
|
||||
if dataItem != nil {
|
||||
dataItems = append(dataItems, *dataItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataItems
|
||||
}
|
||||
|
||||
func collectHistogramVec(metric string, labels map[string]string) *DataItem {
|
||||
vec, err := testutil.GetHistogramVecFromGatherer(legacyregistry.DefaultGatherer, metric, nil)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
func collectHistogramData(vec testutil.HistogramVec, labels, lvMap map[string]string, metric string) *DataItem {
|
||||
if len(vec) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := vec.Validate(); err != nil {
|
||||
klog.Error(err)
|
||||
return nil
|
||||
@@ -236,6 +258,9 @@ func collectHistogramVec(metric string, labels map[string]string) *DataItem {
|
||||
for k, v := range labels {
|
||||
labelMap[k] = v
|
||||
}
|
||||
for k, v := range lvMap {
|
||||
labelMap[k] = v
|
||||
}
|
||||
return &DataItem{
|
||||
Labels: labelMap,
|
||||
Data: map[string]float64{
|
||||
|
Reference in New Issue
Block a user