MCPcopy
hub / github.com/prometheus/prometheus / Open

Function Open

tsdb/agent/db.go:291–369  ·  view source on GitHub ↗

Open returns a new agent.DB in the given directory.

(l *slog.Logger, reg prometheus.Registerer, rs *remote.Storage, dir string, opts *Options)

Source from the content-addressed store, hash-verified

289
290// Open returns a new agent.DB in the given directory.
291func Open(l *slog.Logger, reg prometheus.Registerer, rs *remote.Storage, dir string, opts *Options) (*DB, error) {
292 opts = validateOptions(opts)
293
294 locker, err := tsdbutil.NewDirLocker(dir, "agent", l, reg)
295 if err != nil {
296 return nil, err
297 }
298 if !opts.NoLockfile {
299 if err := locker.Lock(); err != nil {
300 return nil, err
301 }
302 }
303
304 // remote_write expects WAL to be stored in a "wal" subdirectory of the main storage.
305 dir = filepath.Join(dir, "wal")
306
307 w, err := wlog.NewSize(l, reg, dir, opts.WALSegmentSize, opts.WALCompression)
308 if err != nil {
309 return nil, fmt.Errorf("creating WAL: %w", err)
310 }
311
312 db := &DB{
313 logger: l,
314 opts: opts,
315 rs: rs,
316
317 wal: w,
318 locker: locker,
319
320 nextRef: atomic.NewUint64(0),
321 series: newStripeSeries(opts.StripeSize),
322 deleted: make(map[chunks.HeadSeriesRef]deletedRefMeta),
323
324 donec: make(chan struct{}),
325 stopc: make(chan struct{}),
326
327 metrics: newDBMetrics(reg),
328 }
329
330 db.bufPool.New = func() any {
331 return make([]byte, 0, 1024)
332 }
333
334 db.appenderPool.New = func() any {
335 return &appender{
336 appenderBase: appenderBase{
337 DB: db,
338 pendingSeries: make([]record.RefSeries, 0, 100),
339 pendingSamples: make([]record.RefSample, 0, 100),
340 pendingHistograms: make([]record.RefHistogramSample, 0, 100),
341 pendingFloatHistograms: make([]record.RefFloatHistogramSample, 0, 100),
342 pendingExamplars: make([]record.RefExemplar, 0, 10),
343 },
344 }
345 }
346 db.appenderV2Pool.New = func() any {
347 return &appenderV2{
348 appenderBase: appenderBase{

Callers 12

mainFunction · 0.92
createTestAgentDBFunction · 0.70
TestWALReplayFunction · 0.70
TestLockfileFunction · 0.70
Test_ExistingWAL_NextRefFunction · 0.70
TestDBAllowOOOSamplesFunction · 0.70
benchCheckpointFunction · 0.70
TestWALReplay_AppendV2Function · 0.70

Calls 9

LockMethod · 0.95
replayWALMethod · 0.95
runMethod · 0.95
NewDirLockerFunction · 0.92
NewSizeFunction · 0.92
validateOptionsFunction · 0.85
RepairMethod · 0.80
newStripeSeriesFunction · 0.70
newDBMetricsFunction · 0.70

Tested by 11

createTestAgentDBFunction · 0.56
TestWALReplayFunction · 0.56
TestLockfileFunction · 0.56
Test_ExistingWAL_NextRefFunction · 0.56
TestDBAllowOOOSamplesFunction · 0.56
benchCheckpointFunction · 0.56
TestWALReplay_AppendV2Function · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…