MCPcopy Index your code
hub / github.com/cortexproject/cortex / createTSDB

Method createTSDB

pkg/ingester/ingester.go:2847–2978  ·  view source on GitHub ↗

createTSDB creates a TSDB for a given userID, and returns the created db.

(userID string)

Source from the content-addressed store, hash-verified

2845
2846// createTSDB creates a TSDB for a given userID, and returns the created db.
2847func (i *Ingester) createTSDB(userID string) (*userTSDB, error) {
2848 tsdbPromReg := prometheus.NewRegistry()
2849 udir := i.cfg.BlocksStorageConfig.TSDB.BlocksDir(userID)
2850 userLogger := logutil.WithUserID(userID, i.logger)
2851
2852 blockRanges := i.cfg.BlocksStorageConfig.TSDB.BlockRanges.ToMilliseconds()
2853
2854 var postingCache cortex_tsdb.ExpandedPostingsCache
2855 if i.expandedPostingsCacheFactory != nil {
2856 postingCache = i.expandedPostingsCacheFactory.NewExpandedPostingsCache(userID, i.metrics.expandedPostingsCacheMetrics)
2857 }
2858
2859 var activeQueriedSeries *ActiveQueriedSeries
2860 if i.cfg.ActiveQueriedSeriesMetricsEnabled {
2861 activeQueriedSeries = NewActiveQueriedSeries(
2862 i.cfg.ActiveQueriedSeriesMetricsWindows,
2863 i.cfg.ActiveQueriedSeriesMetricsWindowDuration,
2864 i.cfg.ActiveQueriedSeriesMetricsSampleRate,
2865 i.logger,
2866 )
2867 }
2868
2869 userDB := &userTSDB{
2870 userID: userID,
2871 activeSeries: NewActiveSeries(),
2872 activeQueriedSeries: activeQueriedSeries,
2873 seriesInMetric: newMetricCounter(i.limiter, i.cfg.getIgnoreSeriesLimitForMetricNamesMap()),
2874 labelSetCounter: newLabelSetCounter(i.limiter),
2875 ingestedAPISamples: util_math.NewEWMARate(0.2, i.cfg.RateUpdatePeriod),
2876 ingestedRuleSamples: util_math.NewEWMARate(0.2, i.cfg.RateUpdatePeriod),
2877
2878 instanceLimitsFn: i.getInstanceLimits,
2879 instanceSeriesCount: &i.TSDBState.seriesCount,
2880 interner: util.NewLruInterner(i.cfg.LabelsStringInterningEnabled),
2881 labelsStringInterningEnabled: i.cfg.LabelsStringInterningEnabled,
2882
2883 blockRetentionPeriod: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
2884 postingCache: postingCache,
2885 }
2886
2887 enableExemplars := false
2888 maxExemplarsForUser := i.getMaxExemplars(userID)
2889 if maxExemplarsForUser > 0 {
2890 enableExemplars = true
2891 }
2892 oooTimeWindow := i.limits.OutOfOrderTimeWindow(userID)
2893
2894 walCompressType := compression.None
2895 if i.cfg.BlocksStorageConfig.TSDB.WALCompressionType != "" {
2896 walCompressType = i.cfg.BlocksStorageConfig.TSDB.WALCompressionType
2897 }
2898
2899 // Create a new user database
2900 db, err := tsdb.Open(udir, logutil.GoKitLogToSlog(userLogger), tsdbPromReg, &tsdb.Options{
2901 RetentionDuration: i.cfg.BlocksStorageConfig.TSDB.Retention.Milliseconds(),
2902 MinBlockDuration: blockRanges[0],
2903 MaxBlockDuration: blockRanges[len(blockRanges)-1],
2904 NoLockfile: true,

Callers 2

getOrCreateTSDBMethod · 0.95
openExistingTSDBMethod · 0.95

Implementers 1

Ingesterpkg/ingester/ingester.go

Calls 15

getMaxExemplarsMethod · 0.95
blockChunkQuerierFuncMethod · 0.95
setLastUpdateMethod · 0.95
NewLruInternerFunction · 0.92
TimeFromMillisFunction · 0.92
NewUserBucketClientFunction · 0.92
NewActiveQueriedSeriesFunction · 0.85
NewActiveSeriesFunction · 0.85
newMetricCounterFunction · 0.85
newLabelSetCounterFunction · 0.85
BlocksDirMethod · 0.80

Tested by

no test coverage detected