Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added request logging for gRPC and HTTP in the server side #3361

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
2580544
Added request logging for grpc
yashrsharma44 Oct 25, 2020
9a25121
Added request logging for grpc
yashrsharma44 Oct 25, 2020
f525ccb
changed the logging option to log start and finish of a call
yashrsharma44 Oct 25, 2020
b6d338c
added flags for enabling/disabling request logging for grpc
yashrsharma44 Oct 25, 2020
42d2284
nitpicks due to make docs
yashrsharma44 Oct 26, 2020
fdbfe9a
added a changelog
yashrsharma44 Oct 26, 2020
0633a92
nitpicks
yashrsharma44 Nov 9, 2020
c5a26f1
configure option for logging
yashrsharma44 Nov 9, 2020
96fa990
changelog nitpick
yashrsharma44 Nov 9, 2020
d32d8f2
added changelog
yashrsharma44 Nov 17, 2020
bef9889
more nitpicks
yashrsharma44 Nov 17, 2020
623e017
renamed requestLoggingDecision to reqLogDecision and some nitcpicks
yashrsharma44 Nov 17, 2020
7d5c90b
Added the check of reusing the request-id if present
yashrsharma44 Nov 17, 2020
6aefc0e
make docs nitpick
yashrsharma44 Nov 17, 2020
072c645
Added the default level of debug and error codes for logging
yashrsharma44 Nov 18, 2020
4ed4410
Add the levels for logging
yashrsharma44 Nov 18, 2020
5dd871b
Added a YAML flag for request logging config
yashrsharma44 Dec 8, 2020
9b81c85
Changed the setup signature to accept a reqlog param to be shared amo…
yashrsharma44 Dec 8, 2020
702cab9
Updated the grpc middleware package to include the latest signature o…
yashrsharma44 Dec 8, 2020
d7b592d
Added new config files for YAML parsing
yashrsharma44 Dec 8, 2020
cab016f
changelog nitpick
yashrsharma44 Dec 8, 2020
5622a1b
linting nitpicks
yashrsharma44 Dec 9, 2020
65632a2
Added deprecation warning and added a function to reroute logging thr…
yashrsharma44 Dec 10, 2020
508d187
docs nitpicks
yashrsharma44 Dec 10, 2020
a44c6e1
bug fix for reverse logging condition
yashrsharma44 Dec 10, 2020
4bf9742
fixed some bugs for evaluating the options and added a warning for de…
yashrsharma44 Dec 15, 2020
6ff8d57
removed gophercloud from go.mod
yashrsharma44 Dec 15, 2020
21eac29
self addressed comments
yashrsharma44 Dec 15, 2020
a762e13
* Added a dummy variable which was used by the, to be deprecated flag…
yashrsharma44 Dec 18, 2020
34da06d
* Added a fail-first approach if the request logging is incorrectly e…
yashrsharma44 Dec 18, 2020
bc99e87
Renaming of functions
yashrsharma44 Dec 18, 2020
8f4f1b1
Removed indentation and simplified else conditions
yashrsharma44 Dec 18, 2020
276f674
break down the yaml struct for grpc and http into its individual configs
yashrsharma44 Dec 18, 2020
20a09d8
make docs nits
yashrsharma44 Dec 18, 2020
c505074
modify changelog
yashrsharma44 Dec 18, 2020
ef51cad
modified the signature of setup function to the original one
yashrsharma44 Dec 18, 2020
d7e0774
removed the message for the flags
yashrsharma44 Dec 18, 2020
76710a6
make docs nits
yashrsharma44 Dec 18, 2020
bbfebb0
Added auto generation scripts for req logging
yashrsharma44 Dec 18, 2020
00a9788
removed request logging from compactor
yashrsharma44 Dec 18, 2020
1433ddc
remove verbose warn messages
yashrsharma44 Dec 18, 2020
01686d6
changed pass by value to pass by reference
yashrsharma44 Dec 18, 2020
aa0c220
removed occurence of os.Exit
yashrsharma44 Dec 18, 2020
6e693eb
make docs nits
yashrsharma44 Dec 18, 2020
425646a
revert compact.go to master
yashrsharma44 Dec 18, 2020
f7e98c2
rename ReqlogConfig to RequestConfig
yashrsharma44 Dec 18, 2020
a8170ab
Added a validation check so that all the configs are checked before a…
yashrsharma44 Dec 18, 2020
2b86f64
nits
yashrsharma44 Dec 18, 2020
41976b8
Modify the message for request.logging flag for having a default valu…
yashrsharma44 Jan 7, 2021
c576f05
remove a line from the flags
yashrsharma44 Jan 8, 2021
4f52da3
remove a deceptive comment
yashrsharma44 Jan 8, 2021
441caa4
changed the var name to small caps
yashrsharma44 Jan 8, 2021
86801c4
change errors.Errorf to Wrapf for providing context to error message
yashrsharma44 Jan 15, 2021
b2c01dd
move changelog entry to unreleased tag
yashrsharma44 Jan 15, 2021
e588aa1
changed request.logging to `request.logging` in the flags
yashrsharma44 Feb 12, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ We use _breaking :warning:_ to mark changes that are not backward compatible (re
### Added

- [#3700](https://github.com/thanos-io/thanos/pull/3700) ui: make old bucket viewer UI work with vanilla Prometheus blocks
- [#3361](https://github.com/thanos-io/thanos/pull/3361) Sidecar, Store, Query, Ruler, Receiver, Query-Frontend: Added request logging for gRPC and HTTP in the server side.
- [#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.

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,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
31 changes: 23 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 @@ -65,7 +67,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`. 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 @@ -126,6 +128,7 @@ func registerQuery(app *extkingpin.App) {
defaultEvaluationInterval := extkingpin.ModelDuration(cmd.Flag("query.default-evaluation-interval", "Set default evaluation interval for sub queries.").Default("1m"))

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 @@ -141,6 +144,17 @@ func registerQuery(app *extkingpin.App) {
return errors.Errorf("Address %s is duplicated for --rule flag.", dup)
}

// Check if the YAML configuration of request.logging is correct.
httpLogOpts, err := logging.DecideHTTPFlag(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrapf(err, "error while parsing config for request logging")
}

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

var fileSD *file.Discovery
if len(*fileSDFiles) > 0 {
conf := &file.SDConfig{
Expand All @@ -163,7 +177,9 @@ func registerQuery(app *extkingpin.App) {
logger,
reg,
tracer,
*requestLoggingDecision,
httpLogOpts,
grpcLogOpts,
tagOpts,
*grpcBindAddr,
time.Duration(*grpcGracePeriod),
*grpcCert,
Expand Down Expand Up @@ -213,7 +229,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 @@ -433,10 +451,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 @@ -488,7 +503,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.WithListen(grpcBindAddr),
Expand Down
17 changes: 11 additions & 6 deletions cmd/thanos/query_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,17 @@ 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`. 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)
// Check if the YAML configuration of request.logging is correct.
httpLogOpts, err := logging.DecideHTTPFlag(cfg.RequestLoggingDecision, reqLogConfig)
if err != nil {
return errors.Wrapf(err, "error while parsing config for request logging")
}

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

Expand All @@ -138,6 +145,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 @@ -208,10 +216,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
16 changes: 15 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 @@ -24,6 +26,7 @@ import (
"github.com/prometheus/prometheus/tsdb"

"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 @@ -97,6 +100,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 @@ -107,6 +112,12 @@ 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.")
}

// Check if the YAML configuration of request.logging is correct. .
tagOpts, GRPCLogOpts, err := logging.DecideGRPCFlag("", reqLogConfig)
if err != nil {
return errors.Wrapf(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 @@ -132,6 +143,7 @@ func registerReceive(app *extkingpin.App) {
logger,
reg,
tracer,
GRPCLogOpts, tagOpts,
*grpcBindAddr,
time.Duration(*grpcGracePeriod),
*grpcCert,
Expand Down Expand Up @@ -173,6 +185,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 @@ -485,7 +499,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
32 changes: 24 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`. 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 @@ -129,6 +131,8 @@ func registerRule(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, reload <-chan struct{}, _ bool) error {
lset, err := parseFlagLabels(*labelStrs)
if err != nil {
Expand Down Expand Up @@ -177,11 +181,24 @@ func registerRule(app *extkingpin.App) {
return errors.New("--alertmanagers.url and --alertmanagers.config* parameters cannot be defined at the same time")
}

// Check if the YAML configuration of request.logging is correct.
httpLogOpts, err := logging.DecideHTTPFlag(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrapf(err, "error while parsing config for request logging")
}

tagOpts, grpcLogOpts, err := logging.DecideGRPCFlag(*reqLogDecision, reqLogConfig)
if err != nil {
return errors.Wrapf(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 @@ -271,7 +288,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 @@ -556,7 +575,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 @@ -598,10 +617,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
17 changes: 15 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"
thanosmodel "github.com/thanos-io/thanos/pkg/model"
"github.com/thanos-io/thanos/pkg/objstore/client"
"github.com/thanos-io/thanos/pkg/prober"
Expand All @@ -47,6 +50,12 @@ 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 {
// Check if the YAML configuration of request.logging is correct.
tagOpts, GRPCLogOpts, err := logging.DecideGRPCFlag("", conf.reqLogConfig)
if err != nil {
return errors.Wrapf(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 @@ -58,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 @@ -70,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 @@ -215,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.WithListen(conf.grpc.bindAddress),
Expand Down Expand Up @@ -388,6 +399,7 @@ type sidecarConfig struct {
connection connConfig
tsdb tsdbConfig
reloader reloaderConfig
reqLogConfig *extflag.PathOrContent
objStore extflag.PathOrContent
shipper shipperConfig
limitMinTime thanosmodel.TimeOrDurationValue
Expand All @@ -400,6 +412,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