diff --git a/pkg/loki/modules.go b/pkg/loki/modules.go index 60e2683b599ff..d675d078c6dba 100644 --- a/pkg/loki/modules.go +++ b/pkg/loki/modules.go @@ -33,6 +33,7 @@ import ( "github.com/prometheus/client_golang/prometheus/collectors/version" "github.com/prometheus/common/model" + "github.com/grafana/dskit/netutil" "github.com/grafana/loki/v3/pkg/analytics" "github.com/grafana/loki/v3/pkg/bloombuild/builder" "github.com/grafana/loki/v3/pkg/bloombuild/planner" @@ -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) +}