Skip to content

Commit 2967310

Browse files
committed
Addresses #144, Part 2: Adding Billing Rates to the config.py and rewriting code references.
Removed CLI arguments for setting rates
1 parent dfece72 commit 2967310

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

openshift_metrics/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,22 @@
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_ENV = os.getenv("USE_NERC_RATES")
25+
USE_NERC_RATES = USE_NERC_RATES_ENV.lower() == "true" if USE_NERC_RATES_ENV else None
26+
27+
# Individual rates (used when USE_NERC_RATES=false)
28+
RATE_CPU_SU = os.getenv("RATE_CPU_SU")
29+
RATE_GPU_V100_SU = os.getenv("RATE_GPU_V100_SU")
30+
RATE_GPU_A100SXM4_SU = os.getenv("RATE_GPU_A100SXM4_SU")
31+
RATE_GPU_A100_SU = os.getenv("RATE_GPU_A100_SU")
32+
RATE_GPU_H100_SU = os.getenv("RATE_GPU_H100_SU")
33+
34+
# Legacy rate (for backward compatibility)
35+
GPU_A100_RATE = os.getenv("GPU_A100_RATE")

openshift_metrics/merge.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
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+
USE_NERC_RATES,
18+
RATE_CPU_SU,
19+
RATE_GPU_V100_SU,
20+
RATE_GPU_A100SXM4_SU,
21+
RATE_GPU_A100_SU,
22+
RATE_GPU_H100_SU,
23+
)
1624

1725
logging.basicConfig(level=logging.INFO)
1826
logger = logging.getLogger(__name__)
@@ -89,16 +97,6 @@ def main():
8997
nargs="*",
9098
help="List of timestamp ranges in UTC to ignore in the format 'YYYY-MM-DDTHH:MM:SS,YYYY-MM-DDTHH:MM:SS'",
9199
)
92-
parser.add_argument(
93-
"--use-nerc-rates",
94-
action="store_true",
95-
help="Use rates from the nerc-rates repo",
96-
)
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)
102100

103101
args = parser.parse_args()
104102
files = args.files
@@ -147,7 +145,12 @@ def main():
147145

148146
report_month = datetime.strftime(report_start_date, "%Y-%m")
149147

150-
if args.use_nerc_rates:
148+
if USE_NERC_RATES is None:
149+
raise ValueError(
150+
"USE_NERC_RATES environment variable must be set to 'true' or 'false'"
151+
)
152+
153+
if USE_NERC_RATES:
151154
logger.info("Using nerc rates.")
152155
nerc_data = nerc_rates.load_from_url()
153156
rates = invoice.Rates(
@@ -160,12 +163,23 @@ def main():
160163
gpu_h100=nerc_data.get_value_at("GPUH100 SU Rate", report_month, Decimal),
161164
)
162165
else:
166+
if RATE_CPU_SU is None:
167+
raise ValueError("RATE_CPU_SU environment variable must be set")
168+
if RATE_GPU_V100_SU is None:
169+
raise ValueError("RATE_GPU_V100_SU environment variable must be set")
170+
if RATE_GPU_A100SXM4_SU is None:
171+
raise ValueError("RATE_GPU_A100SXM4_SU environment variable must be set")
172+
if RATE_GPU_A100_SU is None:
173+
raise ValueError("RATE_GPU_A100_SU environment variable must be set")
174+
if RATE_GPU_H100_SU is None:
175+
raise ValueError("RATE_GPU_H100_SU environment variable must be set")
176+
163177
rates = invoice.Rates(
164-
cpu=Decimal(args.rate_cpu_su),
165-
gpu_a100=Decimal(args.rate_gpu_a100_su),
166-
gpu_a100sxm4=Decimal(args.rate_gpu_a100sxm4_su),
167-
gpu_v100=Decimal(args.rate_gpu_v100_su),
168-
gpu_h100=Decimal(args.rate_gpu_h100_su),
178+
cpu=Decimal(RATE_CPU_SU),
179+
gpu_a100=Decimal(RATE_GPU_A100_SU),
180+
gpu_a100sxm4=Decimal(RATE_GPU_A100SXM4_SU),
181+
gpu_v100=Decimal(RATE_GPU_V100_SU),
182+
gpu_h100=Decimal(RATE_GPU_H100_SU),
169183
)
170184

171185
if args.invoice_file:

0 commit comments

Comments
 (0)