Skip to content

Commit

Permalink
Upstream changes for PR #3361 - Added request logging for gRPC and HT…
Browse files Browse the repository at this point in the history
…TP in the server side (#3862)

* Added request logging for grpc

Signed-off-by: Yash Sharma <[email protected]>

Added request logging for grpc

Signed-off-by: Yash Sharma <[email protected]>

changed the logging option to log start and finish of a call

Signed-off-by: Yash Sharma <[email protected]>

added flags for enabling/disabling request logging for grpc

Signed-off-by: Yash Sharma <[email protected]>

nitpicks due to make docs

Signed-off-by: Yash Sharma <[email protected]>

added a changelog

Signed-off-by: Yash Sharma <[email protected]>

nitpicks

Signed-off-by: Yash Sharma <[email protected]>

configure option for logging

Signed-off-by: Yash Sharma <[email protected]>

changelog nitpick

Signed-off-by: Yash Sharma <[email protected]>

added changelog

Signed-off-by: Yash Sharma <[email protected]>

more nitpicks

Signed-off-by: Yash Sharma <[email protected]>

renamed requestLoggingDecision to reqLogDecision and some nitcpicks

Signed-off-by: Yash Sharma <[email protected]>

Added the check of reusing the request-id if present

Signed-off-by: Yash Sharma <[email protected]>

make docs nitpick

Signed-off-by: Yash Sharma <[email protected]>

Added the default level of debug and error codes for logging

Signed-off-by: Yash Sharma <[email protected]>

Add the levels for logging

Signed-off-by: Yash Sharma <[email protected]>

Added a YAML flag for request logging config

Signed-off-by: Yash Sharma <[email protected]>

Changed the setup signature to accept a reqlog param to be shared among all the components of Thanos. Changed the signature of decision for logging, and pushed the new yaml config among all the middleware

Signed-off-by: Yash Sharma <[email protected]>

Updated the grpc middleware package to include the latest signature of the decider

Signed-off-by: Yash Sharma <[email protected]>

Added new config files for YAML parsing

Signed-off-by: Yash Sharma <[email protected]>

changelog nitpick

Signed-off-by: Yash Sharma <[email protected]>

linting nitpicks

Signed-off-by: Yash Sharma <[email protected]>

Added deprecation warning and added a function to reroute logging through one of the flags

Signed-off-by: Yash Sharma <[email protected]>

docs nitpicks

Signed-off-by: Yash Sharma <[email protected]>

bug fix for reverse logging condition

Signed-off-by: Yash Sharma <[email protected]>

fixed some bugs for evaluating the options and added a warning for deprecating flag of log.request.decision

Signed-off-by: Yash Sharma <[email protected]>

removed gophercloud from go.mod

Signed-off-by: Yash Sharma <[email protected]>

self addressed comments

Signed-off-by: Yash Sharma <[email protected]>

* Added a dummy variable which was used by the, to be deprecated flag of request logging
* Added a warning that request logging is disabled for tools
* Removed a flag which is to be deprecated in the next release

Signed-off-by: Yash Sharma <[email protected]>

* Added a fail-first approach if the request logging is incorrectly enabled.

Signed-off-by: Yash Sharma <[email protected]>

Renaming of functions

Signed-off-by: Yash Sharma <[email protected]>

Removed indentation and simplified else conditions

Signed-off-by: Yash Sharma <[email protected]>

break down the yaml struct for grpc and http into its individual configs

Signed-off-by: Yash Sharma <[email protected]>

make docs nits

Signed-off-by: Yash Sharma <[email protected]>

modify changelog

Signed-off-by: Yash Sharma <[email protected]>

modified the signature of setup function to the original one

Signed-off-by: Yash Sharma <[email protected]>

removed the message for the flags

Signed-off-by: Yash Sharma <[email protected]>

make docs nits

Signed-off-by: Yash Sharma <[email protected]>

Added auto generation scripts for req logging

Signed-off-by: Yash Sharma <[email protected]>

removed request logging from compactor

Signed-off-by: Yash Sharma <[email protected]>

remove verbose warn messages

Signed-off-by: Yash Sharma <[email protected]>

changed pass by value to pass by reference

Signed-off-by: Yash Sharma <[email protected]>

removed occurence of os.Exit

Signed-off-by: Yash Sharma <[email protected]>

make docs nits

Signed-off-by: Yash Sharma <[email protected]>

revert compact.go to master

Signed-off-by: Yash Sharma <[email protected]>

rename ReqlogConfig to RequestConfig

Signed-off-by: Yash Sharma <[email protected]>

Added a validation check so that all the configs are checked before a component starts

Signed-off-by: Yash Sharma <[email protected]>

nits

Signed-off-by: Yash Sharma <[email protected]>

Modify the message for request.logging flag for having a default value as null

Signed-off-by: Yash Sharma <[email protected]>

remove a line from the flags

Signed-off-by: Yash Sharma <[email protected]>

remove a deceptive comment

Signed-off-by: Yash Sharma <[email protected]>

changed the var name to small caps

Signed-off-by: Yash Sharma <[email protected]>

change errors.Errorf to Wrapf for providing context to error message

Signed-off-by: Yash Sharma <[email protected]>

move changelog entry to unreleased tag

Signed-off-by: Yash Sharma <[email protected]>

changed request.logging to `request.logging` in the flags

Signed-off-by: Yash Sharma <[email protected]>

* added changelog entry

Signed-off-by: Yash Sharma <[email protected]>

* changed changelog

Signed-off-by: Yash Sharma <[email protected]>

* renamed decidehttpflag and decidegrpcflag

Signed-off-by: Yash Sharma <[email protected]>

* addressed reviewers comments

Signed-off-by: Yash Sharma <[email protected]>
  • Loading branch information
yashrsharma44 authored Mar 4, 2021
1 parent 569a4d7 commit befb025
Show file tree
Hide file tree
Showing 28 changed files with 733 additions and 72 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re

### Added

- [#3862](https://github.com/thanos-io/thanos/pull/3862) Sidecar, Store, Query, Ruler, Receiver, Query-Frontend: Added request logging for gRPC and HTTP in the server side.
- [#3740](https://github.com/thanos-io/thanos/pull/3740) Query: Added `--query.default-step` flag to set default step.
- [#3700](https://github.com/thanos-io/thanos/pull/3700) ui: make old bucket viewer UI work with vanilla Prometheus blocks
- [#2641](https://github.com/thanos-io/thanos/issues/2641) Query Frontend: Added `--query-range.request-downsampled` flag enabling additional queries for downsampled data in case of empty or incomplete response to range request.
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func runCompact(
global.Register(r, false, ins)

// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func() logging.Decision {
opts := []logging.Option{logging.WithDecider(func(_ string, _ error) logging.Decision {
return logging.NoLogCall
})}
logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...)
Expand Down
30 changes: 22 additions & 8 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
"github.com/oklog/run"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
Expand All @@ -25,6 +26,7 @@ import (
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/promql"

grpc_logging "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
v1 "github.com/thanos-io/thanos/pkg/api/query"
"github.com/thanos-io/thanos/pkg/compact/downsample"
"github.com/thanos-io/thanos/pkg/component"
Expand Down Expand Up @@ -66,7 +68,7 @@ func registerQuery(app *extkingpin.App) {
webExternalPrefix := cmd.Flag("web.external-prefix", "Static prefix for all HTML links and redirect URLs in the UI query web interface. Actual endpoints are still served on / or the web.route-prefix. This allows thanos UI to be served behind a reverse proxy that strips a URL sub-path.").Default("").String()
webPrefixHeaderName := cmd.Flag("web.prefix-header", "Name of HTTP request header used for dynamic prefixing of UI links and redirects. This option is ignored if web.external-prefix argument is set. Security risk: enable this option only if a reverse proxy in front of thanos is resetting the header. The --web.prefix-header=X-Forwarded-Prefix option can be useful, for example, if Thanos UI is served via Traefik reverse proxy with PathPrefixStrip option enabled, which sends the stripped prefix value in X-Forwarded-Prefix header. This allows thanos UI to be served on a sub-path.").Default("").String()

requestLoggingDecision := cmd.Flag("log.request.decision", "Request Logging for logging the start and end of requests. LogFinishCall is enabled by default. LogFinishCall : Logs the finish call of the requests. LogStartAndFinishCall : Logs the start and finish call of the requests. NoLogCall : Disable request logging.").Default("LogFinishCall").Enum("NoLogCall", "LogFinishCall", "LogStartAndFinishCall")
reqLogDecision := cmd.Flag("log.request.decision", "Deprecation Warning - This flag would be soon deprecated, and replaced with `request.logging-config`. Request Logging for logging the start and end of requests. By default this flag is disabled. LogFinishCall: Logs the finish call of the requests. LogStartAndFinishCall: Logs the start and finish call of the requests. NoLogCall: Disable request logging.").Default("").Enum("NoLogCall", "LogFinishCall", "LogStartAndFinishCall", "")

queryTimeout := extkingpin.ModelDuration(cmd.Flag("query.timeout", "Maximum time to process query by query node.").
Default("2m"))
Expand Down Expand Up @@ -136,6 +138,7 @@ func registerQuery(app *extkingpin.App) {
Default("1s"))

storeResponseTimeout := extkingpin.ModelDuration(cmd.Flag("store.response-timeout", "If a Store doesn't send any data in this specified duration then a Store will be ignored and partial data will be returned if it's enabled. 0 disables timeout.").Default("0ms"))
reqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd)

cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ <-chan struct{}, _ bool) error {
selectorLset, err := parseFlagLabels(*selectorLabels)
Expand All @@ -155,6 +158,16 @@ func registerQuery(app *extkingpin.App) {
return errors.Errorf("Address %s is duplicated for --metadata flag.", dup)
}

httpLogOpts, err := logging.ParseHTTPOptions(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

tagOpts, grpcLogOpts, err := logging.ParsegRPCOptions(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

var fileSD *file.Discovery
if len(*fileSDFiles) > 0 {
conf := &file.SDConfig{
Expand All @@ -177,7 +190,9 @@ func registerQuery(app *extkingpin.App) {
logger,
reg,
tracer,
*requestLoggingDecision,
httpLogOpts,
grpcLogOpts,
tagOpts,
*grpcBindAddr,
time.Duration(*grpcGracePeriod),
*grpcCert,
Expand Down Expand Up @@ -230,7 +245,9 @@ func runQuery(
logger log.Logger,
reg *prometheus.Registry,
tracer opentracing.Tracer,
requestLoggingDecision string,
httpLogOpts []logging.Option,
grpcLogOpts []grpc_logging.Option,
tagOpts []tags.Option,
grpcBindAddr string,
grpcGracePeriod time.Duration,
grpcCert string,
Expand Down Expand Up @@ -471,10 +488,7 @@ func runQuery(
}

// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func() logging.Decision {
return logging.LogDecision[requestLoggingDecision]
})}
logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...)
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)

ins := extpromhttp.NewInstrumentationMiddleware(reg)
// TODO(bplotka in PR #513 review): pass all flags, not only the flags needed by prefix rewriting.
Expand Down Expand Up @@ -529,7 +543,7 @@ func runQuery(
return errors.Wrap(err, "setup gRPC server")
}

s := grpcserver.New(logger, reg, tracer, comp, grpcProbe,
s := grpcserver.New(logger, reg, tracer, grpcLogOpts, tagOpts, comp, grpcProbe,
grpcserver.WithServer(store.RegisterStoreServer(proxy)),
grpcserver.WithServer(rules.RegisterRulesServer(rulesProxy)),
grpcserver.WithServer(metadata.RegisterMetadataServer(metadataProxy)),
Expand Down
16 changes: 10 additions & 6 deletions cmd/thanos/query_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,16 @@ func registerQueryFrontend(app *extkingpin.App) {
"If multiple headers match the request, the first matching arg specified will take precedence. "+
"If no headers match 'anonymous' will be used.").PlaceHolder("<http-header-name>").StringsVar(&cfg.orgIdHeaders)

cmd.Flag("log.request.decision", "Request Logging for logging the start and end of requests. LogFinishCall is enabled by default. LogFinishCall : Logs the finish call of the requests. LogStartAndFinishCall : Logs the start and finish call of the requests. NoLogCall : Disable request logging.").Default("LogFinishCall").EnumVar(&cfg.RequestLoggingDecision, "NoLogCall", "LogFinishCall", "LogStartAndFinishCall")
cmd.Flag("log.request.decision", "Deprecation Warning - This flag would be soon deprecated, and replaced with `request.logging-config`. Request Logging for logging the start and end of requests. By default this flag is disabled. LogFinishCall : Logs the finish call of the requests. LogStartAndFinishCall : Logs the start and finish call of the requests. NoLogCall : Disable request logging.").Default("").EnumVar(&cfg.RequestLoggingDecision, "NoLogCall", "LogFinishCall", "LogStartAndFinishCall", "")
reqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd)

cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ <-chan struct{}, _ bool) error {
return runQueryFrontend(g, logger, reg, tracer, cfg, comp)
httpLogOpts, err := logging.ParseHTTPOptions(cfg.RequestLoggingDecision, reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

return runQueryFrontend(g, logger, reg, tracer, httpLogOpts, cfg, comp)
})
}

Expand All @@ -137,6 +143,7 @@ func runQueryFrontend(
logger log.Logger,
reg *prometheus.Registry,
tracer opentracing.Tracer,
httpLogOpts []logging.Option,
cfg *queryFrontendConfig,
comp component.Component,
) error {
Expand Down Expand Up @@ -201,10 +208,7 @@ func runQueryFrontend(
)

// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func() logging.Decision {
return logging.LogDecision[cfg.RequestLoggingDecision]
})}
logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...)
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)
ins := extpromhttp.NewInstrumentationMiddleware(reg)

// Start metrics HTTP server.
Expand Down
15 changes: 14 additions & 1 deletion cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
grpc_logging "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
"github.com/oklog/run"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
Expand All @@ -25,6 +27,7 @@ import (
"github.com/thanos-io/thanos/pkg/block/metadata"

"github.com/thanos-io/thanos/pkg/extkingpin"
"github.com/thanos-io/thanos/pkg/logging"

"github.com/thanos-io/thanos/pkg/component"
"github.com/thanos-io/thanos/pkg/extflag"
Expand Down Expand Up @@ -102,6 +105,8 @@ func registerReceive(app *extkingpin.App) {
"about order.").
Default("false").Hidden().Bool()

reqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd)

cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ <-chan struct{}, _ bool) error {
lset, err := parseFlagLabels(*labelStrs)
if err != nil {
Expand All @@ -112,6 +117,11 @@ func registerReceive(app *extkingpin.App) {
return errors.New("no external labels configured for receive, uniquely identifying external labels must be configured (ideally with `receive_` prefix); see https://thanos.io/tip/thanos/storage.md#external-labels for details.")
}

tagOpts, grpcLogOpts, err := logging.ParsegRPCOptions("", reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

tsdbOpts := &tsdb.Options{
MinBlockDuration: int64(time.Duration(*tsdbMinBlockDuration) / time.Millisecond),
MaxBlockDuration: int64(time.Duration(*tsdbMaxBlockDuration) / time.Millisecond),
Expand All @@ -138,6 +148,7 @@ func registerReceive(app *extkingpin.App) {
logger,
reg,
tracer,
grpcLogOpts, tagOpts,
*grpcBindAddr,
time.Duration(*grpcGracePeriod),
*grpcCert,
Expand Down Expand Up @@ -180,6 +191,8 @@ func runReceive(
logger log.Logger,
reg *prometheus.Registry,
tracer opentracing.Tracer,
grpcLogOpts []grpc_logging.Option,
tagOpts []tags.Option,
grpcBindAddr string,
grpcGracePeriod time.Duration,
grpcCert string,
Expand Down Expand Up @@ -494,7 +507,7 @@ func runReceive(
WriteableStoreServer: webHandler,
}

s = grpcserver.New(logger, &receive.UnRegisterer{Registerer: reg}, tracer, comp, grpcProbe,
s = grpcserver.New(logger, &receive.UnRegisterer{Registerer: reg}, tracer, grpcLogOpts, tagOpts, comp, grpcProbe,
grpcserver.WithServer(store.RegisterStoreServer(rw)),
grpcserver.WithServer(store.RegisterWritableStoreServer(rw)),
grpcserver.WithListen(grpcBindAddr),
Expand Down
31 changes: 23 additions & 8 deletions cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
grpc_logging "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
"github.com/oklog/run"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
Expand Down Expand Up @@ -99,7 +101,7 @@ func registerRule(app *extkingpin.App) {
webExternalPrefix := cmd.Flag("web.external-prefix", "Static prefix for all HTML links and redirect URLs in the UI query web interface. Actual endpoints are still served on / or the web.route-prefix. This allows thanos UI to be served behind a reverse proxy that strips a URL sub-path.").Default("").String()
webPrefixHeaderName := cmd.Flag("web.prefix-header", "Name of HTTP request header used for dynamic prefixing of UI links and redirects. This option is ignored if web.external-prefix argument is set. Security risk: enable this option only if a reverse proxy in front of thanos is resetting the header. The --web.prefix-header=X-Forwarded-Prefix option can be useful, for example, if Thanos UI is served via Traefik reverse proxy with PathPrefixStrip option enabled, which sends the stripped prefix value in X-Forwarded-Prefix header. This allows thanos UI to be served on a sub-path.").Default("").String()

requestLoggingDecision := cmd.Flag("log.request.decision", "Request Logging for logging the start and end of requests. LogFinishCall is enabled by default. LogFinishCall : Logs the finish call of the requests. LogStartAndFinishCall : Logs the start and finish call of the requests. NoLogCall : Disable request logging.").Default("LogFinishCall").Enum("NoLogCall", "LogFinishCall", "LogStartAndFinishCall")
reqLogDecision := cmd.Flag("log.request.decision", "Deprecation Warning - This flag would be soon deprecated, and replaced with `request.logging-config`. Request Logging for logging the start and end of requests. By default this flag is disabled. LogFinishCall: Logs the finish call of the requests. LogStartAndFinishCall: Logs the start and finish call of the requests. NoLogCall: Disable request logging.").Default("").Enum("NoLogCall", "LogFinishCall", "LogStartAndFinishCall", "")

objStoreConfig := extkingpin.RegisterCommonObjStoreFlags(cmd, "", false)

Expand Down Expand Up @@ -132,6 +134,8 @@ func registerRule(app *extkingpin.App) {
hashFunc := cmd.Flag("hash-func", "Specify which hash function to use when calculating the hashes of produced files. If no function has been specified, it does not happen. This permits avoiding downloading some files twice albeit at some performance cost. Possible values are: \"\", \"SHA256\".").
Default("").Enum("SHA256", "")

reqLogConfig := extkingpin.RegisterRequestLoggingFlags(cmd)

cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, reload <-chan struct{}, _ bool) error {
lset, err := parseFlagLabels(*labelStrs)
if err != nil {
Expand Down Expand Up @@ -180,11 +184,23 @@ func registerRule(app *extkingpin.App) {
return errors.New("--alertmanagers.url and --alertmanagers.config* parameters cannot be defined at the same time")
}

httpLogOpts, err := logging.ParseHTTPOptions(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

tagOpts, grpcLogOpts, err := logging.ParsegRPCOptions(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

return runRule(g,
logger,
reg,
tracer,
*requestLoggingDecision,
httpLogOpts,
grpcLogOpts,
tagOpts,
reload,
lset,
*alertmgrs,
Expand Down Expand Up @@ -275,7 +291,9 @@ func runRule(
logger log.Logger,
reg *prometheus.Registry,
tracer opentracing.Tracer,
requestLoggingDecision string,
httpLogOpts []logging.Option,
grpcLogOpts []grpc_logging.Option,
tagOpts []tags.Option,
reloadSignal <-chan struct{},
lset labels.Labels,
alertmgrURLs []string,
Expand Down Expand Up @@ -561,7 +579,7 @@ func runRule(
}

// TODO: Add rules API implementation when ready.
s := grpcserver.New(logger, reg, tracer, comp, grpcProbe,
s := grpcserver.New(logger, reg, tracer, grpcLogOpts, tagOpts, comp, grpcProbe,
grpcserver.WithServer(store.RegisterStoreServer(tsdbStore)),
grpcserver.WithServer(thanosrules.RegisterRulesServer(ruleMgr)),
grpcserver.WithListen(grpcBindAddr),
Expand Down Expand Up @@ -603,10 +621,7 @@ func runRule(
ins := extpromhttp.NewInstrumentationMiddleware(reg)

// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func() logging.Decision {
return logging.LogDecision[requestLoggingDecision]
})}
logMiddleware := logging.NewHTTPServerMiddleware(logger, opts...)
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)

// TODO(bplotka in PR #513 review): pass all flags, not only the flags needed by prefix rewriting.
ui.NewRuleUI(logger, reg, ruleMgr, alertQueryURL.String(), webExternalPrefix, webPrefixHeaderName).Register(router, ins)
Expand Down
16 changes: 14 additions & 2 deletions cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
grpc_logging "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging"
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
"github.com/oklog/run"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
Expand All @@ -27,6 +29,7 @@ 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/logging"
meta "github.com/thanos-io/thanos/pkg/metadata"
thanosmodel "github.com/thanos-io/thanos/pkg/model"
"github.com/thanos-io/thanos/pkg/objstore/client"
Expand All @@ -48,6 +51,11 @@ func registerSidecar(app *extkingpin.App) {
conf := &sidecarConfig{}
conf.registerFlag(cmd)
cmd.Setup(func(g *run.Group, logger log.Logger, reg *prometheus.Registry, tracer opentracing.Tracer, _ <-chan struct{}, _ bool) error {
tagOpts, grpcLogOpts, err := logging.ParsegRPCOptions("", conf.reqLogConfig)
if err != nil {
return errors.Wrap(err, "error while parsing config for request logging")
}

rl := reloader.New(log.With(logger, "component", "reloader"),
extprom.WrapRegistererWithPrefix("thanos_sidecar_", reg),
&reloader.Options{
Expand All @@ -59,7 +67,7 @@ func registerSidecar(app *extkingpin.App) {
RetryInterval: conf.reloader.retryInterval,
})

return runSidecar(g, logger, reg, tracer, rl, component.Sidecar, *conf)
return runSidecar(g, logger, reg, tracer, rl, component.Sidecar, *conf, grpcLogOpts, tagOpts)
})
}

Expand All @@ -71,6 +79,8 @@ func runSidecar(
reloader *reloader.Reloader,
comp component.Component,
conf sidecarConfig,
grpcLogOpts []grpc_logging.Option,
tagOpts []tags.Option,
) error {
var m = &promMetadata{
promURL: conf.prometheus.url,
Expand Down Expand Up @@ -216,7 +226,7 @@ func runSidecar(
return errors.Wrap(err, "setup gRPC server")
}

s := grpcserver.New(logger, reg, tracer, comp, grpcProbe,
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(meta.RegisterMetadataServer(meta.NewPrometheus(conf.prometheus.url, c))),
Expand Down Expand Up @@ -390,6 +400,7 @@ type sidecarConfig struct {
connection connConfig
tsdb tsdbConfig
reloader reloaderConfig
reqLogConfig *extflag.PathOrContent
objStore extflag.PathOrContent
shipper shipperConfig
limitMinTime thanosmodel.TimeOrDurationValue
Expand All @@ -402,6 +413,7 @@ func (sc *sidecarConfig) registerFlag(cmd extkingpin.FlagClause) {
sc.connection.registerFlag(cmd)
sc.tsdb.registerFlag(cmd)
sc.reloader.registerFlag(cmd)
sc.reqLogConfig = extkingpin.RegisterRequestLoggingFlags(cmd)
sc.objStore = *extkingpin.RegisterCommonObjStoreFlags(cmd, "", false)
sc.shipper.registerFlag(cmd)
cmd.Flag("min-time", "Start of time range limit to serve. Thanos sidecar will serve only metrics, which happened later than this value. Option can be a constant time in RFC3339 format or time duration relative to current time, such as -1d or 2h45m. Valid duration units are ms, s, m, h, d, w, y.").
Expand Down
Loading

0 comments on commit befb025

Please sign in to comment.