From d0839e0d66647e29ecb7221c39f1706e66dd24f4 Mon Sep 17 00:00:00 2001 From: Seena Fallah Date: Tue, 20 Aug 2024 22:20:19 +0200 Subject: [PATCH] fix(memberlist): Respect interface names config for advertise address If interface names are specified in common config, use this to fulfill the instance_addr with it. Signed-off-by: Seena Fallah --- pkg/loki/modules.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pkg/loki/modules.go b/pkg/loki/modules.go index 60e2683b599ff..96fd8a9c1acf6 100644 --- a/pkg/loki/modules.go +++ b/pkg/loki/modules.go @@ -22,6 +22,7 @@ import ( "github.com/grafana/dskit/kv/codec" "github.com/grafana/dskit/kv/memberlist" "github.com/grafana/dskit/middleware" + "github.com/grafana/dskit/netutil" "github.com/grafana/dskit/ring" "github.com/grafana/dskit/runtimeconfig" "github.com/grafana/dskit/server" @@ -1449,6 +1450,15 @@ func (t *Loki) initMemberlistKV() (services.Service, error) { ) dnsProvider := dns.NewProvider(util_log.Logger, dnsProviderReg, dns.GolangResolverType) + var err error + t.Cfg.MemberlistKV.AdvertiseAddr, err = GetInstanceAddr( + t.Cfg.MemberlistKV.AdvertiseAddr, + t.Cfg.Common.InstanceInterfaceNames, + util_log.Logger, + ) + if err != nil { + return nil, err + } t.MemberlistKV = memberlist.NewKVInitService(&t.Cfg.MemberlistKV, util_log.Logger, dnsProvider, reg) t.Cfg.CompactorConfig.CompactorRing.KVStore.MemberlistKV = t.MemberlistKV.GetMemberlistKV @@ -2042,3 +2052,11 @@ func schemaHasBoltDBShipperConfig(scfg config.SchemaConfig) bool { return false } + +func GetInstanceAddr(addr string, netInterfaces []string, logger log.Logger) (string, error) { + if addr != "" { + return addr, nil + } + + return netutil.GetFirstAddressOf(netInterfaces, logger, false) +}