mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* fix up ring store init Signed-off-by: Joe Elliott <[email protected]> * fix partition ring Signed-off-by: Joe Elliott <[email protected]> * cleanup Signed-off-by: Joe Elliott <[email protected]> * generate manifest Signed-off-by: Joe Elliott <[email protected]> * fix flakey test Signed-off-by: Joe Elliott <[email protected]> * lint Signed-off-by: Joe Elliott <[email protected]> --------- Signed-off-by: Joe Elliott <[email protected]>
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package ring
|
|
|
|
import (
|
|
"flag"
|
|
"net"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/go-kit/log/level"
|
|
"github.com/grafana/dskit/flagext"
|
|
"github.com/grafana/dskit/kv"
|
|
"github.com/grafana/dskit/ring"
|
|
|
|
"github.com/grafana/tempo/pkg/util/log"
|
|
)
|
|
|
|
type Config struct {
|
|
KVStore kv.Config `yaml:"kvstore"`
|
|
HeartbeatPeriod time.Duration `yaml:"heartbeat_period"`
|
|
HeartbeatTimeout time.Duration `yaml:"heartbeat_timeout"`
|
|
|
|
InstanceID string `yaml:"instance_id"`
|
|
InstanceInterfaceNames []string `yaml:"instance_interface_names"`
|
|
InstanceAddr string `yaml:"instance_addr"`
|
|
InstancePort int `yaml:"instance_port"`
|
|
EnableInet6 bool `yaml:"enable_inet6"`
|
|
InstanceZone string `yaml:"instance_zone"`
|
|
|
|
// Injected internally
|
|
ListenPort int `yaml:"-"`
|
|
}
|
|
|
|
func (cfg *Config) RegisterFlagsAndApplyDefaults(prefix string, f *flag.FlagSet) {
|
|
cfg.KVStore.RegisterFlagsWithPrefix(prefix, "collectors/", f)
|
|
cfg.KVStore.Store = "memberlist"
|
|
|
|
cfg.HeartbeatPeriod = 5 * time.Second
|
|
cfg.HeartbeatTimeout = 1 * time.Minute
|
|
|
|
hostname, err := os.Hostname()
|
|
if err != nil {
|
|
level.Error(log.Logger).Log("msg", "failed to get hostname", "err", err)
|
|
os.Exit(1)
|
|
}
|
|
cfg.InstanceID = hostname
|
|
cfg.InstanceInterfaceNames = []string{"eth0", "en0"}
|
|
|
|
f.StringVar(&cfg.InstanceZone, prefix+".instance-availability-zone", "", "Define Availability Zone in which this instance is running.")
|
|
}
|
|
|
|
func (cfg *Config) ToRingConfig() ring.Config {
|
|
rc := ring.Config{}
|
|
flagext.DefaultValues(&rc)
|
|
|
|
rc.KVStore = cfg.KVStore
|
|
rc.HeartbeatTimeout = cfg.HeartbeatTimeout
|
|
rc.ReplicationFactor = 1
|
|
rc.SubringCacheDisabled = true
|
|
|
|
return rc
|
|
}
|
|
|
|
func (cfg *Config) ToLifecyclerConfig(numTokens int) (ring.BasicLifecyclerConfig, error) {
|
|
instanceAddr, err := ring.GetInstanceAddr(cfg.InstanceAddr, cfg.InstanceInterfaceNames, log.Logger, cfg.EnableInet6)
|
|
if err != nil {
|
|
level.Error(log.Logger).Log("msg", "failed to get instance address", "err", err)
|
|
return ring.BasicLifecyclerConfig{}, err
|
|
}
|
|
|
|
instancePort := ring.GetInstancePort(cfg.InstancePort, cfg.ListenPort)
|
|
instanceAddrPort := net.JoinHostPort(instanceAddr, strconv.Itoa(instancePort))
|
|
|
|
return ring.BasicLifecyclerConfig{
|
|
ID: cfg.InstanceID,
|
|
Addr: instanceAddrPort,
|
|
Zone: cfg.InstanceZone,
|
|
HeartbeatPeriod: cfg.HeartbeatPeriod,
|
|
NumTokens: numTokens,
|
|
}, nil
|
|
}
|