def __ensure_provisioning_writes(table_name):
    """ Ensure that provisioning of writes is correct

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

    consumed_write_units_percent = \
        statistics.get_consumed_write_units_percent(table_name)

    # Check if we should update write provisioning
    if (consumed_write_units_percent == 0 and not
        get_table_option(table_name, 'allow_scaling_down_writes_on_0_percent')):

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

    elif (consumed_write_units_percent >=
        get_table_option(table_name, 'writes_upper_threshold')):

        if get_table_option(table_name, 'increase_writes_unit') == 'percent':
            updated_provisioning = calculators.increase_writes_in_percent(
                table_name,
                updated_write_units,
                get_table_option(table_name, 'increase_writes_with'))
        else:
            updated_provisioning = calculators.increase_writes_in_units(
                table_name,
                updated_write_units,
                get_table_option(table_name, 'increase_writes_with'))

        update_needed = True
        updated_write_units = updated_provisioning

    elif (consumed_write_units_percent <=
        get_table_option(table_name, 'writes_lower_threshold')):

        if get_table_option(table_name, 'decrease_writes_unit') == 'percent':
            updated_provisioning = calculators.decrease_writes_in_percent(
                table_name,
                updated_write_units,
                get_table_option(table_name, 'decrease_writes_with'))
        else:
            updated_provisioning = calculators.decrease_writes_in_units(
                table_name,
                updated_write_units,
                get_table_option(table_name, 'decrease_writes_with'))

        update_needed = True
        updated_write_units = updated_provisioning

    return update_needed, int(updated_write_units)
Пример #2
0
 def test_decrease_writes_in_percent_more_than_100_percent(self):
     """ Handle decreases of more that 100% """
     result = calculators.decrease_writes_in_percent(20, 120, 1, 'test')
     self.assertEqual(result, 1)
Пример #3
0
 def test_decrease_writes_in_percent_hit_min_value(self):
     """ Check that min values are honoured """
     result = calculators.decrease_writes_in_percent(20, 50, 15, 'test')
     self.assertEqual(result, 15)
Пример #4
0
 def test_decrease_writes_in_percent(self):
     """ Ensure that a regular decrease works """
     result = calculators.decrease_writes_in_percent(200, 90, 1, 'test')
     self.assertEqual(result, 20)
 def test_decrease_writes_in_percent_more_than_100_percent(self):
     """ Handle decreases of more that 100% """
     result = calculators.decrease_writes_in_percent(20, 120, 1, 'test')
     self.assertEqual(result, 1)
 def test_decrease_writes_in_percent_hit_min_value(self):
     """ Check that min values are honoured """
     result = calculators.decrease_writes_in_percent(20, 50, 15, 'test')
     self.assertEqual(result, 15)
 def test_decrease_writes_in_percent(self):
     """ Ensure that a regular decrease works """
     result = calculators.decrease_writes_in_percent(200, 90, 1, 'test')
     self.assertEqual(result, 20)
Пример #8
0
def __ensure_provisioning_writes(table_name, key_name):
    """ Ensure that provisioning of writes 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_write_units
    """
    update_needed = False
    updated_write_units = statistics.get_provisioned_write_units(table_name)

    consumed_write_units_percent = \
        statistics.get_consumed_write_units_percent(table_name)

    # Check if we should update write provisioning
    if (consumed_write_units_percent == 0 and not
        get_table_option(key_name, 'allow_scaling_down_writes_on_0_percent')):

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

    elif (consumed_write_units_percent >=
        get_table_option(key_name, 'writes_upper_threshold')):

        if get_table_option(key_name, 'increase_writes_unit') == 'percent':
            updated_provisioning = calculators.increase_writes_in_percent(
                table_name,
                updated_write_units,
                get_table_option(key_name, 'increase_writes_with'),
                key_name)
        else:
            updated_provisioning = calculators.increase_writes_in_units(
                table_name,
                updated_write_units,
                get_table_option(key_name, 'increase_writes_with'),
                key_name)

        update_needed = True
        updated_write_units = updated_provisioning

    elif (consumed_write_units_percent <=
        get_table_option(key_name, 'writes_lower_threshold')):

        if get_table_option(key_name, 'decrease_writes_unit') == 'percent':
            updated_provisioning = calculators.decrease_writes_in_percent(
                table_name,
                updated_write_units,
                get_table_option(key_name, 'decrease_writes_with'),
                key_name)
        else:
            updated_provisioning = calculators.decrease_writes_in_units(
                table_name,
                updated_write_units,
                get_table_option(key_name, 'decrease_writes_with'),
                key_name)

        update_needed = True
        updated_write_units = updated_provisioning

    return update_needed, int(updated_write_units)