MCPcopy
hub / github.com/grafana/dskit / SimpleMemberlistKV

Function SimpleMemberlistKV

ring/example/local/local.go:156–192  ·  view source on GitHub ↗

SimpleMemberlistKV returns a memberlist KV as a service. Starting and stopping the service is up to the caller. Caller can create an instance `kv.Client` from returned service by explicity calling `.GetMemberlistKV()` which can be used as dependency to create a ring or ring lifecycler.

(bindaddr string, bindport int, joinmembers []string)

Source from the content-addressed store, hash-verified

154// Caller can create an instance `kv.Client` from returned service by explicity calling `.GetMemberlistKV()`
155// which can be used as dependency to create a ring or ring lifecycler.
156func SimpleMemberlistKV(bindaddr string, bindport int, joinmembers []string) *memberlist.KVInitService {
157 var config memberlist.KVConfig
158 flagext.DefaultValues(&config)
159
160 // Codecs is used to tell memberlist library how to serialize/de-serialize the messages between peers.
161 // `ring.GetCodec()` uses default, which is protobuf.
162 config.Codecs = []codec.Codec{ring.GetCodec()}
163
164 // TCPTransport defines what addr and port this particular peer should listen on.
165 config.TCPTransport = memberlist.TCPTransportConfig{
166 BindPort: bindport,
167 BindAddrs: []string{bindaddr},
168 }
169
170 // joinmembers are the addresses of peers who are already in the memberlist group.
171 // Usually provided if this peer is trying to join an existing cluster.
172 // Generally you start the very first peer without `joinmembers`, but start all
173 // other peers with at least one `joinmembers`.
174 if len(joinmembers) > 0 {
175 config.JoinMembers = joinmembers
176 }
177
178 // resolver defines how each peers IP address should be resolved.
179 // We use default resolver comes with Go.
180 resolver := dns.NewProvider(dns.GolangResolverType, 0, log.With(logger, "component", "dns"), prometheus.NewPedanticRegistry())
181
182 config.NodeName = bindaddr
183 config.StreamTimeout = 5 * time.Second
184
185 return memberlist.NewKVInitService(
186 &config,
187 log.With(logger, "component", "memberlist"),
188 resolver,
189 prometheus.NewPedanticRegistry(),
190 )
191
192}
193
194// SimpleRing returns an instance of `ring.Ring` as a service. Starting and stopping the service is up to the caller.
195func SimpleRing(store kv.Client) (*ring.Ring, error) {

Callers 2

runClusterFunction · 0.85
runClientFunction · 0.85

Calls 5

DefaultValuesFunction · 0.92
GetCodecFunction · 0.92
NewProviderFunction · 0.92
NewKVInitServiceFunction · 0.92
WithMethod · 0.80

Tested by

no test coverage detected