github.com/kubewharf/katalyst-core@v0.5.3/pkg/agent/sysadvisor/plugin/overcommitmentaware/overcommitment_aware.go (about)

     1  /*
     2  Copyright 2022 The Katalyst Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package overcommitmentaware
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/metacache"
    23  	"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin"
    24  	"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/overcommitmentaware/realtime"
    25  	"github.com/kubewharf/katalyst-core/pkg/agent/sysadvisor/plugin/overcommitmentaware/reporter"
    26  	"github.com/kubewharf/katalyst-core/pkg/config"
    27  	"github.com/kubewharf/katalyst-core/pkg/metaserver"
    28  	"github.com/kubewharf/katalyst-core/pkg/metrics"
    29  	metricspool "github.com/kubewharf/katalyst-core/pkg/metrics/metrics-pool"
    30  )
    31  
    32  const (
    33  	PluginName = "overcommitment-aware-plugin"
    34  )
    35  
    36  // OvercommitmentAwarePlugin calculates node overcommitment ratio,
    37  // values will be reported to node KCNR annotations by the reporter.
    38  type OvercommitmentAwarePlugin struct {
    39  	name string
    40  
    41  	realtimeAdvisor *realtime.RealtimeOvercommitmentAdvisor
    42  	reporter        reporter.OvercommitRatioReporter
    43  
    44  	emitter metrics.MetricEmitter
    45  }
    46  
    47  func NewOvercommitmentAwarePlugin(
    48  	pluginName string, conf *config.Configuration,
    49  	_ interface{},
    50  	emitterPool metricspool.MetricsEmitterPool,
    51  	metaServer *metaserver.MetaServer,
    52  	_ metacache.MetaCache,
    53  ) (plugin.SysAdvisorPlugin, error) {
    54  	emitter := emitterPool.GetDefaultMetricsEmitter()
    55  
    56  	realtimeOvercommitmentAdvisor := realtime.NewRealtimeOvercommitmentAdvisor(conf, metaServer, emitter)
    57  
    58  	overcommitRatioReporter, err := reporter.NewOvercommitRatioReporter(emitter, conf, realtimeOvercommitmentAdvisor, metaServer)
    59  	if err != nil {
    60  		return nil, err
    61  	}
    62  
    63  	op := &OvercommitmentAwarePlugin{
    64  		name: pluginName,
    65  
    66  		realtimeAdvisor: realtimeOvercommitmentAdvisor,
    67  		reporter:        overcommitRatioReporter,
    68  	}
    69  
    70  	return op, nil
    71  }
    72  
    73  func (op *OvercommitmentAwarePlugin) Run(ctx context.Context) {
    74  	go op.realtimeAdvisor.Run(ctx)
    75  
    76  	go op.reporter.Run(ctx)
    77  }
    78  
    79  func (op *OvercommitmentAwarePlugin) Name() string {
    80  	return op.name
    81  }
    82  
    83  func (op *OvercommitmentAwarePlugin) Init() error {
    84  	return nil
    85  }