Skip to content

Commit

Permalink
info: Return store info only when the service is ready (#5255)
Browse files Browse the repository at this point in the history
* return store info only when the service is ready

Signed-off-by: Ben Ye <ben.ye@bytedance.com>

* fix test

Signed-off-by: Ben Ye <ben.ye@bytedance.com>
  • Loading branch information
Ben Ye committed Mar 25, 2022
1 parent a636c19 commit f0e673a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -26,6 +26,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#5224](https://github.com/thanos-io/thanos/pull/5224) Receive: Remove sort on label hashing
- [#5231](https://github.com/thanos-io/thanos/pull/5231) Tools: Bucket verify tool ignores blocks with deletion markers.
- [#5244](https://github.com/thanos-io/thanos/pull/5244) Query: Promote negative offset and `@` modifier to stable features as per Prometheus [#10121](https://github.com/prometheus/prometheus/pull/10121).
- [#5255](https://github.com/thanos-io/thanos/pull/5255) InfoAPI: Set store API unavailable when stores are not ready.

### Removed

Expand Down
11 changes: 7 additions & 4 deletions cmd/thanos/query.go
Expand Up @@ -661,11 +661,14 @@ func runQuery(
component.Query.String(),
info.WithLabelSetFunc(func() []labelpb.ZLabelSet { return proxy.LabelSet() }),
info.WithStoreInfoFunc(func() *infopb.StoreInfo {
minTime, maxTime := proxy.TimeRange()
return &infopb.StoreInfo{
MinTime: minTime,
MaxTime: maxTime,
if httpProbe.IsReady() {
mint, maxt := proxy.TimeRange()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
}
}
return nil
}),
info.WithExemplarsInfoFunc(),
info.WithRulesInfoFunc(),
Expand Down
16 changes: 10 additions & 6 deletions cmd/thanos/receive.go
Expand Up @@ -259,7 +259,8 @@ func runReceive(

level.Debug(logger).Log("msg", "setting up grpc server")
{
if err := setupAndRunGRPCServer(g, logger, reg, tracer, conf, reloadGRPCServer, comp, dbs, webHandler, grpcLogOpts, tagOpts, grpcProbe); err != nil {
if err := setupAndRunGRPCServer(g, logger, reg, tracer, conf, reloadGRPCServer, comp, dbs, webHandler, grpcLogOpts,
tagOpts, grpcProbe, httpProbe.IsReady); err != nil {
return err
}
}
Expand Down Expand Up @@ -294,7 +295,7 @@ func setupAndRunGRPCServer(g *run.Group,
grpcLogOpts []grpc_logging.Option,
tagOpts []tags.Option,
grpcProbe *prober.GRPCProbe,

isReady func() bool,
) error {

var s *grpcserver.Server
Expand Down Expand Up @@ -329,11 +330,14 @@ func setupAndRunGRPCServer(g *run.Group,
component.Receive.String(),
info.WithLabelSetFunc(func() []labelpb.ZLabelSet { return mts.LabelSet() }),
info.WithStoreInfoFunc(func() *infopb.StoreInfo {
minTime, maxTime := mts.TimeRange()
return &infopb.StoreInfo{
MinTime: minTime,
MaxTime: maxTime,
if isReady() {
minTime, maxTime := mts.TimeRange()
return &infopb.StoreInfo{
MinTime: minTime,
MaxTime: maxTime,
}
}
return nil
}),
info.WithExemplarsInfoFunc(),
)
Expand Down
11 changes: 7 additions & 4 deletions cmd/thanos/rule.go
Expand Up @@ -604,11 +604,14 @@ func runRule(
return tsdbStore.LabelSet()
}),
info.WithStoreInfoFunc(func() *infopb.StoreInfo {
mint, maxt := tsdbStore.TimeRange()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
if httpProbe.IsReady() {
mint, maxt := tsdbStore.TimeRange()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
}
}
return nil
}),
)
options = append(options, grpcserver.WithServer(store.RegisterStoreServer(tsdbStore)))
Expand Down
11 changes: 7 additions & 4 deletions cmd/thanos/sidecar.go
Expand Up @@ -265,11 +265,14 @@ func runSidecar(
return promStore.LabelSet()
}),
info.WithStoreInfoFunc(func() *infopb.StoreInfo {
mint, maxt := promStore.Timestamps()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
if httpProbe.IsReady() {
mint, maxt := promStore.Timestamps()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
}
}
return nil
}),
info.WithExemplarsInfoFunc(),
info.WithRulesInfoFunc(),
Expand Down
11 changes: 7 additions & 4 deletions cmd/thanos/store.go
Expand Up @@ -390,11 +390,14 @@ func runStore(
return bs.LabelSet()
}),
info.WithStoreInfoFunc(func() *infopb.StoreInfo {
mint, maxt := bs.TimeRange()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
if httpProbe.IsReady() {
mint, maxt := bs.TimeRange()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
}
}
return nil
}),
)

Expand Down
6 changes: 3 additions & 3 deletions pkg/prober/http.go
Expand Up @@ -32,7 +32,7 @@ func (p *HTTPProbe) HealthyHandler(logger log.Logger) http.HandlerFunc {

// ReadyHandler returns a HTTP Handler which responds readiness checks.
func (p *HTTPProbe) ReadyHandler(logger log.Logger) http.HandlerFunc {
return p.handler(logger, p.isReady)
return p.handler(logger, p.IsReady)
}

func (p *HTTPProbe) handler(logger log.Logger, c check) http.HandlerFunc {
Expand All @@ -47,8 +47,8 @@ func (p *HTTPProbe) handler(logger log.Logger, c check) http.HandlerFunc {
}
}

// isReady returns true if component is ready.
func (p *HTTPProbe) isReady() bool {
// IsReady returns true if component is ready.
func (p *HTTPProbe) IsReady() bool {
ready := p.ready.Load()
return ready > 0
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/prober/http_test.go
Expand Up @@ -27,7 +27,7 @@ func TestHTTPProberHealthInitialState(t *testing.T) {
func TestHTTPProberReadinessInitialState(t *testing.T) {
p := NewHTTP()

testutil.Assert(t, !p.isReady(), "initially should not be ready")
testutil.Assert(t, !p.IsReady(), "initially should not be ready")
}

func TestHTTPProberHealthyStatusSetting(t *testing.T) {
Expand All @@ -49,11 +49,11 @@ func TestHTTPProberReadyStatusSetting(t *testing.T) {

p.Ready()

testutil.Assert(t, p.isReady(), "should be ready")
testutil.Assert(t, p.IsReady(), "should be ready")

p.NotReady(testError)

testutil.Assert(t, !p.isReady(), "should not be ready")
testutil.Assert(t, !p.IsReady(), "should not be ready")
}

func TestHTTPProberMuxRegistering(t *testing.T) {
Expand Down

0 comments on commit f0e673a

Please sign in to comment.