github.com/kubewharf/katalyst-core@v0.5.3/pkg/metrics/metrics-pool/metrics_pool.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 metrics_pool
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/kubewharf/katalyst-core/pkg/metrics"
    23  )
    24  
    25  // MetricsEmitterPool is a metrics emitter pool for metrics emitter.
    26  // it stores all the emitter implementations, and provide a getter
    27  // function to acquire them. this thought is much like the thread pool.
    28  type MetricsEmitterPool interface {
    29  	// GetDefaultMetricsEmitter returns the default metrics.MetricEmitter
    30  	// that should be handled by this mux; while SetDefaultMetricsEmitter
    31  	// provides a way to set the default metrics.MetricEmitter
    32  	GetDefaultMetricsEmitter() metrics.MetricEmitter
    33  	SetDefaultMetricsEmitter(metricEmitter metrics.MetricEmitter)
    34  
    35  	// GetMetricsEmitter returns the specific metrics.MetricEmitter.
    36  	// the parameters are used for certain pool implementation to parse request info.
    37  	// we will always try to get emitter from local cache, and creating one if not exist.
    38  	GetMetricsEmitter(parameters interface{}) (metrics.MetricEmitter, error)
    39  
    40  	// Run starts the syncing logic of emitter pool implementations
    41  	Run(ctx context.Context)
    42  }
    43  
    44  type DummyMetricsEmitterPool struct{}
    45  
    46  var _ MetricsEmitterPool = DummyMetricsEmitterPool{}
    47  
    48  func (d DummyMetricsEmitterPool) GetDefaultMetricsEmitter() metrics.MetricEmitter {
    49  	return metrics.DummyMetrics{}
    50  }
    51  
    52  func (d DummyMetricsEmitterPool) SetDefaultMetricsEmitter(_ metrics.MetricEmitter) {}
    53  
    54  func (d DummyMetricsEmitterPool) GetMetricsEmitter(_ interface{}) (metrics.MetricEmitter, error) {
    55  	return metrics.DummyMetrics{}, nil
    56  }
    57  func (d DummyMetricsEmitterPool) Run(_ context.Context) {}