forked from grafana/pyroscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributor_ring.go
36 lines (29 loc) · 1.13 KB
/
distributor_ring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package distributor
import (
"fmt"
"github.com/go-kit/log"
"github.com/grafana/dskit/ring"
"github.com/grafana/pyroscope/pkg/util"
)
const (
// ringNumTokens is how many tokens each distributor should have in the ring.
// Distributors use a ring because they need to know how many distributors there
// are in total for rate limiting.
ringNumTokens = 1
)
func toBasicLifecyclerConfig(cfg util.CommonRingConfig, logger log.Logger) (ring.BasicLifecyclerConfig, error) {
instanceAddr, err := ring.GetInstanceAddr(cfg.InstanceAddr, cfg.InstanceInterfaceNames, logger, cfg.EnableIPv6)
if err != nil {
return ring.BasicLifecyclerConfig{}, err
}
instancePort := ring.GetInstancePort(cfg.InstancePort, cfg.ListenPort)
return ring.BasicLifecyclerConfig{
ID: cfg.InstanceID,
Addr: fmt.Sprintf("%s:%d", instanceAddr, instancePort),
HeartbeatPeriod: cfg.HeartbeatPeriod,
HeartbeatTimeout: cfg.HeartbeatTimeout,
TokensObservePeriod: 0,
NumTokens: ringNumTokens,
KeepInstanceInTheRingOnShutdown: false,
}, nil
}