<commit_before>from dtest import Tester
from tools import debug, known_failure
from jmxutils import JolokiaAgent, make_mbean, remove_perf_disable_shared_mem


# We currently only have attributes that are incrementing.
# MBEAN_VALUES are expressed in tuple with the first value being the class, then the type,
# a dictionary of arguments for make_mbean(), the attribute, and then the value.
# MBEAN_VALUES_PRE are values for up to release 2.2, MBEAN_VALUES_POST are for 3.0 and later.
# In 3.0 "ColumnFamily" has been renamed to "Table" and "Row" to "Partition".
# However, the old names are also supported for backward compatibility and we test them via
# the mbean aliases, see begin_test().
def MBEAN_VALUES_PRE(ks, table, node):
    return [('db', 'Caches', {}, 'CounterCacheKeysToSave', 2147483647),
            ('db', 'Caches', {}, 'CounterCacheSavePeriodInSeconds', 7200),
            ('db', 'BatchlogManager', {}, 'TotalBatchesReplayed', 0),
            ('db', 'Caches', {}, 'RowCacheSavePeriodInSeconds', 0),
            ('db', 'IndexSummaries', {}, 'MemoryPoolSizeInMB', 'MBeanIncrement'),
            ('db', 'IndexSummaries', {}, 'IndexIntervals', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'AllMemtablesLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'AllMemtablesHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'AllMemtablesOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'ColumnFamily', {'name': 'BloomFilterDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'BloomFilterFalsePositives'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'IndexSummaryOffHeapMemoryUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'LiveDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'LiveSSTableCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableColumnsCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableOnHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableSwitchCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'ColumnFamily', {'name': 'PendingCompactions'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'MaxRowSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'MinRowSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'MeanRowSize'}, 'Value', 'MBeanDecrement'),
            ('metrics', 'ColumnFamily', {'name': 'RowCacheHit'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'RowCacheHitOutOfRange'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'RowCacheMiss'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'EstimatedRowSizeHistogram', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'EstimatedRowCount', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual')]


def MBEAN_VALUES_POST(ks, table, node):
    return [('db', 'Caches', {}, 'CounterCacheKeysToSave', 2147483647),
            ('db', 'Caches', {}, 'CounterCacheSavePeriodInSeconds', 7200),
            ('db', 'BatchlogManager', {}, 'TotalBatchesReplayed', 0),
            ('db', 'Caches', {}, 'RowCacheSavePeriodInSeconds', 0),
            ('db', 'IndexSummaries', {}, 'MemoryPoolSizeInMB', 'MBeanIncrement'),
            ('db', 'IndexSummaries', {}, 'IndexIntervals', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'AllMemtablesLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'AllMemtablesHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'AllMemtablesOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'Table', {'name': 'BloomFilterDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'BloomFilterFalsePositives'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'IndexSummaryOffHeapMemoryUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'LiveDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'LiveSSTableCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableColumnsCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableOnHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableSwitchCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'Table', {'name': 'PendingCompactions'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'MaxPartitionSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'MinPartitionSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'MeanPartitionSize'}, 'Value', 'MBeanDecrement'),
            ('metrics', 'Table', {'name': 'RowCacheHit'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'RowCacheHitOutOfRange'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'RowCacheMiss'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'EstimatedPartitionSizeHistogram', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'EstimatedPartitionCount', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual')]


def offheap_memtable_val(node):
    memtable_allocation_type = node.get_conf_option('memtable_allocation_type')
    offheap_memtable = memtable_allocation_type is not None and memtable_allocation_type.startswith('offheap')
    return 'MBeanIncrement' if offheap_memtable else 'MBeanEqual'


class TestJMXMetrics(Tester):

    def __init__(self, *args, **kwargs):
        Tester.__init__(self, *args, **kwargs)

    @known_failure(failure_source='test',
                   jira_url='https://issues.apache.org/jira/browse/CASSANDRA-10845')
    def begin_test(self):
        """
        @jira_ticket CASSANDRA-7436
        This test measures the values of MBeans before and after running a load. We expect
        the values to change a certain way, and thus deem them as 'MBeanEqual','MBeanDecrement',
        'MBeanIncrement', or a constant to express this expected change. If the value does not reflect
        this expected change, then it raises an AssertionError.

        @jira_ticket CASSANDRA-9448
        This test also makes sure to cover all metrics that were renamed by CASSANDRA-9448, in post 3.0
        we also check that the old alias names are the same as the new names.
        """
        cluster = self.cluster
        cluster.populate(1)
        node = cluster.nodelist()[0]
        remove_perf_disable_shared_mem(node)
        cluster.start(wait_for_binary_proto=True)
        session = self.patient_cql_connection(node)
        self.create_ks(session, 'keyspace1', 1)
        session.execute("""
                        CREATE TABLE keyspace1.counter1 (<commit_msg>skip failing jmx metrics test<commit_after>from dtest import Tester
from tools import debug, known_failure, require
from jmxutils import JolokiaAgent, make_mbean, remove_perf_disable_shared_mem


# We currently only have attributes that are incrementing.
# MBEAN_VALUES are expressed in tuple with the first value being the class, then the type,
# a dictionary of arguments for make_mbean(), the attribute, and then the value.
# MBEAN_VALUES_PRE are values for up to release 2.2, MBEAN_VALUES_POST are for 3.0 and later.
# In 3.0 "ColumnFamily" has been renamed to "Table" and "Row" to "Partition".
# However, the old names are also supported for backward compatibility and we test them via
# the mbean aliases, see begin_test().
def MBEAN_VALUES_PRE(ks, table, node):
    return [('db', 'Caches', {}, 'CounterCacheKeysToSave', 2147483647),
            ('db', 'Caches', {}, 'CounterCacheSavePeriodInSeconds', 7200),
            ('db', 'BatchlogManager', {}, 'TotalBatchesReplayed', 0),
            ('db', 'Caches', {}, 'RowCacheSavePeriodInSeconds', 0),
            ('db', 'IndexSummaries', {}, 'MemoryPoolSizeInMB', 'MBeanIncrement'),
            ('db', 'IndexSummaries', {}, 'IndexIntervals', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'AllMemtablesLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'AllMemtablesHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'AllMemtablesOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'ColumnFamily', {'name': 'BloomFilterDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'BloomFilterFalsePositives'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'IndexSummaryOffHeapMemoryUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'LiveDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'LiveSSTableCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableColumnsCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableOnHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableSwitchCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'ColumnFamily', {'name': 'MemtableOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'ColumnFamily', {'name': 'PendingCompactions'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'MaxRowSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'MinRowSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'MeanRowSize'}, 'Value', 'MBeanDecrement'),
            ('metrics', 'ColumnFamily', {'name': 'RowCacheHit'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'RowCacheHitOutOfRange'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'RowCacheMiss'}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'EstimatedRowSizeHistogram', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual'),
            ('metrics', 'ColumnFamily', {'name': 'EstimatedRowCount', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual')]


def MBEAN_VALUES_POST(ks, table, node):
    return [('db', 'Caches', {}, 'CounterCacheKeysToSave', 2147483647),
            ('db', 'Caches', {}, 'CounterCacheSavePeriodInSeconds', 7200),
            ('db', 'BatchlogManager', {}, 'TotalBatchesReplayed', 0),
            ('db', 'Caches', {}, 'RowCacheSavePeriodInSeconds', 0),
            ('db', 'IndexSummaries', {}, 'MemoryPoolSizeInMB', 'MBeanIncrement'),
            ('db', 'IndexSummaries', {}, 'IndexIntervals', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'AllMemtablesLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'AllMemtablesHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'AllMemtablesOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'Table', {'name': 'BloomFilterDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'BloomFilterFalsePositives'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'IndexSummaryOffHeapMemoryUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'LiveDiskSpaceUsed'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'LiveSSTableCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableColumnsCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableLiveDataSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableOnHeapSize'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableSwitchCount'}, 'Value', 'MBeanIncrement'),
            ('metrics', 'Table', {'name': 'MemtableOffHeapSize'}, 'Value', offheap_memtable_val(node)),
            ('metrics', 'Table', {'name': 'PendingCompactions'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'MaxPartitionSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'MinPartitionSize'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'MeanPartitionSize'}, 'Value', 'MBeanDecrement'),
            ('metrics', 'Table', {'name': 'RowCacheHit'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'RowCacheHitOutOfRange'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'RowCacheMiss'}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'EstimatedPartitionSizeHistogram', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual'),
            ('metrics', 'Table', {'name': 'EstimatedPartitionCount', 'keyspace': ks, 'scope': table}, 'Value', 'MBeanEqual')]


def offheap_memtable_val(node):
    memtable_allocation_type = node.get_conf_option('memtable_allocation_type')
    offheap_memtable = memtable_allocation_type is not None and memtable_allocation_type.startswith('offheap')
    return 'MBeanIncrement' if offheap_memtable else 'MBeanEqual'


class TestJMXMetrics(Tester):

    def __init__(self, *args, **kwargs):
        Tester.__init__(self, *args, **kwargs)

    @known_failure(failure_source='test',
                   jira_url='https://issues.apache.org/jira/browse/CASSANDRA-10845')
    @require('10845')
    def begin_test(self):
        """
        @jira_ticket CASSANDRA-7436
        This test measures the values of MBeans before and after running a load. We expect
        the values to change a certain way, and thus deem them as 'MBeanEqual','MBeanDecrement',
        'MBeanIncrement', or a constant to express this expected change. If the value does not reflect
        this expected change, then it raises an AssertionError.

        @jira_ticket CASSANDRA-9448
        This test also makes sure to cover all metrics that were renamed by CASSANDRA-9448, in post 3.0
        we also check that the old alias names are the same as the new names.
        """
        cluster = self.cluster
        cluster.populate(1)
        node = cluster.nodelist()[0]
        remove_perf_disable_shared_mem(node)
        cluster.start(wait_for_binary_proto=True)
        session = self.patient_cql_connection(node)
        self.create_ks(session, 'keyspace1', 1)
        session.execute("""
                        CREATE TABLE keyspace1.counter1 (
{'fraction_non_alphanumeric': 0.1780152472795986, 'fraction_numerical': 0.008535870202645467, 'mean_word_length': 4.050345508390918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7105417', 'n_tokens_mistral': 4547, 'n_tokens_neox': 4440, 'n_words': 1140}