Skip to main content

metrics_test.go

metrics_test.go - Overview

This file contains tests for verifying the metrics functionality in BadgerDB. It checks if the metrics related to writes, reads, vlog, and compaction are being tracked correctly.

Detailed Documentation

clearAllMetrics

  • Purpose: Resets all exported metrics variables to their zero values. It iterates through all the exported variables and resets them based on their type.
  • Parameters: None
  • Returns: None

TestWriteMetrics

  • Purpose: Tests the write metrics of BadgerDB. It writes a number of entries to the database and verifies that the corresponding metrics (badger_write_bytes_user, badger_put_num_user, badger_write_bytes_l0, badger_write_bytes_compaction) are updated correctly. It also forces a compaction and checks the badger_write_bytes_compaction metric after compaction.
  • Parameters:
    • t (*testing.T): Testing object for running the test.
  • Returns: None

TestVlogMetrics

  • Purpose: Tests the vlog related metrics of BadgerDB. It writes large values to the database, forcing them to be stored in the value log. It then verifies that the badger_write_num_vlog and badger_write_bytes_vlog metrics are updated correctly. It also reads a value from the value log and verifies that the badger_read_num_vlog and badger_read_bytes_vlog metrics are updated correctly.
  • Parameters:
    • t (*testing.T): Testing object for running the test.
  • Returns: None

TestReadMetrics

  • Purpose: Tests the read metrics of BadgerDB. It writes a number of entries to the database, then reads some of them. It verifies that the corresponding metrics (badger_get_num_user, badger_get_num_memtable, badger_get_num_lsm, badger_hit_num_lsm_bloom_filter, badger_read_bytes_lsm, badger_get_with_result_num_user, badger_iterator_num_user) are updated correctly. It also forces a compaction and checks the LSM and Bloom filter metrics after compaction.
  • Parameters:
    • t (*testing.T): Testing object for running the test.
  • Returns: None

Getting Started Relevance