Skip to content

Commit

Permalink
memberlist: respect interface names config for advertise addr
Browse files Browse the repository at this point in the history
If interface names are specified in common config, use this to
fulfill the instance_addr with it.

Signed-off-by: Seena Fallah <[email protected]>
  • Loading branch information
clwluvw committed Aug 20, 2024
1 parent 07f9169 commit 5696cdc
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2042,3 +2052,16 @@ func schemaHasBoltDBShipperConfig(scfg config.SchemaConfig) bool {

return false
}

func GetInstanceAddr(addr string, netInterfaces []string, logger log.Logger) (string, error) {
if len(netInterfaces) == 0 {
return addr, nil
}

addr, err := netutil.GetFirstAddressOf(netInterfaces, logger, false)
if err != nil {
return "", err
}

return addr, nil
}

0 comments on commit 5696cdc

Please sign in to comment.