-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add single compactor http client for delete and gennumber clients #7453
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -350,7 +350,7 @@ func (t *Loki) initQuerier() (services.Service, error) { | |
toMerge := []middleware.Interface{ | ||
httpreq.ExtractQueryMetricsMiddleware(), | ||
} | ||
if t.supportIndexDeleteRequest() { | ||
if t.supportIndexDeleteRequest() && t.Cfg.CompactorConfig.RetentionEnabled { | ||
toMerge = append( | ||
toMerge, | ||
queryrangebase.CacheGenNumberHeaderSetterMiddleware(t.cacheGenerationLoader), | ||
|
@@ -660,7 +660,8 @@ func (t *Loki) initQueryFrontendTripperware() (_ services.Service, err error) { | |
t.Cfg.QueryRange, | ||
util_log.Logger, | ||
t.overrides, | ||
t.Cfg.SchemaConfig, t.cacheGenerationLoader, | ||
t.Cfg.SchemaConfig, | ||
t.cacheGenerationLoader, t.Cfg.CompactorConfig.RetentionEnabled, | ||
prometheus.DefaultRegisterer, | ||
) | ||
if err != nil { | ||
|
@@ -679,7 +680,13 @@ func (t *Loki) initCacheGenerationLoader() (_ services.Service, err error) { | |
if err != nil { | ||
return nil, err | ||
} | ||
client, err = generationnumber.NewGenNumberClient(compactorAddress, &http.Client{Timeout: 5 * time.Second}) | ||
|
||
httpClient, err := compactor.NewCompactorHTTPClient(t.Cfg.CompactorClient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client, err = generationnumber.NewGenNumberClient(compactorAddress, httpClient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
@@ -1112,7 +1119,7 @@ func (t *Loki) initUsageReport() (services.Service, error) { | |
} | ||
|
||
func (t *Loki) deleteRequestsClient(clientType string, limits *validation.Overrides) (deletion.DeleteRequestsClient, error) { | ||
if !t.supportIndexDeleteRequest() { | ||
if !t.supportIndexDeleteRequest() || !t.Cfg.CompactorConfig.RetentionEnabled { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, this seems to add to the argument this additional check should be moved into that function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, it is more explicit for the reader that we need an index store that supports deletes and explicitly opt-in to use the feature. |
||
return deletion.NewNoOpDeleteRequestsStore(), nil | ||
} | ||
|
||
|
@@ -1121,7 +1128,7 @@ func (t *Loki) deleteRequestsClient(clientType string, limits *validation.Overri | |
return nil, err | ||
} | ||
|
||
httpClient, err := deletion.NewDeleteHTTPClient(t.Cfg.DeleteClient) | ||
httpClient, err := compactor.NewCompactorHTTPClient(t.Cfg.CompactorClient) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,7 @@ type resultsCache struct { | |
merger Merger | ||
cacheGenNumberLoader CacheGenNumberLoader | ||
shouldCache ShouldCacheFn | ||
retentionEnabled bool | ||
metrics *ResultsCacheMetrics | ||
} | ||
|
||
|
@@ -181,6 +182,7 @@ func NewResultsCacheMiddleware( | |
extractor Extractor, | ||
cacheGenNumberLoader CacheGenNumberLoader, | ||
shouldCache ShouldCacheFn, | ||
retentionEnabled bool, | ||
metrics *ResultsCacheMetrics, | ||
) (Middleware, error) { | ||
if cacheGenNumberLoader != nil { | ||
|
@@ -199,6 +201,7 @@ func NewResultsCacheMiddleware( | |
splitter: splitter, | ||
cacheGenNumberLoader: cacheGenNumberLoader, | ||
shouldCache: shouldCache, | ||
retentionEnabled: retentionEnabled, | ||
metrics: metrics, | ||
} | ||
}), nil | ||
|
@@ -214,7 +217,7 @@ func (s resultsCache) Do(ctx context.Context, r Request) (Response, error) { | |
return s.next.Do(ctx, r) | ||
} | ||
|
||
if s.cacheGenNumberLoader != nil { | ||
if s.cacheGenNumberLoader != nil && s.retentionEnabled { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again I'm not quite sure why we are having to add this check now but it wasn't needed before? seems out of scope with adding TLS support to the client, so I'm curious what motivated it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although it seems out of scope, but on the other hand fixing TLS makes the 404s visible in the querier/ruler logs. I know if you run the entire system withough TLS you see the 404s anyway if retention is disabled. In any case both bits missing TLS support and 404s on disabled retentions are hindsights of the compactor client. IMHO the PR is just removing these hindsights and we may need to just re-title/change the changelog entry to be more informative in that direction. WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sounds like good enough justification to me! thanks for that added context. |
||
ctx = cache.InjectCacheGenNumber(ctx, s.cacheGenNumberLoader.GetResultsCacheGenNumber(tenantIDs)) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package compactor | ||
|
||
import ( | ||
"flag" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/grafana/dskit/crypto/tls" | ||
) | ||
|
||
// Config for compactor's generation-number client | ||
type ClientConfig struct { | ||
TLSEnabled bool `yaml:"tls_enabled"` | ||
TLS tls.ClientConfig `yaml:",inline"` | ||
} | ||
|
||
// RegisterFlags adds the flags required to config this to the given FlagSet. | ||
func (cfg *ClientConfig) RegisterFlags(f *flag.FlagSet) { | ||
prefix := "boltdb.shipper.compactor.client" | ||
f.BoolVar(&cfg.TLSEnabled, prefix+".tls-enabled", false, | ||
periklis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Enable TLS in the HTTP client. This flag needs to be enabled when any other TLS flag is set. If set to false, insecure connection to HTTP server will be used.") | ||
cfg.TLS.RegisterFlagsWithPrefix(prefix, f) | ||
} | ||
|
||
// NewDeleteHTTPClient return a pointer to a http client instance based on the | ||
// delete client tls settings. | ||
func NewCompactorHTTPClient(cfg ClientConfig) (*http.Client, error) { | ||
transport := http.DefaultTransport.(*http.Transport).Clone() | ||
transport.MaxIdleConns = 250 | ||
transport.MaxIdleConnsPerHost = 250 | ||
|
||
if cfg.TLSEnabled { | ||
tlsCfg, err := cfg.TLS.GetTLSConfig() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
transport.TLSClientConfig = tlsCfg | ||
} | ||
|
||
return &http.Client{Timeout: 5 * time.Second, Transport: transport}, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this additional check for, why wasn't it previously needed? You check it in combination with
t.supportIndexDeleteRequests
in multiple places so I'm curious if it should be moved into thet.supportIndexDeleteRequests
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above in the description this extra check is needed when the deletes-based retention is entirely disabled. This is the case by default IIRC and produces red-herring errors in the querier and ruler logs like this:
I found moving it into the
supportIndexDeleteRequests
obscures the fact that this method is dedicated to check if the underlying index store supports deletes. AddingRetentionEnabled
in there would make the check for retention hidden/implicit with the store capabilities. OTH as proposed in the implementation it is more explicit for the reader to know that we need an index store that supports deletes and explicitly opt-in to use the feature.