Skip to content

Commit

Permalink
Add Info server in Sidecar and StoreGW
Browse files Browse the repository at this point in the history
Signed-off-by: Hitanshu Mehta <[email protected]>
  • Loading branch information
hitanshu-mehta committed Jun 1, 2021
1 parent ea8cf49 commit 89aedf4
Show file tree
Hide file tree
Showing 9 changed files with 1,298 additions and 15 deletions.
30 changes: 29 additions & 1 deletion cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/thanos-io/thanos/pkg/extkingpin"
"github.com/thanos-io/thanos/pkg/extprom"
thanoshttp "github.com/thanos-io/thanos/pkg/http"
"github.com/thanos-io/thanos/pkg/info"
"github.com/thanos-io/thanos/pkg/info/infopb"
"github.com/thanos-io/thanos/pkg/logging"
meta "github.com/thanos-io/thanos/pkg/metadata"
thanosmodel "github.com/thanos-io/thanos/pkg/model"
Expand All @@ -43,6 +45,7 @@ import (
httpserver "github.com/thanos-io/thanos/pkg/server/http"
"github.com/thanos-io/thanos/pkg/shipper"
"github.com/thanos-io/thanos/pkg/store"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/targets"
"github.com/thanos-io/thanos/pkg/tls"
"github.com/thanos-io/thanos/pkg/tracing"
Expand Down Expand Up @@ -247,12 +250,37 @@ func runSidecar(
return errors.Wrap(err, "setup gRPC server")
}

examplarSrv := exemplars.NewPrometheus(conf.prometheus.url, c, m.Labels)

infoSrv := info.NewInfoServer(
infopb.ComponentType_SIDECAR,
func() []labelpb.ZLabelSet {
return promStore.LabelSet()
},
func() *infopb.StoreInfo {
mint, maxt := promStore.Timestamps()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
}
},
func() *infopb.ExemplarsInfo {
// Currently Exemplars API does not expose metadata such as min/max time,
// so we are using default minimum and maximum possible values as min/max time.
return &infopb.ExemplarsInfo{
MinTime: time.Unix(math.MinInt64/1000+62135596801, 0).UTC().Unix(),
MaxTime: time.Unix(math.MaxInt64/1000-62135596801, 999999999).UTC().Unix(),
}
},
)

s := grpcserver.New(logger, reg, tracer, grpcLogOpts, tagOpts, comp, grpcProbe,
grpcserver.WithServer(store.RegisterStoreServer(promStore)),
grpcserver.WithServer(rules.RegisterRulesServer(rules.NewPrometheus(conf.prometheus.url, c, m.Labels))),
grpcserver.WithServer(targets.RegisterTargetsServer(targets.NewPrometheus(conf.prometheus.url, c, m.Labels))),
grpcserver.WithServer(meta.RegisterMetadataServer(meta.NewPrometheus(conf.prometheus.url, c))),
grpcserver.WithServer(exemplars.RegisterExemplarsServer(exemplars.NewPrometheus(conf.prometheus.url, c, m.Labels))),
grpcserver.WithServer(exemplars.RegisterExemplarsServer(examplarSrv)),
grpcserver.WithServer(info.RegisterInfoServer(infoSrv)),
grpcserver.WithListen(conf.grpc.bindAddress),
grpcserver.WithGracePeriod(time.Duration(conf.grpc.gracePeriod)),
grpcserver.WithTLSConfig(tlsCfg),
Expand Down
20 changes: 20 additions & 0 deletions cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"github.com/thanos-io/thanos/pkg/extprom"
extpromhttp "github.com/thanos-io/thanos/pkg/extprom/http"
"github.com/thanos-io/thanos/pkg/gate"
"github.com/thanos-io/thanos/pkg/info"
"github.com/thanos-io/thanos/pkg/info/infopb"
"github.com/thanos-io/thanos/pkg/logging"
"github.com/thanos-io/thanos/pkg/model"
"github.com/thanos-io/thanos/pkg/objstore/client"
Expand All @@ -39,6 +41,7 @@ import (
httpserver "github.com/thanos-io/thanos/pkg/server/http"
"github.com/thanos-io/thanos/pkg/store"
storecache "github.com/thanos-io/thanos/pkg/store/cache"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"github.com/thanos-io/thanos/pkg/tls"
"github.com/thanos-io/thanos/pkg/ui"
)
Expand Down Expand Up @@ -379,6 +382,22 @@ func runStore(
cancel()
})
}

infoSrv := info.NewInfoServer(
infopb.ComponentType_STORE,
func() []labelpb.ZLabelSet {
return bs.LabelSet()
},
func() *infopb.StoreInfo {
mint, maxt := bs.TimeRange()
return &infopb.StoreInfo{
MinTime: mint,
MaxTime: maxt,
}
},
func() *infopb.ExemplarsInfo { return nil },
)

// Start query (proxy) gRPC StoreAPI.
{
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpcConfig.tlsSrvCert, conf.grpcConfig.tlsSrvKey, conf.grpcConfig.tlsSrvClientCA)
Expand All @@ -388,6 +407,7 @@ func runStore(

s := grpcserver.New(logger, reg, tracer, grpcLogOpts, tagOpts, conf.component, grpcProbe,
grpcserver.WithServer(store.RegisterStoreServer(bs)),
grpcserver.WithServer(info.RegisterInfoServer(infoSrv)),
grpcserver.WithListen(conf.grpcConfig.bindAddress),
grpcserver.WithGracePeriod(time.Duration(conf.grpcConfig.gracePeriod)),
grpcserver.WithTLSConfig(tlsCfg),
Expand Down
54 changes: 54 additions & 0 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

package info

import (
"context"

"github.com/go-kit/kit/log"
"github.com/thanos-io/thanos/pkg/info/infopb"
"github.com/thanos-io/thanos/pkg/store/labelpb"
"google.golang.org/grpc"
)

type InfoServer struct {
infopb.UnimplementedInfoServer

logger log.Logger
component infopb.ComponentType

getLabelSet func() []labelpb.ZLabelSet
getStoreInfo func() *infopb.StoreInfo
getExemplarsInfo func() *infopb.ExemplarsInfo
}

func NewInfoServer(
component infopb.ComponentType,
getLabelSet func() []labelpb.ZLabelSet,
getStoreInfo func() *infopb.StoreInfo,
getExemplarsInfo func() *infopb.ExemplarsInfo,
) *InfoServer {
return &InfoServer{
component: component,
getLabelSet: getLabelSet,
getStoreInfo: getStoreInfo,
getExemplarsInfo: getExemplarsInfo,
}
}

// RegisterInfoServer register info server.
func RegisterInfoServer(infoSrv infopb.InfoServer) func(*grpc.Server) {
return func(s *grpc.Server) {
infopb.RegisterInfoServer(s, infoSrv)
}
}

func (srv *InfoServer) Info(ctx context.Context, req *infopb.InfoRequest) (*infopb.InfoResponse, error) {
return &infopb.InfoResponse{
LabelSets: srv.getLabelSet(),
ComponentType: srv.component,
StoreInfo: srv.getStoreInfo(),
ExemplarsInfo: srv.getExemplarsInfo(),
}, nil
}
Loading

0 comments on commit 89aedf4

Please sign in to comment.