MCPcopy Create free account
hub / github.com/cortexproject/cortex / newAlertmanagerClientsPool

Function newAlertmanagerClientsPool

pkg/alertmanager/alertmanager_client.go:61–98  ·  view source on GitHub ↗
(discovery client.PoolServiceDiscovery, amClientCfg ClientConfig, logger log.Logger, reg prometheus.Registerer)

Source from the content-addressed store, hash-verified

59}
60
61func newAlertmanagerClientsPool(discovery client.PoolServiceDiscovery, amClientCfg ClientConfig, logger log.Logger, reg prometheus.Registerer) ClientsPool {
62 // We prefer sane defaults instead of exposing further config options.
63 grpcCfg := grpcclient.Config{
64 MaxRecvMsgSize: amClientCfg.MaxRecvMsgSize,
65 MaxSendMsgSize: amClientCfg.MaxSendMsgSize,
66 GRPCCompression: amClientCfg.GRPCCompression,
67 RateLimit: 0,
68 RateLimitBurst: 0,
69 BackoffOnRatelimits: false,
70 TLSEnabled: amClientCfg.TLSEnabled,
71 TLS: amClientCfg.TLS,
72 ConnectTimeout: amClientCfg.ConnectTimeout,
73 }
74
75 requestDuration := promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
76 Name: "cortex_alertmanager_distributor_client_request_duration_seconds",
77 Help: "Time spent executing requests from an alertmanager to another alertmanager.",
78 Buckets: prometheus.ExponentialBuckets(0.008, 4, 7),
79 }, []string{"operation", "status_code"})
80
81 factory := func(addr string) (client.PoolClient, error) {
82 return dialAlertmanagerClient(grpcCfg, addr, requestDuration)
83 }
84
85 poolCfg := client.PoolConfig{
86 CheckInterval: time.Minute,
87 HealthCheckEnabled: true,
88 HealthCheckTimeout: 10 * time.Second,
89 }
90
91 clientsCount := promauto.With(reg).NewGauge(prometheus.GaugeOpts{
92 Namespace: "cortex",
93 Name: "alertmanager_distributor_clients",
94 Help: "The current number of alertmanager distributor clients in the pool.",
95 })
96
97 return &alertmanagerClientsPool{pool: client.NewPool("alertmanager", poolCfg, discovery, factory, clientsCount, logger)}
98}
99
100func (f *alertmanagerClientsPool) GetClientFor(addr string) (Client, error) {
101 c, err := f.pool.GetClientFor(addr)

Callers 2

NewDistributorFunction · 0.85

Calls 2

NewPoolFunction · 0.92
dialAlertmanagerClientFunction · 0.85

Tested by

no test coverage detected