Allow rating rules that have 12 digits in the integer part of the number

Currently, CloudKitty only allows creating rating rules as
"99.999999999999999999999999". Therefore, for prices equal to or higher
than 100, we would not be able to use them. This patch will enable
operators to use any value between 0 and 999999999999 (in the integer
part of the number), which will provide more flexibility.

Change-Id: I2ff4a09ce3b0fdf0b08a7e565b58794b25ac5ade
Story: 2009947
Task: 44865
This commit is contained in:
Rafael Weingärtner 2022-04-09 09:16:26 -03:00 committed by Pierre Riteau
parent 65a4768dce
commit ab1e31dc16
4 changed files with 59 additions and 4 deletions

View File

@ -0,0 +1,45 @@
# Copyright 2018 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
"""Increase cost fields to 30 digits
Revision ID: 4e0232ce
Revises: Ifbf5b2515c7
Create Date: 2022-04-06 08:00:00.000000
"""
from alembic import op
import importlib
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '4e0232ce'
down_revision = 'Ifbf5b2515c7'
def upgrade():
down_version_module = importlib.import_module(
"cloudkitty.rating.hash.db.sqlalchemy.alembic.versions."
"644faa4491fd_update_tenant_id_type_from_uuid_to_text")
for table_name in ('hashmap_mappings', 'hashmap_thresholds'):
with op.batch_alter_table(
table_name, reflect_args=down_version_module.get_reflect(
table_name)) as batch_op:
batch_op.alter_column('cost',
type_=sa.Numeric(precision=40, scale=28))

View File

@ -230,7 +230,7 @@ class HashMapMapping(Base, HashMapBase):
sqlalchemy.String(255),
nullable=True)
cost = sqlalchemy.Column(
sqlalchemy.Numeric(30, 28),
sqlalchemy.Numeric(40, 28),
nullable=False)
map_type = sqlalchemy.Column(
sqlalchemy.Enum(
@ -309,7 +309,7 @@ class HashMapThreshold(Base, HashMapBase):
sqlalchemy.Numeric(20, 8),
nullable=True)
cost = sqlalchemy.Column(
sqlalchemy.Numeric(30, 28),
sqlalchemy.Numeric(40, 28),
nullable=False)
map_type = sqlalchemy.Column(
sqlalchemy.Enum(

View File

@ -160,8 +160,8 @@ As for mappings, a threshold can be tied to a specific scope/project.
Cost
----
The cost option is the actual cost for the rating period. It has a precision of
28 decimal digits (on the right side of the number), and 30 digits on the left
side of the number.
28 decimal digits (on the right side of the decimal point), and 12 digits on
the left side of the decimal point (the integer part of the number).
Examples
========

View File

@ -0,0 +1,10 @@
---
fixes:
- |
Allow rating rules that have more than 2 digits in integer part.
Currently, CloudKitty only allows creating rating rules as
``99.999999999999999999999999``. Therefore, for prices equal to or higher
than 100, we would not be able to use them. This patch will enable
operators to use any value between ``0`` and ``999999999999`` (in the
integer part of the number), which will provide more flexibility.