github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/ingester/metrics_test.go (about)

     1  package ingester
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/prometheus/client_golang/prometheus"
     8  	"github.com/prometheus/client_golang/prometheus/promauto"
     9  	"github.com/prometheus/client_golang/prometheus/testutil"
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestTSDBMetrics(t *testing.T) {
    14  	mainReg := prometheus.NewPedanticRegistry()
    15  
    16  	tsdbMetrics := newTSDBMetrics(mainReg)
    17  
    18  	tsdbMetrics.setRegistryForUser("user1", populateTSDBMetrics(12345))
    19  	tsdbMetrics.setRegistryForUser("user2", populateTSDBMetrics(85787))
    20  	tsdbMetrics.setRegistryForUser("user3", populateTSDBMetrics(999))
    21  
    22  	err := testutil.GatherAndCompare(mainReg, bytes.NewBufferString(`
    23  			# HELP cortex_ingester_shipper_dir_syncs_total Total number of TSDB dir syncs
    24  			# TYPE cortex_ingester_shipper_dir_syncs_total counter
    25  			# 12345 + 85787 + 999
    26  			cortex_ingester_shipper_dir_syncs_total 99131
    27  
    28  			# HELP cortex_ingester_shipper_dir_sync_failures_total Total number of failed TSDB dir syncs
    29  			# TYPE cortex_ingester_shipper_dir_sync_failures_total counter
    30  			# 2*(12345 + 85787 + 999)
    31  			cortex_ingester_shipper_dir_sync_failures_total 198262
    32  
    33  			# HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks
    34  			# TYPE cortex_ingester_shipper_uploads_total counter
    35  			# 3*(12345 + 85787 + 999)
    36  			cortex_ingester_shipper_uploads_total 297393
    37  
    38  			# HELP cortex_ingester_shipper_upload_failures_total Total number of TSDB block upload failures
    39  			# TYPE cortex_ingester_shipper_upload_failures_total counter
    40  			# 4*(12345 + 85787 + 999)
    41  			cortex_ingester_shipper_upload_failures_total 396524
    42  
    43  			# HELP cortex_ingester_tsdb_compactions_total Total number of TSDB compactions that were executed.
    44  			# TYPE cortex_ingester_tsdb_compactions_total counter
    45  			cortex_ingester_tsdb_compactions_total 693917
    46  
    47  			# HELP cortex_ingester_tsdb_compaction_duration_seconds Duration of TSDB compaction runs.
    48  			# TYPE cortex_ingester_tsdb_compaction_duration_seconds histogram
    49  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="1"} 0
    50  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="2"} 0
    51  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="4"} 0
    52  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="8"} 0
    53  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="16"} 3
    54  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="32"} 3
    55  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="64"} 3
    56  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="128"} 3
    57  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="256"} 3
    58  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="512"} 3
    59  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="+Inf"} 3
    60  			cortex_ingester_tsdb_compaction_duration_seconds_sum 27
    61  			cortex_ingester_tsdb_compaction_duration_seconds_count 3
    62  
    63  			# HELP cortex_ingester_tsdb_wal_fsync_duration_seconds Duration of TSDB WAL fsync.
    64  			# TYPE cortex_ingester_tsdb_wal_fsync_duration_seconds summary
    65  			cortex_ingester_tsdb_wal_fsync_duration_seconds{quantile="0.5"} 30
    66  			cortex_ingester_tsdb_wal_fsync_duration_seconds{quantile="0.9"} 30
    67  			cortex_ingester_tsdb_wal_fsync_duration_seconds{quantile="0.99"} 30
    68  			cortex_ingester_tsdb_wal_fsync_duration_seconds_sum 30
    69  			cortex_ingester_tsdb_wal_fsync_duration_seconds_count 3
    70  
    71  			# HELP cortex_ingester_tsdb_wal_page_flushes_total Total number of TSDB WAL page flushes.
    72  			# TYPE cortex_ingester_tsdb_wal_page_flushes_total counter
    73  			cortex_ingester_tsdb_wal_page_flushes_total 1090441
    74  
    75  			# HELP cortex_ingester_tsdb_wal_completed_pages_total Total number of TSDB WAL completed pages.
    76  			# TYPE cortex_ingester_tsdb_wal_completed_pages_total counter
    77  			cortex_ingester_tsdb_wal_completed_pages_total 1189572
    78  
    79  			# HELP cortex_ingester_tsdb_wal_truncations_failed_total Total number of TSDB WAL truncations that failed.
    80  			# TYPE cortex_ingester_tsdb_wal_truncations_failed_total counter
    81  			cortex_ingester_tsdb_wal_truncations_failed_total 1288703
    82  
    83  			# HELP cortex_ingester_tsdb_wal_truncations_total Total number of TSDB  WAL truncations attempted.
    84  			# TYPE cortex_ingester_tsdb_wal_truncations_total counter
    85  			cortex_ingester_tsdb_wal_truncations_total 1387834
    86  
    87  			# HELP cortex_ingester_tsdb_wal_corruptions_total Total number of TSDB WAL corruptions.
    88  			# TYPE cortex_ingester_tsdb_wal_corruptions_total counter
    89  			cortex_ingester_tsdb_wal_corruptions_total 2.676537e+06
    90  
    91  			# HELP cortex_ingester_tsdb_wal_writes_failed_total Total number of TSDB WAL writes that failed.
    92  			# TYPE cortex_ingester_tsdb_wal_writes_failed_total counter
    93  			cortex_ingester_tsdb_wal_writes_failed_total 1486965
    94  
    95  			# HELP cortex_ingester_tsdb_head_truncations_failed_total Total number of TSDB head truncations that failed.
    96  			# TYPE cortex_ingester_tsdb_head_truncations_failed_total counter
    97  			cortex_ingester_tsdb_head_truncations_failed_total 2.775668e+06
    98  
    99  			# HELP cortex_ingester_tsdb_head_truncations_total Total number of TSDB head truncations attempted.
   100  			# TYPE cortex_ingester_tsdb_head_truncations_total counter
   101  			cortex_ingester_tsdb_head_truncations_total 2.874799e+06
   102  
   103  			# HELP cortex_ingester_tsdb_head_gc_duration_seconds Runtime of garbage collection in the TSDB head.
   104  			# TYPE cortex_ingester_tsdb_head_gc_duration_seconds summary
   105  			cortex_ingester_tsdb_head_gc_duration_seconds_sum 9
   106  			cortex_ingester_tsdb_head_gc_duration_seconds_count 3
   107  
   108  			# HELP cortex_ingester_tsdb_checkpoint_deletions_failed_total Total number of TSDB checkpoint deletions that failed.
   109  			# TYPE cortex_ingester_tsdb_checkpoint_deletions_failed_total counter
   110  			cortex_ingester_tsdb_checkpoint_deletions_failed_total 1586096
   111  
   112  			# HELP cortex_ingester_tsdb_checkpoint_deletions_total Total number of TSDB checkpoint deletions attempted.
   113  			# TYPE cortex_ingester_tsdb_checkpoint_deletions_total counter
   114  			cortex_ingester_tsdb_checkpoint_deletions_total 1685227
   115  
   116  			# HELP cortex_ingester_tsdb_checkpoint_creations_failed_total Total number of TSDB checkpoint creations that failed.
   117  			# TYPE cortex_ingester_tsdb_checkpoint_creations_failed_total counter
   118  			cortex_ingester_tsdb_checkpoint_creations_failed_total 1784358
   119  
   120  			# HELP cortex_ingester_tsdb_checkpoint_creations_total Total number of TSDB checkpoint creations attempted.
   121  			# TYPE cortex_ingester_tsdb_checkpoint_creations_total counter
   122  			cortex_ingester_tsdb_checkpoint_creations_total 1883489
   123  
   124  			# HELP cortex_ingester_memory_series_created_total The total number of series that were created per user.
   125  			# TYPE cortex_ingester_memory_series_created_total counter
   126  			# 5 * (12345, 85787 and 999 respectively)
   127  			cortex_ingester_memory_series_created_total{user="user1"} 61725
   128  			cortex_ingester_memory_series_created_total{user="user2"} 428935
   129  			cortex_ingester_memory_series_created_total{user="user3"} 4995
   130  
   131  			# HELP cortex_ingester_memory_series_removed_total The total number of series that were removed per user.
   132  			# TYPE cortex_ingester_memory_series_removed_total counter
   133  			# 6 * (12345, 85787 and 999 respectively)
   134  			cortex_ingester_memory_series_removed_total{user="user1"} 74070
   135  			cortex_ingester_memory_series_removed_total{user="user2"} 514722
   136  			cortex_ingester_memory_series_removed_total{user="user3"} 5994
   137  
   138  			# HELP cortex_ingester_tsdb_head_active_appenders Number of currently active TSDB appender transactions.
   139  			# TYPE cortex_ingester_tsdb_head_active_appenders gauge
   140  			cortex_ingester_tsdb_head_active_appenders 1982620
   141  
   142  			# HELP cortex_ingester_tsdb_head_series_not_found_total Total number of TSDB requests for series that were not found.
   143  			# TYPE cortex_ingester_tsdb_head_series_not_found_total counter
   144  			cortex_ingester_tsdb_head_series_not_found_total 2081751
   145  
   146  			# HELP cortex_ingester_tsdb_head_chunks Total number of chunks in the TSDB head block.
   147  			# TYPE cortex_ingester_tsdb_head_chunks gauge
   148  			cortex_ingester_tsdb_head_chunks 2180882
   149  
   150  			# HELP cortex_ingester_tsdb_head_chunks_created_total Total number of series created in the TSDB head.
   151  			# TYPE cortex_ingester_tsdb_head_chunks_created_total counter
   152  			cortex_ingester_tsdb_head_chunks_created_total{user="user1"} 283935
   153  			cortex_ingester_tsdb_head_chunks_created_total{user="user2"} 1973101
   154  			cortex_ingester_tsdb_head_chunks_created_total{user="user3"} 22977
   155  
   156  			# HELP cortex_ingester_tsdb_head_chunks_removed_total Total number of series removed in the TSDB head.
   157  			# TYPE cortex_ingester_tsdb_head_chunks_removed_total counter
   158  			cortex_ingester_tsdb_head_chunks_removed_total{user="user1"} 296280
   159  			cortex_ingester_tsdb_head_chunks_removed_total{user="user2"} 2058888
   160  			cortex_ingester_tsdb_head_chunks_removed_total{user="user3"} 23976
   161  
   162  			# HELP cortex_ingester_tsdb_wal_truncate_duration_seconds Duration of TSDB WAL truncation.
   163  			# TYPE cortex_ingester_tsdb_wal_truncate_duration_seconds summary
   164  			cortex_ingester_tsdb_wal_truncate_duration_seconds_sum 75
   165  			cortex_ingester_tsdb_wal_truncate_duration_seconds_count 3
   166  
   167  			# HELP cortex_ingester_tsdb_mmap_chunk_corruptions_total Total number of memory-mapped TSDB chunk corruptions.
   168  			# TYPE cortex_ingester_tsdb_mmap_chunk_corruptions_total counter
   169  			cortex_ingester_tsdb_mmap_chunk_corruptions_total 2577406
   170  
   171  			# HELP cortex_ingester_tsdb_blocks_loaded Number of currently loaded data blocks
   172  			# TYPE cortex_ingester_tsdb_blocks_loaded gauge
   173  			cortex_ingester_tsdb_blocks_loaded 15
   174  
   175  			# HELP cortex_ingester_tsdb_reloads_total Number of times the database reloaded block data from disk.
   176  			# TYPE cortex_ingester_tsdb_reloads_total counter
   177  			cortex_ingester_tsdb_reloads_total 30
   178  
   179  			# HELP cortex_ingester_tsdb_reloads_failures_total Number of times the database failed to reloadBlocks block data from disk.
   180  			# TYPE cortex_ingester_tsdb_reloads_failures_total counter
   181  			cortex_ingester_tsdb_reloads_failures_total 21
   182  
   183  			# HELP cortex_ingester_tsdb_symbol_table_size_bytes Size of symbol table in memory for loaded blocks
   184  			# TYPE cortex_ingester_tsdb_symbol_table_size_bytes gauge
   185  			cortex_ingester_tsdb_symbol_table_size_bytes{user="user1"} 12641280
   186  			cortex_ingester_tsdb_symbol_table_size_bytes{user="user2"} 87845888
   187  			cortex_ingester_tsdb_symbol_table_size_bytes{user="user3"} 1022976
   188  
   189  			# HELP cortex_ingester_tsdb_storage_blocks_bytes The number of bytes that are currently used for local storage by all blocks.
   190  			# TYPE cortex_ingester_tsdb_storage_blocks_bytes gauge
   191  			cortex_ingester_tsdb_storage_blocks_bytes{user="user1"} 50565120
   192  			cortex_ingester_tsdb_storage_blocks_bytes{user="user2"} 351383552
   193  			cortex_ingester_tsdb_storage_blocks_bytes{user="user3"} 4091904
   194  
   195  			# HELP cortex_ingester_tsdb_time_retentions_total The number of times that blocks were deleted because the maximum time limit was exceeded.
   196  			# TYPE cortex_ingester_tsdb_time_retentions_total counter
   197  			cortex_ingester_tsdb_time_retentions_total 33
   198  
   199  			# HELP cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds The timestamp of the oldest exemplar stored in circular storage. Useful to check for what time range the current exemplar buffer limit allows. This usually means the last timestamp for all exemplars for a typical setup. This is not true though if one of the series timestamp is in future compared to rest series.
   200  			# TYPE cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds gauge
   201  			cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds{user="user1"} 1234
   202  			cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds{user="user2"} 1234
   203  			cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds{user="user3"} 1234
   204  
   205  			# HELP cortex_ingester_tsdb_exemplar_out_of_order_exemplars_total Total number of out of order exemplar ingestion failed attempts.
   206  			# TYPE cortex_ingester_tsdb_exemplar_out_of_order_exemplars_total counter
   207  			cortex_ingester_tsdb_exemplar_out_of_order_exemplars_total 9
   208  			
   209  			# HELP cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage Number of TSDB series with exemplars currently in storage.
   210  			# TYPE cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage gauge
   211  			cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage{user="user1"} 1
   212  			cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage{user="user2"} 1
   213  			cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage{user="user3"} 1
   214  
   215  			# HELP cortex_ingester_tsdb_exemplar_exemplars_appended_total Total number of TSDB exemplars appended.
   216  			# TYPE cortex_ingester_tsdb_exemplar_exemplars_appended_total counter
   217  			cortex_ingester_tsdb_exemplar_exemplars_appended_total 300
   218  
   219  			# HELP cortex_ingester_tsdb_exemplar_exemplars_in_storage Number of TSDB exemplars currently in storage.
   220  			# TYPE cortex_ingester_tsdb_exemplar_exemplars_in_storage gauge
   221  			cortex_ingester_tsdb_exemplar_exemplars_in_storage 30
   222  	`))
   223  	require.NoError(t, err)
   224  }
   225  
   226  func TestTSDBMetricsWithRemoval(t *testing.T) {
   227  	mainReg := prometheus.NewPedanticRegistry()
   228  
   229  	tsdbMetrics := newTSDBMetrics(mainReg)
   230  
   231  	tsdbMetrics.setRegistryForUser("user1", populateTSDBMetrics(12345))
   232  	tsdbMetrics.setRegistryForUser("user2", populateTSDBMetrics(85787))
   233  	tsdbMetrics.setRegistryForUser("user3", populateTSDBMetrics(999))
   234  	tsdbMetrics.removeRegistryForUser("user3")
   235  
   236  	err := testutil.GatherAndCompare(mainReg, bytes.NewBufferString(`
   237  			# HELP cortex_ingester_shipper_dir_syncs_total Total number of TSDB dir syncs
   238  			# TYPE cortex_ingester_shipper_dir_syncs_total counter
   239  			# 12345 + 85787 + 999
   240  			cortex_ingester_shipper_dir_syncs_total 99131
   241  
   242  			# HELP cortex_ingester_shipper_dir_sync_failures_total Total number of failed TSDB dir syncs
   243  			# TYPE cortex_ingester_shipper_dir_sync_failures_total counter
   244  			# 2*(12345 + 85787 + 999)
   245  			cortex_ingester_shipper_dir_sync_failures_total 198262
   246  
   247  			# HELP cortex_ingester_shipper_uploads_total Total number of uploaded TSDB blocks
   248  			# TYPE cortex_ingester_shipper_uploads_total counter
   249  			# 3*(12345 + 85787 + 999)
   250  			cortex_ingester_shipper_uploads_total 297393
   251  
   252  			# HELP cortex_ingester_shipper_upload_failures_total Total number of TSDB block upload failures
   253  			# TYPE cortex_ingester_shipper_upload_failures_total counter
   254  			# 4*(12345 + 85787 + 999)
   255  			cortex_ingester_shipper_upload_failures_total 396524
   256  
   257  			# HELP cortex_ingester_tsdb_compactions_total Total number of TSDB compactions that were executed.
   258  			# TYPE cortex_ingester_tsdb_compactions_total counter
   259  			cortex_ingester_tsdb_compactions_total 693917
   260  
   261  			# HELP cortex_ingester_tsdb_compaction_duration_seconds Duration of TSDB compaction runs.
   262  			# TYPE cortex_ingester_tsdb_compaction_duration_seconds histogram
   263  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="1"} 0
   264  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="2"} 0
   265  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="4"} 0
   266  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="8"} 0
   267  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="16"} 3
   268  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="32"} 3
   269  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="64"} 3
   270  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="128"} 3
   271  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="256"} 3
   272  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="512"} 3
   273  			cortex_ingester_tsdb_compaction_duration_seconds_bucket{le="+Inf"} 3
   274  			cortex_ingester_tsdb_compaction_duration_seconds_sum 27
   275  			cortex_ingester_tsdb_compaction_duration_seconds_count 3
   276  
   277  			# HELP cortex_ingester_tsdb_wal_fsync_duration_seconds Duration of TSDB WAL fsync.
   278  			# TYPE cortex_ingester_tsdb_wal_fsync_duration_seconds summary
   279  			cortex_ingester_tsdb_wal_fsync_duration_seconds{quantile="0.5"} 30
   280  			cortex_ingester_tsdb_wal_fsync_duration_seconds{quantile="0.9"} 30
   281  			cortex_ingester_tsdb_wal_fsync_duration_seconds{quantile="0.99"} 30
   282  			cortex_ingester_tsdb_wal_fsync_duration_seconds_sum 30
   283  			cortex_ingester_tsdb_wal_fsync_duration_seconds_count 3
   284  
   285  			# HELP cortex_ingester_tsdb_wal_page_flushes_total Total number of TSDB WAL page flushes.
   286  			# TYPE cortex_ingester_tsdb_wal_page_flushes_total counter
   287  			cortex_ingester_tsdb_wal_page_flushes_total 1090441
   288  
   289  			# HELP cortex_ingester_tsdb_wal_completed_pages_total Total number of TSDB WAL completed pages.
   290  			# TYPE cortex_ingester_tsdb_wal_completed_pages_total counter
   291  			cortex_ingester_tsdb_wal_completed_pages_total 1189572
   292  
   293  			# HELP cortex_ingester_tsdb_wal_truncations_failed_total Total number of TSDB WAL truncations that failed.
   294  			# TYPE cortex_ingester_tsdb_wal_truncations_failed_total counter
   295  			cortex_ingester_tsdb_wal_truncations_failed_total 1288703
   296  
   297  			# HELP cortex_ingester_tsdb_wal_truncations_total Total number of TSDB  WAL truncations attempted.
   298  			# TYPE cortex_ingester_tsdb_wal_truncations_total counter
   299  			cortex_ingester_tsdb_wal_truncations_total 1387834
   300  
   301  			# HELP cortex_ingester_tsdb_wal_corruptions_total Total number of TSDB WAL corruptions.
   302  			# TYPE cortex_ingester_tsdb_wal_corruptions_total counter
   303  			cortex_ingester_tsdb_wal_corruptions_total 2.676537e+06
   304  
   305  			# HELP cortex_ingester_tsdb_wal_writes_failed_total Total number of TSDB WAL writes that failed.
   306  			# TYPE cortex_ingester_tsdb_wal_writes_failed_total counter
   307  			cortex_ingester_tsdb_wal_writes_failed_total 1486965
   308  
   309  			# HELP cortex_ingester_tsdb_head_truncations_failed_total Total number of TSDB head truncations that failed.
   310  			# TYPE cortex_ingester_tsdb_head_truncations_failed_total counter
   311  			cortex_ingester_tsdb_head_truncations_failed_total 2.775668e+06
   312  
   313  			# HELP cortex_ingester_tsdb_head_truncations_total Total number of TSDB head truncations attempted.
   314  			# TYPE cortex_ingester_tsdb_head_truncations_total counter
   315  			cortex_ingester_tsdb_head_truncations_total 2.874799e+06
   316  
   317  			# HELP cortex_ingester_tsdb_head_gc_duration_seconds Runtime of garbage collection in the TSDB head.
   318  			# TYPE cortex_ingester_tsdb_head_gc_duration_seconds summary
   319  			cortex_ingester_tsdb_head_gc_duration_seconds_sum 9
   320  			cortex_ingester_tsdb_head_gc_duration_seconds_count 3
   321  
   322  			# HELP cortex_ingester_tsdb_checkpoint_deletions_failed_total Total number of TSDB checkpoint deletions that failed.
   323  			# TYPE cortex_ingester_tsdb_checkpoint_deletions_failed_total counter
   324  			cortex_ingester_tsdb_checkpoint_deletions_failed_total 1586096
   325  
   326  			# HELP cortex_ingester_tsdb_checkpoint_deletions_total Total number of TSDB checkpoint deletions attempted.
   327  			# TYPE cortex_ingester_tsdb_checkpoint_deletions_total counter
   328  			cortex_ingester_tsdb_checkpoint_deletions_total 1685227
   329  
   330  			# HELP cortex_ingester_tsdb_checkpoint_creations_failed_total Total number of TSDB checkpoint creations that failed.
   331  			# TYPE cortex_ingester_tsdb_checkpoint_creations_failed_total counter
   332  			cortex_ingester_tsdb_checkpoint_creations_failed_total 1784358
   333  
   334  			# HELP cortex_ingester_tsdb_checkpoint_creations_total Total number of TSDB checkpoint creations attempted.
   335  			# TYPE cortex_ingester_tsdb_checkpoint_creations_total counter
   336  			cortex_ingester_tsdb_checkpoint_creations_total 1883489
   337  
   338  			# HELP cortex_ingester_memory_series_created_total The total number of series that were created per user.
   339  			# TYPE cortex_ingester_memory_series_created_total counter
   340  			# 5 * (12345, 85787 and 999 respectively)
   341  			cortex_ingester_memory_series_created_total{user="user1"} 61725
   342  			cortex_ingester_memory_series_created_total{user="user2"} 428935
   343  
   344  			# HELP cortex_ingester_memory_series_removed_total The total number of series that were removed per user.
   345  			# TYPE cortex_ingester_memory_series_removed_total counter
   346  			# 6 * (12345, 85787 and 999 respectively)
   347  			cortex_ingester_memory_series_removed_total{user="user1"} 74070
   348  			cortex_ingester_memory_series_removed_total{user="user2"} 514722
   349  
   350  			# HELP cortex_ingester_tsdb_head_active_appenders Number of currently active TSDB appender transactions.
   351  			# TYPE cortex_ingester_tsdb_head_active_appenders gauge
   352  			cortex_ingester_tsdb_head_active_appenders 1962640
   353  
   354  			# HELP cortex_ingester_tsdb_head_series_not_found_total Total number of TSDB requests for series that were not found.
   355  			# TYPE cortex_ingester_tsdb_head_series_not_found_total counter
   356  			cortex_ingester_tsdb_head_series_not_found_total 2081751
   357  
   358  			# HELP cortex_ingester_tsdb_head_chunks Total number of chunks in the TSDB head block.
   359  			# TYPE cortex_ingester_tsdb_head_chunks gauge
   360  			cortex_ingester_tsdb_head_chunks 2158904
   361  
   362  			# HELP cortex_ingester_tsdb_head_chunks_created_total Total number of series created in the TSDB head.
   363  			# TYPE cortex_ingester_tsdb_head_chunks_created_total counter
   364  			cortex_ingester_tsdb_head_chunks_created_total{user="user1"} 283935
   365  			cortex_ingester_tsdb_head_chunks_created_total{user="user2"} 1973101
   366  
   367  			# HELP cortex_ingester_tsdb_head_chunks_removed_total Total number of series removed in the TSDB head.
   368  			# TYPE cortex_ingester_tsdb_head_chunks_removed_total counter
   369  			cortex_ingester_tsdb_head_chunks_removed_total{user="user1"} 296280
   370  			cortex_ingester_tsdb_head_chunks_removed_total{user="user2"} 2058888
   371  
   372  			# HELP cortex_ingester_tsdb_wal_truncate_duration_seconds Duration of TSDB WAL truncation.
   373  			# TYPE cortex_ingester_tsdb_wal_truncate_duration_seconds summary
   374  			cortex_ingester_tsdb_wal_truncate_duration_seconds_sum 75
   375  			cortex_ingester_tsdb_wal_truncate_duration_seconds_count 3
   376  
   377  			# HELP cortex_ingester_tsdb_mmap_chunk_corruptions_total Total number of memory-mapped TSDB chunk corruptions.
   378  			# TYPE cortex_ingester_tsdb_mmap_chunk_corruptions_total counter
   379  			cortex_ingester_tsdb_mmap_chunk_corruptions_total 2577406
   380  
   381  			# HELP cortex_ingester_tsdb_blocks_loaded Number of currently loaded data blocks
   382  			# TYPE cortex_ingester_tsdb_blocks_loaded gauge
   383  			cortex_ingester_tsdb_blocks_loaded 10
   384  
   385  			# HELP cortex_ingester_tsdb_reloads_total Number of times the database reloaded block data from disk.
   386  			# TYPE cortex_ingester_tsdb_reloads_total counter
   387  			cortex_ingester_tsdb_reloads_total 30
   388  
   389  			# HELP cortex_ingester_tsdb_reloads_failures_total Number of times the database failed to reloadBlocks block data from disk.
   390  			# TYPE cortex_ingester_tsdb_reloads_failures_total counter
   391  			cortex_ingester_tsdb_reloads_failures_total 21
   392  
   393  			# HELP cortex_ingester_tsdb_symbol_table_size_bytes Size of symbol table in memory for loaded blocks
   394  			# TYPE cortex_ingester_tsdb_symbol_table_size_bytes gauge
   395  			cortex_ingester_tsdb_symbol_table_size_bytes{user="user1"} 12641280
   396  			cortex_ingester_tsdb_symbol_table_size_bytes{user="user2"} 87845888
   397  
   398  			# HELP cortex_ingester_tsdb_storage_blocks_bytes The number of bytes that are currently used for local storage by all blocks.
   399  			# TYPE cortex_ingester_tsdb_storage_blocks_bytes gauge
   400  			cortex_ingester_tsdb_storage_blocks_bytes{user="user1"} 50565120
   401  			cortex_ingester_tsdb_storage_blocks_bytes{user="user2"} 351383552
   402  
   403  			# HELP cortex_ingester_tsdb_time_retentions_total The number of times that blocks were deleted because the maximum time limit was exceeded.
   404  			# TYPE cortex_ingester_tsdb_time_retentions_total counter
   405  			cortex_ingester_tsdb_time_retentions_total 33
   406  
   407  			# HELP cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds The timestamp of the oldest exemplar stored in circular storage. Useful to check for what time range the current exemplar buffer limit allows. This usually means the last timestamp for all exemplars for a typical setup. This is not true though if one of the series timestamp is in future compared to rest series.
   408  			# TYPE cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds gauge
   409  			cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds{user="user1"} 1234
   410  			cortex_ingester_tsdb_exemplar_last_exemplars_timestamp_seconds{user="user2"} 1234
   411  
   412  			# HELP cortex_ingester_tsdb_exemplar_out_of_order_exemplars_total Total number of out of order exemplar ingestion failed attempts.
   413  			# TYPE cortex_ingester_tsdb_exemplar_out_of_order_exemplars_total counter
   414  			cortex_ingester_tsdb_exemplar_out_of_order_exemplars_total 9
   415  			
   416  			# HELP cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage Number of TSDB series with exemplars currently in storage.
   417  			# TYPE cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage gauge
   418  			cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage{user="user1"} 1
   419  			cortex_ingester_tsdb_exemplar_series_with_exemplars_in_storage{user="user2"} 1
   420  
   421  			# HELP cortex_ingester_tsdb_exemplar_exemplars_appended_total Total number of TSDB exemplars appended.
   422  			# TYPE cortex_ingester_tsdb_exemplar_exemplars_appended_total counter
   423  			cortex_ingester_tsdb_exemplar_exemplars_appended_total 300
   424  
   425  			# HELP cortex_ingester_tsdb_exemplar_exemplars_in_storage Number of TSDB exemplars currently in storage.
   426  			# TYPE cortex_ingester_tsdb_exemplar_exemplars_in_storage gauge
   427  			cortex_ingester_tsdb_exemplar_exemplars_in_storage 20
   428  	`))
   429  	require.NoError(t, err)
   430  }
   431  
   432  func populateTSDBMetrics(base float64) *prometheus.Registry {
   433  	r := prometheus.NewRegistry()
   434  
   435  	// Thanos shipper.
   436  	dirSyncs := promauto.With(r).NewCounter(prometheus.CounterOpts{
   437  		Name: "thanos_shipper_dir_syncs_total",
   438  		Help: "Total number of dir syncs",
   439  	})
   440  	dirSyncs.Add(1 * base)
   441  
   442  	dirSyncFailures := promauto.With(r).NewCounter(prometheus.CounterOpts{
   443  		Name: "thanos_shipper_dir_sync_failures_total",
   444  		Help: "Total number of failed dir syncs",
   445  	})
   446  	dirSyncFailures.Add(2 * base)
   447  
   448  	uploads := promauto.With(r).NewCounter(prometheus.CounterOpts{
   449  		Name: "thanos_shipper_uploads_total",
   450  		Help: "Total number of uploaded blocks",
   451  	})
   452  	uploads.Add(3 * base)
   453  
   454  	uploadFailures := promauto.With(r).NewCounter(prometheus.CounterOpts{
   455  		Name: "thanos_shipper_upload_failures_total",
   456  		Help: "Total number of block upload failures",
   457  	})
   458  	uploadFailures.Add(4 * base)
   459  
   460  	// TSDB Head
   461  	seriesCreated := promauto.With(r).NewCounter(prometheus.CounterOpts{
   462  		Name: "prometheus_tsdb_head_series_created_total",
   463  	})
   464  	seriesCreated.Add(5 * base)
   465  
   466  	seriesRemoved := promauto.With(r).NewCounter(prometheus.CounterOpts{
   467  		Name: "prometheus_tsdb_head_series_removed_total",
   468  	})
   469  	seriesRemoved.Add(6 * base)
   470  
   471  	ran := promauto.With(r).NewCounter(prometheus.CounterOpts{
   472  		Name: "prometheus_tsdb_compactions_total",
   473  		Help: "Total number of compactions that were executed for the partition.",
   474  	})
   475  	ran.Add(7 * base)
   476  
   477  	duration := promauto.With(r).NewHistogram(prometheus.HistogramOpts{
   478  		Name:    "prometheus_tsdb_compaction_duration_seconds",
   479  		Help:    "Duration of compaction runs",
   480  		Buckets: prometheus.ExponentialBuckets(1, 2, 10),
   481  	})
   482  	duration.Observe(9)
   483  
   484  	fsyncDuration := promauto.With(r).NewSummary(prometheus.SummaryOpts{
   485  		Name:       "prometheus_tsdb_wal_fsync_duration_seconds",
   486  		Help:       "Duration of WAL fsync.",
   487  		Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
   488  	})
   489  	fsyncDuration.Observe(10)
   490  
   491  	pageFlushes := promauto.With(r).NewCounter(prometheus.CounterOpts{
   492  		Name: "prometheus_tsdb_wal_page_flushes_total",
   493  		Help: "Total number of page flushes.",
   494  	})
   495  	pageFlushes.Add(11 * base)
   496  
   497  	pageCompletions := promauto.With(r).NewCounter(prometheus.CounterOpts{
   498  		Name: "prometheus_tsdb_wal_completed_pages_total",
   499  		Help: "Total number of completed pages.",
   500  	})
   501  	pageCompletions.Add(12 * base)
   502  
   503  	truncateFail := promauto.With(r).NewCounter(prometheus.CounterOpts{
   504  		Name: "prometheus_tsdb_wal_truncations_failed_total",
   505  		Help: "Total number of WAL truncations that failed.",
   506  	})
   507  	truncateFail.Add(13 * base)
   508  
   509  	truncateTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   510  		Name: "prometheus_tsdb_wal_truncations_total",
   511  		Help: "Total number of WAL truncations attempted.",
   512  	})
   513  	truncateTotal.Add(14 * base)
   514  
   515  	writesFailed := promauto.With(r).NewCounter(prometheus.CounterOpts{
   516  		Name: "prometheus_tsdb_wal_writes_failed_total",
   517  		Help: "Total number of WAL writes that failed.",
   518  	})
   519  	writesFailed.Add(15 * base)
   520  
   521  	checkpointDeleteFail := promauto.With(r).NewCounter(prometheus.CounterOpts{
   522  		Name: "prometheus_tsdb_checkpoint_deletions_failed_total",
   523  		Help: "Total number of checkpoint deletions that failed.",
   524  	})
   525  	checkpointDeleteFail.Add(16 * base)
   526  
   527  	checkpointDeleteTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   528  		Name: "prometheus_tsdb_checkpoint_deletions_total",
   529  		Help: "Total number of checkpoint deletions attempted.",
   530  	})
   531  	checkpointDeleteTotal.Add(17 * base)
   532  
   533  	checkpointCreationFail := promauto.With(r).NewCounter(prometheus.CounterOpts{
   534  		Name: "prometheus_tsdb_checkpoint_creations_failed_total",
   535  		Help: "Total number of checkpoint creations that failed.",
   536  	})
   537  	checkpointCreationFail.Add(18 * base)
   538  
   539  	checkpointCreationTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   540  		Name: "prometheus_tsdb_checkpoint_creations_total",
   541  		Help: "Total number of checkpoint creations attempted.",
   542  	})
   543  	checkpointCreationTotal.Add(19 * base)
   544  
   545  	activeAppenders := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   546  		Name: "prometheus_tsdb_head_active_appenders",
   547  		Help: "Number of currently active appender transactions",
   548  	})
   549  	activeAppenders.Set(20 * base)
   550  
   551  	seriesNotFound := promauto.With(r).NewCounter(prometheus.CounterOpts{
   552  		Name: "prometheus_tsdb_head_series_not_found_total",
   553  		Help: "Total number of requests for series that were not found.",
   554  	})
   555  	seriesNotFound.Add(21 * base)
   556  
   557  	chunks := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   558  		Name: "prometheus_tsdb_head_chunks",
   559  		Help: "Total number of chunks in the head block.",
   560  	})
   561  	chunks.Set(22 * base)
   562  
   563  	chunksCreated := promauto.With(r).NewCounter(prometheus.CounterOpts{
   564  		Name: "prometheus_tsdb_head_chunks_created_total",
   565  		Help: "Total number of chunks created in the head",
   566  	})
   567  	chunksCreated.Add(23 * base)
   568  
   569  	chunksRemoved := promauto.With(r).NewCounter(prometheus.CounterOpts{
   570  		Name: "prometheus_tsdb_head_chunks_removed_total",
   571  		Help: "Total number of chunks removed in the head",
   572  	})
   573  	chunksRemoved.Add(24 * base)
   574  
   575  	walTruncateDuration := promauto.With(r).NewSummary(prometheus.SummaryOpts{
   576  		Name: "prometheus_tsdb_wal_truncate_duration_seconds",
   577  		Help: "Duration of WAL truncation.",
   578  	})
   579  	walTruncateDuration.Observe(25)
   580  
   581  	mmapChunkCorruptionTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   582  		Name: "prometheus_tsdb_mmap_chunk_corruptions_total",
   583  		Help: "Total number of memory-mapped chunk corruptions.",
   584  	})
   585  	mmapChunkCorruptionTotal.Add(26 * base)
   586  
   587  	walCorruptionsTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   588  		Name: "prometheus_tsdb_wal_corruptions_total",
   589  		Help: "Total number of WAL corruptions.",
   590  	})
   591  	walCorruptionsTotal.Add(27 * base)
   592  
   593  	headTruncateFail := promauto.With(r).NewCounter(prometheus.CounterOpts{
   594  		Name: "prometheus_tsdb_head_truncations_failed_total",
   595  		Help: "Total number of head truncations that failed.",
   596  	})
   597  	headTruncateFail.Add(28 * base)
   598  
   599  	headTruncateTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   600  		Name: "prometheus_tsdb_head_truncations_total",
   601  		Help: "Total number of head truncations attempted.",
   602  	})
   603  	headTruncateTotal.Add(29 * base)
   604  
   605  	gcDuration := promauto.With(r).NewSummary(prometheus.SummaryOpts{
   606  		Name: "prometheus_tsdb_head_gc_duration_seconds",
   607  		Help: "Runtime of garbage collection in the head block.",
   608  	})
   609  	gcDuration.Observe(3)
   610  
   611  	loadedBlocks := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   612  		Name: "prometheus_tsdb_blocks_loaded",
   613  		Help: "Number of currently loaded data blocks",
   614  	})
   615  	loadedBlocks.Set(5)
   616  
   617  	reloadsTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   618  		Name: "prometheus_tsdb_reloads_total",
   619  		Help: "Number of times the database reloaded block data from disk.",
   620  	})
   621  	reloadsTotal.Add(10)
   622  
   623  	reloadsFailed := promauto.With(r).NewCounter(prometheus.CounterOpts{
   624  		Name: "prometheus_tsdb_reloads_failures_total",
   625  		Help: "Number of times the database failed to reloadBlocks block data from disk.",
   626  	})
   627  	reloadsFailed.Add(7)
   628  
   629  	symbolTableSize := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   630  		Name: "prometheus_tsdb_symbol_table_size_bytes",
   631  		Help: "Size of symbol table in memory for loaded blocks",
   632  	})
   633  	symbolTableSize.Set(1024 * base)
   634  
   635  	blocksSize := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   636  		Name: "prometheus_tsdb_storage_blocks_bytes",
   637  		Help: "The number of bytes that are currently used for local storage by all blocks.",
   638  	})
   639  	blocksSize.Set(4096 * base)
   640  
   641  	retentionsTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   642  		Name: "prometheus_tsdb_time_retentions_total",
   643  		Help: "The number of times that blocks were deleted because the maximum time limit was exceeded.",
   644  	})
   645  	retentionsTotal.Add(11)
   646  
   647  	exemplarsAppendedTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   648  		Name: "prometheus_tsdb_exemplar_exemplars_appended_total",
   649  		Help: "Total number of appended exemplars.",
   650  	})
   651  	exemplarsAppendedTotal.Add(100)
   652  
   653  	exemplarsStored := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   654  		Name: "prometheus_tsdb_exemplar_exemplars_in_storage",
   655  		Help: "Number of exemplars currently in circular storage.",
   656  	})
   657  	exemplarsStored.Set(10)
   658  
   659  	exemplarsSeriesStored := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   660  		Name: "prometheus_tsdb_exemplar_series_with_exemplars_in_storage",
   661  		Help: "Number of series with exemplars currently in circular storage.",
   662  	})
   663  	exemplarsSeriesStored.Set(1)
   664  
   665  	exemplarsLastTs := promauto.With(r).NewGauge(prometheus.GaugeOpts{
   666  		Name: "prometheus_tsdb_exemplar_last_exemplars_timestamp_seconds",
   667  		Help: "The timestamp of the oldest exemplar stored in circular storage. Useful to check for what time" +
   668  			"range the current exemplar buffer limit allows. This usually means the last timestamp" +
   669  			"for all exemplars for a typical setup. This is not true though if one of the series timestamp is in future compared to rest series.",
   670  	})
   671  	exemplarsLastTs.Set(1234)
   672  
   673  	exemplarsOutOfOrderTotal := promauto.With(r).NewCounter(prometheus.CounterOpts{
   674  		Name: "prometheus_tsdb_exemplar_out_of_order_exemplars_total",
   675  		Help: "Total number of out of order exemplar ingestion failed attempts.",
   676  	})
   677  	exemplarsOutOfOrderTotal.Add(3)
   678  
   679  	return r
   680  }