From 4d37ca7e147a15996ceed93a42bb33ee4e2d9575 Mon Sep 17 00:00:00 2001 From: Bartek Plotka Date: Mon, 4 Jun 2018 15:55:56 +0100 Subject: [PATCH] store: Tiny logging improvements. Signed-off-by: Bartek Plotka --- cmd/thanos/query.go | 10 ++++++++++ cmd/thanos/store.go | 11 +++++++---- pkg/cluster/cluster.go | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 5c9e5603c8..b0022a0c58 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "math" "net" "net/http" @@ -143,6 +144,10 @@ func runQuery( ) error { var staticSpecs []query.StoreSpec for _, addr := range storeAddrs { + if addr == "" { + return errors.New("static store address cannot be empty") + } + staticSpecs = append(staticSpecs, query.NewGRPCStoreSpec(addr)) } var ( @@ -153,6 +158,11 @@ func runQuery( specs = append(staticSpecs) for id, ps := range peer.PeerStates(cluster.PeerTypesStoreAPIs()...) { + if ps.StoreAPIAddr == "" { + level.Error(logger).Log("msg", "Gossip found peer that propagates empty address. Ignoring.", "lset", fmt.Sprintf("%v", ps.Metadata.Labels)) + continue + } + specs = append(specs, &gossipSpec{id: id, addr: ps.StoreAPIAddr, peer: peer}) } return specs diff --git a/cmd/thanos/store.go b/cmd/thanos/store.go index 83ebadcc19..8cfed5567a 100644 --- a/cmd/thanos/store.go +++ b/cmd/thanos/store.go @@ -151,10 +151,13 @@ func runStore( ctx, cancel := context.WithCancel(context.Background()) g.Add(func() error { // New gossip cluster. - if err := peer.Join(cluster.PeerTypeStore, cluster.PeerMetadata{ - MinTime: math.MinInt64, - MaxTime: math.MaxInt64, - }); err != nil { + if err := peer.Join( + cluster.PeerTypeStore, + cluster.PeerMetadata{ + MinTime: math.MinInt64, + MaxTime: math.MaxInt64, + }, + ); err != nil { return errors.Wrap(err, "join cluster") } diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index d5490fdb94..803f6269ab 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -187,7 +187,7 @@ func (p *Peer) Join(peerType PeerType, initialMetadata PeerMetadata) error { } n, _ := ml.Join(p.knownPeers) - level.Debug(p.logger).Log("msg", "joined cluster", "peers", n, "peerType", peerType) + level.Debug(p.logger).Log("msg", "joined cluster", "peerType", peerType) if n > 0 { go warnIfAlone(p.logger, 10*time.Second, p.stopc, ml.NumMembers) @@ -204,6 +204,7 @@ func (p *Peer) Join(peerType PeerType, initialMetadata PeerMetadata) error { QueryAPIAddr: p.advertiseQueryAPIAddress, Metadata: initialMetadata, }) + return nil } @@ -302,7 +303,6 @@ func (p *Peer) PeerStates(types ...PeerType) map[string]PeerState { ps[o.Name] = os continue } - for _, t := range types { if os.Type == t { ps[o.Name] = os