def __ensure_provisioning_reads(table_name):
    """ Ensure that provisioning is correct

    :type table_name: str
    :param table_name: Name of the DynamoDB table
    :returns: (bool, int) -- update_needed, updated_read_units
    """
    update_needed = False
    updated_read_units = statistics.get_provisioned_read_units(table_name)

    consumed_read_units_percent = \
        statistics.get_consumed_read_units_percent(table_name)

    if (consumed_read_units_percent == 0 and not
        get_table_option(table_name, 'allow_scaling_down_reads_on_0_percent')):

        logger.info(
            '{0} - Scaling down reads is not done when usage is at 0%'.format(
                table_name))

    elif (consumed_read_units_percent >=
        get_table_option(table_name, 'reads_upper_threshold')):

        if get_table_option(table_name, 'increase_reads_unit') == 'percent':
            updated_provisioning = calculators.increase_reads_in_percent(
                table_name,
                updated_read_units,
                get_table_option(table_name, 'increase_reads_with'))
        else:
            updated_provisioning = calculators.increase_reads_in_units(
                table_name,
                updated_read_units,
                get_table_option(table_name, 'increase_reads_with'))

        update_needed = True
        updated_read_units = updated_provisioning

    elif (consumed_read_units_percent <=
        get_table_option(table_name, 'reads_lower_threshold')):

        if get_table_option(table_name, 'decrease_reads_unit') == 'percent':
            updated_provisioning = calculators.decrease_reads_in_percent(
                table_name,
                updated_read_units,
                get_table_option(table_name, 'decrease_reads_with'))
        else:
            updated_provisioning = calculators.decrease_reads_in_units(
                table_name,
                updated_read_units,
                get_table_option(table_name, 'decrease_reads_with'))

        update_needed = True
        updated_read_units = updated_provisioning

    return update_needed, int(updated_read_units)
 def test_decrease_reads_in_percent_more_than_100_percent(self):
     """ Handle decreases of more that 100% """
     result = calculators.decrease_reads_in_percent(20, 120, 1, 'test')
     self.assertEqual(result, 1)
 def test_decrease_reads_in_percent_hit_min_value(self):
     """ Check that min values are honoured """
     result = calculators.decrease_reads_in_percent(20, 50, 15, 'test')
     self.assertEqual(result, 15)
 def test_decrease_reads_in_percent(self):
     """ Ensure that a regular decrease works """
     result = calculators.decrease_reads_in_percent(200, 90, 1, 'test')
     self.assertEqual(result, 20)
 def test_decrease_reads_in_percent(self):
     """ Ensure that a regular decrease works """
     result = calculators.decrease_reads_in_percent(200, 90, 1, 'test')
     self.assertEqual(result, 20)
 def test_decrease_reads_in_percent_more_than_100_percent(self):
     """ Handle decreases of more that 100% """
     result = calculators.decrease_reads_in_percent(20, 120, 1, 'test')
     self.assertEqual(result, 1)
 def test_decrease_reads_in_percent_hit_min_value(self):
     """ Check that min values are honoured """
     result = calculators.decrease_reads_in_percent(20, 50, 15, 'test')
     self.assertEqual(result, 15)
Exemple #8
0
def __ensure_provisioning_reads(table_name, key_name):
    """ Ensure that provisioning is correct

    :type table_name: str
    :param table_name: Name of the DynamoDB table
    :type key_name: str
    :param key_name: Configuration option key name
    :returns: (bool, int) -- update_needed, updated_read_units
    """
    update_needed = False
    updated_read_units = statistics.get_provisioned_read_units(table_name)

    consumed_read_units_percent = \
        statistics.get_consumed_read_units_percent(table_name)

    if (consumed_read_units_percent == 0 and not
        get_table_option(key_name, 'allow_scaling_down_reads_on_0_percent')):

        logger.info(
            '{0} - Scaling down reads is not done when usage is at 0%'.format(
                table_name))

    elif (consumed_read_units_percent >=
        get_table_option(key_name, 'reads_upper_threshold')):

        if get_table_option(key_name, 'increase_reads_unit') == 'percent':
            updated_provisioning = calculators.increase_reads_in_percent(
                table_name,
                updated_read_units,
                get_table_option(key_name, 'increase_reads_with'),
                key_name)
        else:
            updated_provisioning = calculators.increase_reads_in_units(
                table_name,
                updated_read_units,
                get_table_option(key_name, 'increase_reads_with'),
                key_name)

        update_needed = True
        updated_read_units = updated_provisioning

    elif (consumed_read_units_percent <=
        get_table_option(key_name, 'reads_lower_threshold')):

        if get_table_option(key_name, 'decrease_reads_unit') == 'percent':
            updated_provisioning = calculators.decrease_reads_in_percent(
                table_name,
                updated_read_units,
                get_table_option(key_name, 'decrease_reads_with'),
                key_name)
        else:
            updated_provisioning = calculators.decrease_reads_in_units(
                table_name,
                updated_read_units,
                get_table_option(key_name, 'decrease_reads_with'),
                key_name)

        update_needed = True
        updated_read_units = updated_provisioning

    return update_needed, int(updated_read_units)