Skip to content

Commit

Permalink
Upstream changes for PR thanos-io#3361 - Added request logging for gR…
Browse files Browse the repository at this point in the history
…PC and HTTP in the server side (thanos-io#3862)

* Added request logging for grpc

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Added request logging for grpc

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

added flags for enabling/disabling request logging for grpc

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

nitpicks due to make docs

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

added a changelog

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

nitpicks

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

configure option for logging

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

changelog nitpick

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

added changelog

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

more nitpicks

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

renamed requestLoggingDecision to reqLogDecision and some nitcpicks

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Added the check of reusing the request-id if present

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

make docs nitpick

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Added the default level of debug and error codes for logging

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Add the levels for logging

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Added a YAML flag for request logging config

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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 <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Added new config files for YAML parsing

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

changelog nitpick

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

linting nitpicks

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

docs nitpicks

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

bug fix for reverse logging condition

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

removed gophercloud from go.mod

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

self addressed comments

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

* 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 <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Renaming of functions

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Removed indentation and simplified else conditions

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

make docs nits

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

modify changelog

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

modified the signature of setup function to the original one

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

removed the message for the flags

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

make docs nits

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

Added auto generation scripts for req logging

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

removed request logging from compactor

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

remove verbose warn messages

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

changed pass by value to pass by reference

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

removed occurence of os.Exit

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

make docs nits

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

revert compact.go to master

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

rename ReqlogConfig to RequestConfig

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

nits

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

remove a line from the flags

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

remove a deceptive comment

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

changed the var name to small caps

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

move changelog entry to unreleased tag

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

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

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

* added changelog entry

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

* changed changelog

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

* renamed decidehttpflag and decidegrpcflag

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>

* addressed reviewers comments

Signed-off-by: Yash Sharma <yashrsharma44@gmail.com>
  • Loading branch information
yashrsharma44 committed 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.