MCPcopy
hub / github.com/prometheus/prometheus / newScrapePool

Function newScrapePool

scrape/scrape.go:138–191  ·  view source on GitHub ↗
(
	cfg *config.ScrapeConfig,
	appendable storage.Appendable,
	appendableV2 storage.AppendableV2,
	offsetSeed uint64,
	logger *slog.Logger,
	buffers *pool.Pool,
	options *Options,
	metrics *scrapeMetrics,
)

Source from the content-addressed store, hash-verified

136}
137
138func newScrapePool(
139 cfg *config.ScrapeConfig,
140 appendable storage.Appendable,
141 appendableV2 storage.AppendableV2,
142 offsetSeed uint64,
143 logger *slog.Logger,
144 buffers *pool.Pool,
145 options *Options,
146 metrics *scrapeMetrics,
147) (*scrapePool, error) {
148 if logger == nil {
149 logger = promslog.NewNopLogger()
150 }
151 if buffers == nil {
152 buffers = pool.New(1e3, 1e6, 3, func(sz int) any { return make([]byte, 0, sz) })
153 }
154
155 client, err := newScrapeClient(cfg.HTTPClientConfig, cfg.JobName, options.HTTPClientOptions...)
156 if err != nil {
157 return nil, err
158 }
159
160 // Validate scheme so we don't need to do it later.
161 // We also do it on scrapePool.reload(...)
162 // TODO(bwplotka): Can we move it to scrape config validation?
163 if err := namevalidationutil.CheckNameValidationScheme(cfg.MetricNameValidationScheme); err != nil {
164 return nil, errors.New("newScrapePool: MetricNameValidationScheme must be set in scrape configuration")
165 }
166 if _, err = config.ToEscapingScheme(cfg.MetricNameEscapingScheme, cfg.MetricNameValidationScheme); err != nil {
167 return nil, fmt.Errorf("invalid metric name escaping scheme, %w", err)
168 }
169
170 symbols := labels.NewSymbolTable()
171 ctx, cancel := context.WithCancel(context.Background())
172 sp := &scrapePool{
173 appendable: appendable,
174 appendableV2: appendableV2,
175 logger: logger,
176 ctx: ctx,
177 cancel: cancel,
178 options: options,
179 config: cfg,
180 client: client,
181 loops: map[uint64]loop{},
182 symbolTable: symbols,
183 lastSymbolTableCheck: time.Now(),
184 activeTargets: map[uint64]*Target{},
185 metrics: metrics,
186 buffers: buffers,
187 offsetSeed: offsetSeed,
188 }
189 sp.metrics.targetScrapePoolTargetLimit.WithLabelValues(sp.config.JobName).Set(float64(sp.config.TargetLimit))
190 return sp, nil
191}
192
193func (sp *scrapePool) newLoop(opts scrapeLoopOptions) loop {
194 if sp.injectTestNewLoop != nil {

Callers 15

reloadMethod · 0.85
testNewScrapePoolFunction · 0.85
testDroppedTargetsListFunction · 0.85
testScrapePoolRacesFunction · 0.85
testReuseScrapeCacheFunction · 0.85
testReuseCacheRaceFunction · 0.85
testScrapeReportLimitFunction · 0.85
testScrapeUTF8Function · 0.85
testLeQuantileReLabelFunction · 0.85
testTypeUnitReLabelFunction · 0.85

Calls 6

NewFunction · 0.92
ToEscapingSchemeFunction · 0.92
NewSymbolTableFunction · 0.92
newScrapeClientFunction · 0.85
SetMethod · 0.65

Tested by 15

testNewScrapePoolFunction · 0.68
testDroppedTargetsListFunction · 0.68
testScrapePoolRacesFunction · 0.68
testReuseScrapeCacheFunction · 0.68
testReuseCacheRaceFunction · 0.68
testScrapeReportLimitFunction · 0.68
testScrapeUTF8Function · 0.68
testLeQuantileReLabelFunction · 0.68
testTypeUnitReLabelFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…