Skip to content

Commit 06ef63d

Browse files
author
Tyler Reid
committed
Migrate to dskit/ring
Signed-off-by: Tyler Reid <[email protected]>
1 parent 85c3781 commit 06ef63d

File tree

87 files changed

+702
-6133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+702
-6133
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ require (
2929
github.com/golang/protobuf v1.5.2
3030
github.com/golang/snappy v0.0.4
3131
github.com/gorilla/mux v1.8.0
32-
github.com/grafana/dskit v0.0.0-20211011144203-3a88ec0b675f
32+
github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1
3333
github.com/json-iterator/go v1.1.11
3434
github.com/lib/pq v1.3.0
3535
github.com/minio/minio-go/v7 v7.0.10

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,8 @@ github.com/grafana/dskit v0.0.0-20210818123532-6645f87e9e12/go.mod h1:QaNAQaCSFO
10141014
github.com/grafana/dskit v0.0.0-20210819132858-471020752967/go.mod h1:uF46UNN1/feB1egpq8UGbBBKvJjGgZauW7pcVbeFLLM=
10151015
github.com/grafana/dskit v0.0.0-20211011144203-3a88ec0b675f h1:FvvSVEbnGeM2bUivGmsiXTi8URJyBU7TcFEEoRe5wWI=
10161016
github.com/grafana/dskit v0.0.0-20211011144203-3a88ec0b675f/go.mod h1:uPG2nyK4CtgNDmWv7qyzYcdI+S90kHHRWvHnBtEMBXM=
1017+
github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1 h1:Qf+/W3Tup0nO21tgJmO14WJK0yyrm4L2UJipZP+Zoow=
1018+
github.com/grafana/dskit v0.0.0-20211021180445-3bd016e9d7f1/go.mod h1:uPG2nyK4CtgNDmWv7qyzYcdI+S90kHHRWvHnBtEMBXM=
10171019
github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85 h1:xLuzPoOzdfNb/RF/IENCw+oLVdZB4G21VPhkHBgwSHY=
10181020
github.com/grafana/gocql v0.0.0-20200605141915-ba5dc39ece85/go.mod h1:crI9WX6p0IhrqB+DqIUHulRW853PaNFf7o4UprV//3I=
10191021
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=

pkg/alertmanager/alertmanager_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"github.com/go-kit/log"
88
"github.com/grafana/dskit/crypto/tls"
99
"github.com/grafana/dskit/grpcclient"
10+
"github.com/grafana/dskit/ring/client"
1011
"github.com/pkg/errors"
1112
"github.com/prometheus/client_golang/prometheus"
1213
"github.com/prometheus/client_golang/prometheus/promauto"
1314
"google.golang.org/grpc"
1415
"google.golang.org/grpc/health/grpc_health_v1"
1516

1617
"github.com/cortexproject/cortex/pkg/alertmanager/alertmanagerpb"
17-
"github.com/cortexproject/cortex/pkg/ring/client"
1818
)
1919

2020
// ClientsPool is the interface used to get the client from the pool for a specified address.

pkg/alertmanager/alertmanager_ring.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"os"
77
"time"
88

9+
"github.com/go-kit/log"
910
"github.com/go-kit/log/level"
1011
"github.com/grafana/dskit/flagext"
1112
"github.com/grafana/dskit/kv"
13+
"github.com/grafana/dskit/ring"
1214

13-
"github.com/cortexproject/cortex/pkg/ring"
1415
util_log "github.com/cortexproject/cortex/pkg/util/log"
1516
)
1617

@@ -94,8 +95,8 @@ func (cfg *RingConfig) RegisterFlags(f *flag.FlagSet) {
9495

9596
// ToLifecyclerConfig returns a LifecyclerConfig based on the alertmanager
9697
// ring config.
97-
func (cfg *RingConfig) ToLifecyclerConfig() (ring.BasicLifecyclerConfig, error) {
98-
instanceAddr, err := ring.GetInstanceAddr(cfg.InstanceAddr, cfg.InstanceInterfaceNames)
98+
func (cfg *RingConfig) ToLifecyclerConfig(logger log.Logger) (ring.BasicLifecyclerConfig, error) {
99+
instanceAddr, err := ring.GetInstanceAddr(cfg.InstanceAddr, cfg.InstanceInterfaceNames, logger)
99100
if err != nil {
100101
return ring.BasicLifecyclerConfig{}, err
101102
}

pkg/alertmanager/alertmanager_ring_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/grafana/dskit/ring"
78
"github.com/stretchr/testify/assert"
8-
9-
"github.com/cortexproject/cortex/pkg/ring"
109
)
1110

1211
func TestIsHealthyForAlertmanagerOperations(t *testing.T) {

pkg/alertmanager/distributor.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212

1313
"github.com/go-kit/log"
1414
"github.com/go-kit/log/level"
15+
"github.com/grafana/dskit/ring"
16+
"github.com/grafana/dskit/ring/client"
1517
"github.com/grafana/dskit/services"
1618
"github.com/opentracing/opentracing-go"
1719
"github.com/pkg/errors"
@@ -20,8 +22,6 @@ import (
2022
"github.com/weaveworks/common/user"
2123

2224
"github.com/cortexproject/cortex/pkg/alertmanager/merger"
23-
"github.com/cortexproject/cortex/pkg/ring"
24-
"github.com/cortexproject/cortex/pkg/ring/client"
2525
"github.com/cortexproject/cortex/pkg/tenant"
2626
"github.com/cortexproject/cortex/pkg/util"
2727
util_log "github.com/cortexproject/cortex/pkg/util/log"

pkg/alertmanager/distributor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/grafana/dskit/flagext"
1818
"github.com/grafana/dskit/kv"
1919
"github.com/grafana/dskit/kv/consul"
20+
"github.com/grafana/dskit/ring"
2021
"github.com/grafana/dskit/services"
2122
"github.com/prometheus/client_golang/prometheus"
2223
"github.com/stretchr/testify/assert"
@@ -27,7 +28,6 @@ import (
2728
"google.golang.org/grpc/health/grpc_health_v1"
2829

2930
"github.com/cortexproject/cortex/pkg/alertmanager/alertmanagerpb"
30-
"github.com/cortexproject/cortex/pkg/ring"
3131
util_log "github.com/cortexproject/cortex/pkg/util/log"
3232
"github.com/cortexproject/cortex/pkg/util/test"
3333
)
@@ -355,7 +355,7 @@ func prepare(t *testing.T, numAM, numHappyAM, replicationFactor int, responseBod
355355
},
356356
HeartbeatTimeout: 60 * time.Minute,
357357
ReplicationFactor: replicationFactor,
358-
}, RingNameForServer, RingKey, nil)
358+
}, RingNameForServer, RingKey, nil, nil)
359359
require.NoError(t, err)
360360
require.NoError(t, services.StartAndAwaitRunning(context.Background(), amRing))
361361
test.Poll(t, time.Second, numAM, func() interface{} {

pkg/alertmanager/lifecycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package alertmanager
22

33
import (
4-
"github.com/cortexproject/cortex/pkg/ring"
4+
"github.com/grafana/dskit/ring"
55
)
66

77
func (r *MultitenantAlertmanager) OnRingInstanceRegister(_ *ring.BasicLifecycler, ringDesc ring.Desc, instanceExists bool, instanceID string, instanceDesc ring.InstanceDesc) (ring.InstanceState, ring.Tokens) {

pkg/alertmanager/multitenant.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"github.com/grafana/dskit/concurrency"
1919
"github.com/grafana/dskit/flagext"
2020
"github.com/grafana/dskit/kv"
21+
"github.com/grafana/dskit/ring"
22+
"github.com/grafana/dskit/ring/client"
2123
"github.com/grafana/dskit/services"
2224
"github.com/pkg/errors"
2325
"github.com/prometheus/alertmanager/cluster"
@@ -34,8 +36,6 @@ import (
3436
"github.com/cortexproject/cortex/pkg/alertmanager/alertmanagerpb"
3537
"github.com/cortexproject/cortex/pkg/alertmanager/alertspb"
3638
"github.com/cortexproject/cortex/pkg/alertmanager/alertstore"
37-
"github.com/cortexproject/cortex/pkg/ring"
38-
"github.com/cortexproject/cortex/pkg/ring/client"
3939
"github.com/cortexproject/cortex/pkg/tenant"
4040
"github.com/cortexproject/cortex/pkg/util"
4141
util_log "github.com/cortexproject/cortex/pkg/util/log"
@@ -398,7 +398,7 @@ func createMultitenantAlertmanager(cfg *MultitenantAlertmanagerConfig, fallbackC
398398
}
399399

400400
if cfg.ShardingEnabled {
401-
lifecyclerCfg, err := am.cfg.ShardingRing.ToLifecyclerConfig()
401+
lifecyclerCfg, err := am.cfg.ShardingRing.ToLifecyclerConfig(am.logger)
402402
if err != nil {
403403
return nil, errors.Wrap(err, "failed to initialize Alertmanager's lifecycler config")
404404
}
@@ -414,15 +414,11 @@ func createMultitenantAlertmanager(cfg *MultitenantAlertmanagerConfig, fallbackC
414414
return nil, errors.Wrap(err, "failed to initialize Alertmanager's lifecycler")
415415
}
416416

417-
am.ring, err = ring.NewWithStoreClientAndStrategy(am.cfg.ShardingRing.ToRingConfig(), RingNameForServer, RingKey, ringStore, ring.NewIgnoreUnhealthyInstancesReplicationStrategy())
417+
am.ring, err = ring.NewWithStoreClientAndStrategy(am.cfg.ShardingRing.ToRingConfig(), RingNameForServer, RingKey, ringStore, ring.NewIgnoreUnhealthyInstancesReplicationStrategy(), prometheus.WrapRegistererWithPrefix("cortex_", am.registry), am.logger)
418418
if err != nil {
419419
return nil, errors.Wrap(err, "failed to initialize Alertmanager's ring")
420420
}
421421

422-
if am.registry != nil {
423-
am.registry.MustRegister(am.ring)
424-
}
425-
426422
am.grpcServer = server.NewServer(&handlerForGRPCServer{am: am})
427423

428424
am.alertmanagerClientsPool = newAlertmanagerClientsPool(client.NewRingServiceDiscovery(am.ring), cfg.AlertmanagerClient, logger, am.registry)

pkg/alertmanager/multitenant_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/grafana/dskit/concurrency"
2424
"github.com/grafana/dskit/flagext"
2525
"github.com/grafana/dskit/kv/consul"
26+
"github.com/grafana/dskit/ring"
2627
"github.com/grafana/dskit/services"
2728
"github.com/prometheus/alertmanager/cluster/clusterpb"
2829
"github.com/prometheus/alertmanager/notify"
@@ -44,7 +45,6 @@ import (
4445
"github.com/cortexproject/cortex/pkg/alertmanager/alertspb"
4546
"github.com/cortexproject/cortex/pkg/alertmanager/alertstore"
4647
"github.com/cortexproject/cortex/pkg/alertmanager/alertstore/bucketclient"
47-
"github.com/cortexproject/cortex/pkg/ring"
4848
"github.com/cortexproject/cortex/pkg/storage/bucket"
4949
"github.com/cortexproject/cortex/pkg/util"
5050
"github.com/cortexproject/cortex/pkg/util/test"
@@ -1445,7 +1445,7 @@ func TestAlertmanager_ReplicasPosition(t *testing.T) {
14451445

14461446
// First, create the alertmanager instances, we'll use a replication factor of 3 and create 3 instances so that we can get the tenant on each replica.
14471447
for i := 1; i <= 3; i++ {
1448-
//instanceIDs = append(instanceIDs, fmt.Sprintf("alertmanager-%d", i))
1448+
// instanceIDs = append(instanceIDs, fmt.Sprintf("alertmanager-%d", i))
14491449
instanceID := fmt.Sprintf("alertmanager-%d", i)
14501450

14511451
amConfig := mockAlertmanagerConfig(t)

0 commit comments

Comments
 (0)