github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/pkg/distributor/clientpool/ingester_client_pool.go (about)

     1  package clientpool
     2  
     3  import (
     4  	"flag"
     5  	"time"
     6  
     7  	"github.com/go-kit/log"
     8  	"github.com/grafana/dskit/ring"
     9  	ring_client "github.com/grafana/dskit/ring/client"
    10  	"github.com/prometheus/client_golang/prometheus"
    11  	"github.com/prometheus/client_golang/prometheus/promauto"
    12  )
    13  
    14  var clients = promauto.NewGauge(prometheus.GaugeOpts{
    15  	Namespace: "cortex",
    16  	Name:      "distributor_ingester_clients",
    17  	Help:      "The current number of ingester clients.",
    18  })
    19  
    20  // PoolConfig is config for creating a Pool.
    21  type PoolConfig struct {
    22  	ClientCleanupPeriod  time.Duration `yaml:"client_cleanup_period"`
    23  	HealthCheckIngesters bool          `yaml:"health_check_ingesters"`
    24  	RemoteTimeout        time.Duration `yaml:"remote_timeout"`
    25  }
    26  
    27  // RegisterFlags adds the flags required to config this to the given FlagSet.
    28  func (cfg *PoolConfig) RegisterFlags(f *flag.FlagSet) {
    29  	f.DurationVar(&cfg.ClientCleanupPeriod, "distributor.client-cleanup-period", 15*time.Second, "How frequently to clean up clients for ingesters that have gone away.")
    30  	f.BoolVar(&cfg.HealthCheckIngesters, "distributor.health-check-ingesters", true, "Run a health check on each ingester client during periodic cleanup.")
    31  }
    32  
    33  func NewPool(cfg PoolConfig, ring ring.ReadRing, factory ring_client.PoolFactory, logger log.Logger) *ring_client.Pool {
    34  	poolCfg := ring_client.PoolConfig{
    35  		CheckInterval:      cfg.ClientCleanupPeriod,
    36  		HealthCheckEnabled: cfg.HealthCheckIngesters,
    37  		HealthCheckTimeout: cfg.RemoteTimeout,
    38  	}
    39  
    40  	return ring_client.NewPool("ingester", poolCfg, ring_client.NewRingServiceDiscovery(ring), factory, clients, logger)
    41  }