Skip to content

Commit 39e759b

Browse files
committed
Addresses #144, Part 2: Adding Billing Rates to the config.py and rewriting code references
1 parent dfece72 commit 39e759b

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

openshift_metrics/config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,21 @@
1414
S3_SECRET_ACCESS_KEY = os.getenv("S3_OUTPUT_SECRET_ACCESS_KEY")
1515
S3_INVOICE_BUCKET = os.getenv("S3_INVOICE_BUCKET", "nerc-invoicing")
1616
S3_METRICS_BUCKET = os.getenv("S3_METRICS_BUCKET", "openshift_metrics")
17+
18+
# Billing Configuration
19+
# Service Unit Names for Rate Lookup from nerc-rates
20+
SU_NAMES = ["GPUV100", "GPUA100", "GPUA100SXM4", "GPUH100", "CPU"]
21+
RESOURCE_NAMES = ["vCPUs", "RAM", "GPUs"]
22+
23+
# Rate Configuration
24+
USE_NERC_RATES = os.getenv("USE_NERC_RATES", "false").lower() == "true"
25+
26+
# Individual rates (used when USE_NERC_RATES=false)
27+
RATE_CPU_SU = os.getenv("RATE_CPU_SU", "0.013")
28+
RATE_GPU_V100_SU = os.getenv("RATE_GPU_V100_SU", "1.214")
29+
RATE_GPU_A100SXM4_SU = os.getenv("RATE_GPU_A100SXM4_SU", "2.078")
30+
RATE_GPU_A100_SU = os.getenv("RATE_GPU_A100_SU", "1.803")
31+
RATE_GPU_H100_SU = os.getenv("RATE_GPU_H100_SU", "6.04")
32+
33+
# Legacy rate (for backward compatibility)
34+
GPU_A100_RATE = os.getenv("GPU_A100_RATE", "1.803")

openshift_metrics/merge.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@
1212

1313
from openshift_metrics import utils, invoice
1414
from openshift_metrics.metrics_processor import MetricsProcessor
15-
from openshift_metrics.config import S3_INVOICE_BUCKET
15+
from openshift_metrics.config import (
16+
S3_INVOICE_BUCKET,
17+
SU_NAMES,
18+
RESOURCE_NAMES,
19+
USE_NERC_RATES,
20+
RATE_CPU_SU,
21+
RATE_GPU_V100_SU,
22+
RATE_GPU_A100SXM4_SU,
23+
RATE_GPU_A100_SU,
24+
RATE_GPU_H100_SU,
25+
)
1626

1727
logging.basicConfig(level=logging.INFO)
1828
logger = logging.getLogger(__name__)
@@ -45,11 +55,9 @@ def parse_timestamp_range(timestamp_range: str) -> Tuple[datetime, datetime]:
4555
def get_su_definitions(report_month) -> dict:
4656
su_definitions = {}
4757
nerc_data = nerc_rates.load_from_url()
48-
su_names = ["GPUV100", "GPUA100", "GPUA100SXM4", "GPUH100", "CPU"]
49-
resource_names = ["vCPUs", "RAM", "GPUs"]
50-
for su_name in su_names:
58+
for su_name in SU_NAMES:
5159
su_definitions.setdefault(f"OpenShift {su_name}", {})
52-
for resource_name in resource_names:
60+
for resource_name in RESOURCE_NAMES:
5361
su_definitions[f"OpenShift {su_name}"][resource_name] = (
5462
nerc_data.get_value_at(
5563
f"{resource_name} in {su_name} SU", report_month, Decimal
@@ -92,13 +100,14 @@ def main():
92100
parser.add_argument(
93101
"--use-nerc-rates",
94102
action="store_true",
103+
default=USE_NERC_RATES,
95104
help="Use rates from the nerc-rates repo",
96105
)
97-
parser.add_argument("--rate-cpu-su", type=Decimal)
98-
parser.add_argument("--rate-gpu-v100-su", type=Decimal)
99-
parser.add_argument("--rate-gpu-a100sxm4-su", type=Decimal)
100-
parser.add_argument("--rate-gpu-a100-su", type=Decimal)
101-
parser.add_argument("--rate-gpu-h100-su", type=Decimal)
106+
parser.add_argument("--rate-cpu-su", type=Decimal, default=Decimal(RATE_CPU_SU))
107+
parser.add_argument("--rate-gpu-v100-su", type=Decimal, default=Decimal(RATE_GPU_V100_SU))
108+
parser.add_argument("--rate-gpu-a100sxm4-su", type=Decimal, default=Decimal(RATE_GPU_A100SXM4_SU))
109+
parser.add_argument("--rate-gpu-a100-su", type=Decimal, default=Decimal(RATE_GPU_A100_SU))
110+
parser.add_argument("--rate-gpu-h100-su", type=Decimal, default=Decimal(RATE_GPU_H100_SU))
102111

103112
args = parser.parse_args()
104113
files = args.files

0 commit comments

Comments
 (0)