Revoke storing target and metadata cache in context. (#10590)

Storing the scrape cache and the target (which also contains that cache)
is apparently causing hige memory increase. I think me might not control
the lifespan of the context enough, therefore old objects keep living in
memory for longer than needed.

Let's unblock the release and look for an alternative so that downstream
consumers can get access to that data.

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
pull/10599/head
Julien Pivotto 2022-04-14 15:18:46 +02:00 committed by GitHub
parent 4d8b77546d
commit db8c550570
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 33 deletions

View File

@ -298,12 +298,8 @@ func newScrapePool(cfg *config.ScrapeConfig, app storage.Appendable, jitterSeed
} }
opts.target.SetMetadataStore(cache) opts.target.SetMetadataStore(cache)
// Store the cache in the context.
loopCtx := ContextWithMetricMetadataStore(ctx, cache)
loopCtx = ContextWithTarget(loopCtx, opts.target)
return newScrapeLoop( return newScrapeLoop(
loopCtx, ctx,
opts.scraper, opts.scraper,
log.With(logger, "target", opts.target), log.With(logger, "target", opts.target),
buffers, buffers,
@ -1795,31 +1791,3 @@ func reusableCache(r, l *config.ScrapeConfig) bool {
} }
return reflect.DeepEqual(zeroConfig(r), zeroConfig(l)) return reflect.DeepEqual(zeroConfig(r), zeroConfig(l))
} }
// CtxKey is a dedicated type for keys of context-embedded values propagated
// with the scrape context.
type ctxKey int
// Valid CtxKey values.
const (
ctxKeyMetadata ctxKey = iota + 1
ctxKeyTarget
)
func ContextWithMetricMetadataStore(ctx context.Context, s MetricMetadataStore) context.Context {
return context.WithValue(ctx, ctxKeyMetadata, s)
}
func MetricMetadataStoreFromContext(ctx context.Context) (MetricMetadataStore, bool) {
s, ok := ctx.Value(ctxKeyMetadata).(MetricMetadataStore)
return s, ok
}
func ContextWithTarget(ctx context.Context, t *Target) context.Context {
return context.WithValue(ctx, ctxKeyTarget, t)
}
func TargetFromContext(ctx context.Context) (*Target, bool) {
t, ok := ctx.Value(ctxKeyTarget).(*Target)
return t, ok
}