From fd928bac4f3b416b93e5c605a48cb0ca483c6d47 Mon Sep 17 00:00:00 2001 From: Christian Haudum Date: Tue, 2 May 2023 17:25:18 +0200 Subject: [PATCH] Upstream changes Pulls changes from https://github.com/grafana/dskit/pull/304 Signed-off-by: Christian Haudum --- go.mod | 2 +- go.sum | 2 ++ .../github.com/grafana/dskit/flagext/bytes.go | 31 ++++++++++++------- vendor/github.com/grafana/dskit/ring/ring.go | 21 ++++++++++++- vendor/modules.txt | 2 +- 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 672adc505ba2..77275399a940 100644 --- a/go.mod +++ b/go.mod @@ -49,7 +49,7 @@ require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/websocket v1.5.0 github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2 - github.com/grafana/dskit v0.0.0-20230518162305-3c92c534827e + github.com/grafana/dskit v0.0.0-20230531063521-9bd0e035aecd github.com/grafana/go-gelf/v2 v2.0.1 github.com/grafana/gomemcache v0.0.0-20230316202710-a081dae0aba9 github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd diff --git a/go.sum b/go.sum index 7f4547610a89..6e60781c6fb2 100644 --- a/go.sum +++ b/go.sum @@ -1091,6 +1091,8 @@ github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2 h1:qhugDMdQ4 github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2/go.mod h1:w/aiO1POVIeXUQyl0VQSZjl5OAGDTL5aX+4v0RA1tcw= github.com/grafana/dskit v0.0.0-20230518162305-3c92c534827e h1:ODjv+9dmklDS33O2B4zPgIDKdnji18o9ofD9qWA+mAs= github.com/grafana/dskit v0.0.0-20230518162305-3c92c534827e/go.mod h1:M03k2fzuQ2n9TVE1xfVKTESibxsXdw0wYfWT3+9Owp4= +github.com/grafana/dskit v0.0.0-20230531063521-9bd0e035aecd h1:lPl/cLANWA5rvlXxs1v05lkDG/aTiGRikhZqEoONaSM= +github.com/grafana/dskit v0.0.0-20230531063521-9bd0e035aecd/go.mod h1:M03k2fzuQ2n9TVE1xfVKTESibxsXdw0wYfWT3+9Owp4= github.com/grafana/go-gelf/v2 v2.0.1 h1:BOChP0h/jLeD+7F9mL7tq10xVkDG15he3T1zHuQaWak= github.com/grafana/go-gelf/v2 v2.0.1/go.mod h1:lexHie0xzYGwCgiRGcvZ723bSNyNI8ZRD4s0CLobh90= github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/IENCw+oLVdZB4G21VPhkHBgwSHY= diff --git a/vendor/github.com/grafana/dskit/flagext/bytes.go b/vendor/github.com/grafana/dskit/flagext/bytes.go index dabb101b8e85..61a5c9d04ec0 100644 --- a/vendor/github.com/grafana/dskit/flagext/bytes.go +++ b/vendor/github.com/grafana/dskit/flagext/bytes.go @@ -8,18 +8,18 @@ import ( "github.com/alecthomas/units" ) -// Bytes is a data type which supports yaml serialization/deserialization -// with units. +// Bytes is a data type which supports use as a flag and yaml +// serialization/deserialization with units. type Bytes uint64 -func (b *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error { - var value string - err := unmarshal(&value) - if err != nil { - return err - } +// String implements flag.Value +func (b *Bytes) String() string { + return units.Base2Bytes(*b).String() +} - bytes, err := units.ParseBase2Bytes(value) +// Set implements flag.Value +func (b *Bytes) Set(s string) error { + bytes, err := units.ParseBase2Bytes(s) if err != nil { return err } @@ -28,6 +28,15 @@ func (b *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error { return nil } -func (b *Bytes) MarshalYAML() (interface{}, error) { - return units.Base2Bytes(*b).String(), nil +func (b *Bytes) UnmarshalYAML(unmarshal func(interface{}) error) error { + var value string + if err := unmarshal(&value); err != nil { + return err + } + + return b.Set(value) +} + +func (b Bytes) MarshalYAML() (interface{}, error) { + return b.String(), nil } diff --git a/vendor/github.com/grafana/dskit/ring/ring.go b/vendor/github.com/grafana/dskit/ring/ring.go index 9cc4e757cb9a..afeb3488b07a 100644 --- a/vendor/github.com/grafana/dskit/ring/ring.go +++ b/vendor/github.com/grafana/dskit/ring/ring.go @@ -78,6 +78,13 @@ type ReadRing interface { CleanupShuffleShardCache(identifier string) } +// DynamicReplicationReadRing extends the ReadRing with an additional function to get a +// ReplicationSet based on a provided replication factor. +type DynamicReplicationReadRing interface { + ReadRing + GetWithRF(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, bufZones []string, rf int) (ReplicationSet, error) +} + var ( // Write operation that also extends replica set, if instance state is not ACTIVE. Write = NewOp([]InstanceState{ACTIVE}, func(s InstanceState) bool { @@ -347,6 +354,19 @@ func (r *Ring) updateRingState(ringDesc *Desc) { // Get returns n (or more) instances which form the replicas for the given key. func (r *Ring) Get(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, bufZones []string) (ReplicationSet, error) { + return r.get(key, op, bufDescs, bufHosts, bufZones, r.cfg.ReplicationFactor) +} + +// GetWithRF returns n (or more) instances which form the replicas for the +// given key and given replication factor. +// If you have zone-aware replication enabled the current GetWithRF() +// implementation doesn't work with a RF > number of zones. +func (r *Ring) GetWithRF(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, bufZones []string, rf int) (ReplicationSet, error) { + return r.get(key, op, bufDescs, bufHosts, bufZones, rf) +} + +// get returns n (or more) instances which form the replicas for the given key. +func (r *Ring) get(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, bufZones []string, n int) (ReplicationSet, error) { r.mtx.RLock() defer r.mtx.RUnlock() if r.ringDesc == nil || len(r.ringTokens) == 0 { @@ -354,7 +374,6 @@ func (r *Ring) Get(key uint32, op Operation, bufDescs []InstanceDesc, bufHosts, } var ( - n = r.cfg.ReplicationFactor instances = bufDescs[:0] start = searchToken(r.ringTokens, key) iterations = 0 diff --git a/vendor/modules.txt b/vendor/modules.txt index 4648ec56952a..cb4a28c1d931 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -793,7 +793,7 @@ github.com/gorilla/websocket # github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2 ## explicit; go 1.17 github.com/grafana/cloudflare-go -# github.com/grafana/dskit v0.0.0-20230518162305-3c92c534827e +# github.com/grafana/dskit v0.0.0-20230531063521-9bd0e035aecd ## explicit; go 1.18 github.com/grafana/dskit/backoff github.com/grafana/dskit/concurrency