Skip to content

Commit ece6907

Browse files
authored
Merge pull request #165 from weaveworks/backout-protoring
Revert "Merge pull request #159 from weaveworks/protoring"
2 parents 8011678 + 5eaee36 commit ece6907

File tree

10 files changed

+156
-306
lines changed

10 files changed

+156
-306
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmd/cortex/cortex
22
.uptodate
33
.pkg
4-
*.pb.go
4+
cortex.pb.go
55
ui/bindata.go

Makefile

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,15 @@ IMAGE_NAMES=$(foreach dir,$(DOCKER_IMAGE_DIRS),$(patsubst %,$(IMAGE_PREFIX)/%,$(
2424
images:
2525
$(info $(IMAGE_NAMES))
2626

27-
PROTO_DEFS := $(shell find . -type f -name "*.proto" ! -path "./tools/*" ! -path "./vendor/*")
28-
PROTO_GOS := $(patsubst %.proto,%.pb.go,$(PROTO_DEFS))
29-
3027
# List of exes please
3128
CORTEX_EXE := ./cmd/cortex/cortex
3229
EXES = $(CORTEX_EXE)
3330

3431
all: $(UPTODATE_FILES)
35-
test: $(PROTO_GOS)
3632

3733
# And what goes into each exe
38-
$(CORTEX_EXE): $(shell find . -name '*.go' ! -path "./tools/*" ! -path "./vendor/*") ui/bindata.go $(PROTO_GOS)
39-
%.pb.go: %.proto
34+
$(CORTEX_EXE): $(shell find . -name '*.go') ui/bindata.go cortex.pb.go
35+
cortex.pb.go: cortex.proto
4036
ui/bindata.go: $(shell find ui/static ui/templates)
4137

4238
# And now what goes into each image
@@ -59,7 +55,7 @@ NETGO_CHECK = @strings $@ | grep cgo_stub\\\.go >/dev/null || { \
5955

6056
ifeq ($(BUILD_IN_CONTAINER),true)
6157

62-
$(EXES) $(PROTO_GOS) ui/bindata.go lint test shell: cortex-build/$(UPTODATE)
58+
$(EXES) cortex.pb.go ui/bindata.go lint test shell: cortex-build/$(UPTODATE)
6359
@mkdir -p $(shell pwd)/.pkg
6460
$(SUDO) docker run $(RM) -ti \
6561
-v $(shell pwd)/.pkg:/go/pkg \
@@ -72,16 +68,16 @@ $(EXES): cortex-build/$(UPTODATE)
7268
go build $(GO_FLAGS) -o $@ ./$(@D)
7369
$(NETGO_CHECK)
7470

75-
%.pb.go: cortex-build/$(UPTODATE)
76-
protoc -I ./vendor:./$(@D) --go_out=plugins=grpc:./$(@D) ./$(patsubst %.pb.go,%.proto,$@)
71+
cortex.pb.go: cortex-build/$(UPTODATE)
72+
protoc -I ./vendor:. --go_out=plugins=grpc:. ./cortex.proto
7773

7874
ui/bindata.go: cortex-build/$(UPTODATE)
7975
go-bindata -pkg ui -o ui/bindata.go -ignore '(.*\.map|bootstrap\.js|bootstrap-theme\.css|bootstrap\.css)' ui/templates/... ui/static/...
8076

8177
lint: cortex-build/$(UPTODATE)
8278
./tools/lint -notestpackage -ignorespelling queriers -ignorespelling Queriers .
8379

84-
test: cortex-build/$(UPTODATE)
80+
test: cortex-build/$(UPTODATE) cortex.pb.go
8581
./tools/test -no-go-get
8682

8783
shell: cortex-build/$(UPTODATE)
@@ -91,7 +87,7 @@ endif
9187

9288
clean:
9389
$(SUDO) docker rmi $(IMAGE_NAMES) >/dev/null 2>&1 || true
94-
rm -rf $(UPTODATE_FILES) $(EXES) $(PROTO_GOS) ui/bindata.go
90+
rm -rf $(UPTODATE_FILES) $(EXES) cortex.pb.go ui/bindata.go
9591
go clean ./...
9692

9793

cmd/cortex/main.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,7 @@ func main() {
138138
prometheus.MustRegister(resourceWatcher)
139139
}
140140

141-
ringCodec := ring.NewDynamicCodec(
142-
ring.JSONCodec{Factory: ring.DescFactory},
143-
ring.ProtoCodec{Factory: ring.ProtoDescFactory},
144-
)
145-
consul, err := ring.NewConsulClient(cfg.consulHost, ringCodec)
141+
consul, err := ring.NewConsulClient(cfg.consulHost)
146142
if err != nil {
147143
log.Fatalf("Error initializing Consul client: %v", err)
148144
}
@@ -160,7 +156,7 @@ func main() {
160156

161157
case modeIngester:
162158
cfg.ingesterConfig.Ring = r
163-
registration, err := ring.RegisterIngester(consul, cfg.ingesterConfig.GRPCListenPort, cfg.numTokens, ringCodec)
159+
registration, err := ring.RegisterIngester(consul, cfg.listenPort, cfg.ingesterConfig.GRPCListenPort, cfg.numTokens)
164160
if err != nil {
165161
// This only happens for errors in configuration & set-up, not for
166162
// network errors.
@@ -187,7 +183,7 @@ func main() {
187183

188184
// Deferring a func to make ordering obvious
189185
defer func() {
190-
registration.ChangeState(ring.IngesterState_LEAVING)
186+
registration.ChangeState(ring.Leaving)
191187
ing.Stop()
192188
registration.Unregister()
193189
}()

distributor/distributor.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ type Distributor struct {
5454
type ReadRing interface {
5555
prometheus.Collector
5656

57-
Get(key uint32, n int, op ring.Operation) ([]*ring.IngesterDesc, error)
58-
BatchGet(keys []uint32, n int, op ring.Operation) ([][]*ring.IngesterDesc, error)
59-
GetAll() []*ring.IngesterDesc
57+
Get(key uint32, n int, op ring.Operation) ([]ring.IngesterDesc, error)
58+
BatchGet(keys []uint32, n int, op ring.Operation) ([][]ring.IngesterDesc, error)
59+
GetAll() []ring.IngesterDesc
6060
}
6161

6262
// Config contains the configuration require to
@@ -121,7 +121,7 @@ func New(cfg Config) (*Distributor, error) {
121121
}, nil
122122
}
123123

124-
func (d *Distributor) getClientFor(ingester *ring.IngesterDesc) (cortex.IngesterClient, error) {
124+
func (d *Distributor) getClientFor(ingester ring.IngesterDesc) (cortex.IngesterClient, error) {
125125
d.clientsMtx.RLock()
126126
client, ok := d.clients[ingester.Hostname]
127127
d.clientsMtx.RUnlock()
@@ -137,7 +137,7 @@ func (d *Distributor) getClientFor(ingester *ring.IngesterDesc) (cortex.Ingester
137137
}
138138

139139
conn, err := grpc.Dial(
140-
ingester.Hostname,
140+
ingester.GRPCHostname,
141141
grpc.WithInsecure(),
142142
grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(
143143
otgrpc.OpenTracingClientInterceptor(opentracing.GlobalTracer()),
@@ -192,7 +192,7 @@ func (d *Distributor) Push(ctx context.Context, req *remote.WriteRequest) (*cort
192192
}
193193

194194
sampleTrackers := make([]sampleTracker, len(samples), len(samples))
195-
samplesByIngester := map[*ring.IngesterDesc][]*sampleTracker{}
195+
samplesByIngester := map[ring.IngesterDesc][]*sampleTracker{}
196196
for i := range samples {
197197
sampleTrackers[i] = sampleTracker{
198198
sample: samples[i],
@@ -204,9 +204,9 @@ func (d *Distributor) Push(ctx context.Context, req *remote.WriteRequest) (*cort
204204
// Skip those that have not heartbeated in a while. NB these are still
205205
// included in the calculation of minSuccess, so if too many failed ingesters
206206
// will cause the whole write to fail.
207-
liveIngesters := make([]*ring.IngesterDesc, 0, len(ingesters[i]))
207+
liveIngesters := make([]ring.IngesterDesc, 0, len(ingesters[i]))
208208
for _, ingester := range ingesters[i] {
209-
if time.Now().Sub(time.Unix(ingester.Timestamp, 0)) <= d.cfg.HeartbeatTimeout {
209+
if time.Now().Sub(ingester.Timestamp) <= d.cfg.HeartbeatTimeout {
210210
liveIngesters = append(liveIngesters, ingester)
211211
}
212212
}
@@ -226,7 +226,7 @@ func (d *Distributor) Push(ctx context.Context, req *remote.WriteRequest) (*cort
226226

227227
errs := make(chan error)
228228
for hostname, samples := range samplesByIngester {
229-
go func(ingester *ring.IngesterDesc, samples []*sampleTracker) {
229+
go func(ingester ring.IngesterDesc, samples []*sampleTracker) {
230230
errs <- d.sendSamples(ctx, ingester, samples)
231231
}(hostname, samples)
232232
}
@@ -246,7 +246,7 @@ func (d *Distributor) Push(ctx context.Context, req *remote.WriteRequest) (*cort
246246
return &cortex.WriteResponse{}, nil
247247
}
248248

249-
func (d *Distributor) sendSamples(ctx context.Context, ingester *ring.IngesterDesc, sampleTrackers []*sampleTracker) error {
249+
func (d *Distributor) sendSamples(ctx context.Context, ingester ring.IngesterDesc, sampleTrackers []*sampleTracker) error {
250250
client, err := d.getClientFor(ingester)
251251
if err != nil {
252252
return err

0 commit comments

Comments
 (0)