|
|
|
@ -2,6 +2,8 @@ package client |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"errors" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"sync" |
|
|
|
"sync" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-kit/log" |
|
|
|
"github.com/go-kit/log" |
|
|
|
@ -20,16 +22,25 @@ type MultiClient struct { |
|
|
|
|
|
|
|
|
|
|
|
// NewMulti creates a new client
|
|
|
|
// NewMulti creates a new client
|
|
|
|
func NewMulti(metrics *Metrics, streamLagLabels []string, logger log.Logger, cfgs ...Config) (Client, error) { |
|
|
|
func NewMulti(metrics *Metrics, streamLagLabels []string, logger log.Logger, cfgs ...Config) (Client, error) { |
|
|
|
|
|
|
|
var fake struct{} |
|
|
|
|
|
|
|
|
|
|
|
if len(cfgs) == 0 { |
|
|
|
if len(cfgs) == 0 { |
|
|
|
return nil, errors.New("at least one client config should be provided") |
|
|
|
return nil, errors.New("at least one client config should be provided") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
clientsCheck := make(map[string]struct{}) |
|
|
|
clients := make([]Client, 0, len(cfgs)) |
|
|
|
clients := make([]Client, 0, len(cfgs)) |
|
|
|
for _, cfg := range cfgs { |
|
|
|
for _, cfg := range cfgs { |
|
|
|
client, err := New(metrics, cfg, streamLagLabels, logger) |
|
|
|
client, err := New(metrics, cfg, streamLagLabels, logger) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Don't allow duplicate clients, we have client specific metrics that need at least one unique label value (name).
|
|
|
|
|
|
|
|
if _, ok := clientsCheck[client.Name()]; ok { |
|
|
|
|
|
|
|
return nil, fmt.Errorf("duplicate client configs are not allowed, found duplicate for URL: %s", cfg.URL) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clientsCheck[client.Name()] = fake |
|
|
|
clients = append(clients, client) |
|
|
|
clients = append(clients, client) |
|
|
|
} |
|
|
|
} |
|
|
|
multi := &MultiClient{ |
|
|
|
multi := &MultiClient{ |
|
|
|
@ -71,3 +82,15 @@ func (m *MultiClient) StopNow() { |
|
|
|
c.StopNow() |
|
|
|
c.StopNow() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *MultiClient) Name() string { |
|
|
|
|
|
|
|
var sb strings.Builder |
|
|
|
|
|
|
|
sb.WriteString("multi:") |
|
|
|
|
|
|
|
for i, c := range m.clients { |
|
|
|
|
|
|
|
sb.WriteString(c.Name()) |
|
|
|
|
|
|
|
if i != len(m.clients)-1 { |
|
|
|
|
|
|
|
sb.WriteString(",") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return sb.String() |
|
|
|
|
|
|
|
} |
|
|
|
|