github.com/kubewharf/katalyst-core@v0.5.3/pkg/metaserver/agent/metric/metric_provisoner.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 metric
    18  
    19  import (
    20  	"sync"
    21  
    22  	"github.com/kubewharf/katalyst-core/pkg/config/agent/global"
    23  	"github.com/kubewharf/katalyst-core/pkg/config/agent/metaserver"
    24  	"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/provisioner/cgroup"
    25  	"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/provisioner/kubelet"
    26  	"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/provisioner/malachite"
    27  	"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/provisioner/rodan"
    28  	"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/metric/types"
    29  	"github.com/kubewharf/katalyst-core/pkg/metaserver/agent/pod"
    30  	"github.com/kubewharf/katalyst-core/pkg/metrics"
    31  	utilmetric "github.com/kubewharf/katalyst-core/pkg/util/metric"
    32  )
    33  
    34  func init() {
    35  	RegisterProvisioners(metaserver.MetricProvisionerMalachite, malachite.NewMalachiteMetricsProvisioner)
    36  	RegisterProvisioners(metaserver.MetricProvisionerKubelet, kubelet.NewKubeletSummaryProvisioner)
    37  	RegisterProvisioners(metaserver.MetricProvisionerCgroup, cgroup.NewCGroupMetricsProvisioner)
    38  	RegisterProvisioners(metaserver.MetricProvisionerRodan, rodan.NewRodanMetricsProvisioner)
    39  }
    40  
    41  type ProvisionerInitFunc func(baseConf *global.BaseConfiguration, metricConf *metaserver.MetricConfiguration,
    42  	emitter metrics.MetricEmitter, fetcher pod.PodFetcher, metricStore *utilmetric.MetricStore) types.MetricsProvisioner
    43  
    44  // provisioners stores the initializing function for each-provisioner
    45  var provisioners sync.Map
    46  
    47  // RegisterProvisioners registers user-defined resource plugin init functions
    48  func RegisterProvisioners(name string, initFunc ProvisionerInitFunc) {
    49  	provisioners.Store(name, initFunc)
    50  }
    51  
    52  // getProvisioners returns provisioner with initialized functions
    53  func getProvisioners() map[string]ProvisionerInitFunc {
    54  	results := make(map[string]ProvisionerInitFunc)
    55  	provisioners.Range(func(key, value interface{}) bool {
    56  		results[key.(string)] = value.(ProvisionerInitFunc)
    57  		return true
    58  	})
    59  	return results
    60  }