mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Add target to context (#10473)
Signed-off-by: Goutham Veeramachaneni <gouthamve@gmail.com>
This commit is contained in:
parent
1291ec7185
commit
4d8bbfd416
|
@ -305,6 +305,7 @@ func newScrapePool(cfg *config.ScrapeConfig, app storage.Appendable, jitterSeed
|
||||||
|
|
||||||
// Store the cache in the context.
|
// Store the cache in the context.
|
||||||
loopCtx := ContextWithMetricMetadataStore(ctx, cache)
|
loopCtx := ContextWithMetricMetadataStore(ctx, cache)
|
||||||
|
loopCtx = ContextWithTarget(loopCtx, opts.target)
|
||||||
|
|
||||||
return newScrapeLoop(
|
return newScrapeLoop(
|
||||||
loopCtx,
|
loopCtx,
|
||||||
|
@ -1812,6 +1813,7 @@ type ctxKey int
|
||||||
// Valid CtxKey values.
|
// Valid CtxKey values.
|
||||||
const (
|
const (
|
||||||
ctxKeyMetadata ctxKey = iota + 1
|
ctxKeyMetadata ctxKey = iota + 1
|
||||||
|
ctxKeyTarget
|
||||||
)
|
)
|
||||||
|
|
||||||
func ContextWithMetricMetadataStore(ctx context.Context, s MetricMetadataStore) context.Context {
|
func ContextWithMetricMetadataStore(ctx context.Context, s MetricMetadataStore) context.Context {
|
||||||
|
@ -1822,3 +1824,12 @@ func MetricMetadataStoreFromContext(ctx context.Context) (MetricMetadataStore, b
|
||||||
s, ok := ctx.Value(ctxKeyMetadata).(MetricMetadataStore)
|
s, ok := ctx.Value(ctxKeyMetadata).(MetricMetadataStore)
|
||||||
return s, ok
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue