1
+ """
2
+ Config for the openshift metrics.
3
+ All values are set in the .env file
4
+ All variables in the .env file are lexicographically identical to the python variables below
5
+ """
6
+ import os
7
+ from decimal import Decimal
8
+ from datetime import datetime , timedelta
9
+ from typing import Dict , List
10
+
11
+ # =============================================================================
12
+ # HARDCODED CONSTANTS (rarely change, application-specific)
13
+ # =============================================================================
14
+
15
+ # Prometheus query strings
16
+ PROMETHEUS_QUERIES = {
17
+ "CPU_REQUEST" : 'kube_pod_resource_request{resource="cpu", node!=""} unless on(pod, namespace) kube_pod_status_unschedulable' ,
18
+ "MEMORY_REQUEST" : 'kube_pod_resource_request{resource="memory", node!=""} unless on(pod, namespace) kube_pod_status_unschedulable' ,
19
+ "GPU_REQUEST" : 'kube_pod_resource_request{resource=~"nvidia.com.*", node!=""} unless on(pod, namespace) kube_pod_status_unschedulable' ,
20
+ "KUBE_NODE_LABELS" : 'kube_node_labels{label_nvidia_com_gpu_product!=""}' ,
21
+ "KUBE_POD_LABELS" : 'kube_pod_labels{label_nerc_mghpcc_org_class!=""}' ,
22
+ }
23
+
24
+ # Cluster name mappings
25
+ CLUSTER_NAME_MAPPING = {
26
+ "https://thanos-querier-openshift-monitoring.apps.shift.nerc.mghpcc.org" : "ocp-prod" ,
27
+ "https://thanos-querier-openshift-monitoring.apps.ocp-test.nerc.mghpcc.org" : "ocp-test" ,
28
+ "https://thanos-querier-openshift-monitoring.apps.edu.nerc.mghpcc.org" : "academic" ,
29
+ }
30
+
31
+ # Default values for empty fields
32
+ DEFAULT_VALUES = {
33
+ "UNKNOWN_NODE" : "Unknown Node" ,
34
+ "UNKNOWN_MODEL" : "Unknown Model" ,
35
+ "EMPTY_STRING" : "" ,
36
+ }
37
+
38
+ # =============================================================================
39
+ # BUSINESS LOGIC CONSTANTS
40
+ # =============================================================================
41
+ # Note: Business logic constants (GPU types, SU types, etc.) are now in constants.py
42
+ # This file only contains truly configurable values that change between deployments
43
+
44
+ # =============================================================================
45
+ # INFRASTRUCTURE CONFIGURATION
46
+ # =============================================================================
47
+
48
+ # OpenShift/Prometheus
49
+ OPENSHIFT_PROMETHEUS_URL = os .getenv ("OPENSHIFT_PROMETHEUS_URL" )
50
+ OPENSHIFT_TOKEN = os .getenv ("OPENSHIFT_TOKEN" )
51
+
52
+ # S3 Configuration
53
+ S3_ENDPOINT_URL = os .getenv ("S3_OUTPUT_ENDPOINT_URL" , "https://s3.us-east-005.backblazeb2.com" )
54
+ S3_ACCESS_KEY_ID = os .getenv ("S3_OUTPUT_ACCESS_KEY_ID" )
55
+ S3_SECRET_ACCESS_KEY = os .getenv ("S3_OUTPUT_SECRET_ACCESS_KEY" )
56
+ S3_INVOICE_BUCKET = os .getenv ("S3_INVOICE_BUCKET" , "nerc-invoicing" )
57
+ S3_METRICS_BUCKET = os .getenv ("S3_METRICS_BUCKET" , "openshift_metrics" )
58
+
59
+ # =============================================================================
60
+ # PROCESSING CONFIGURATION
61
+ # =============================================================================
62
+
63
+ # Metrics processing
64
+ INTERVAL_MINUTES = int (os .getenv ("INTERVAL_MINUTES" , "15" ))
65
+ STEP_MINUTES = int (os .getenv ("STEP_MINUTES" , "15" ))
66
+ GPU_MAPPING_FILE = os .getenv ("GPU_MAPPING_FILE" , "gpu_node_map.json" )
67
+
68
+ # HTTP retry configuration
69
+ HTTP_RETRY_CONFIG = {
70
+ "total" : int (os .getenv ("HTTP_RETRY_TOTAL" , "3" )),
71
+ "backoff_factor" : int (os .getenv ("HTTP_RETRY_BACKOFF_FACTOR" , "1" )),
72
+ "status_forcelist" : [429 , 500 , 502 , 503 , 504 ],
73
+ }
74
+
75
+ # =============================================================================
76
+ # REPORT CONFIGURATION (formerly CLI arguments)
77
+ # =============================================================================
78
+
79
+ # Report dates (with defaults)
80
+ REPORT_START_DATE = os .getenv ("REPORT_START_DATE" , (datetime .today () - timedelta (days = 1 )).strftime ("%Y-%m-%d" ))
81
+ REPORT_END_DATE = os .getenv ("REPORT_END_DATE" , (datetime .today () - timedelta (days = 1 )).strftime ("%Y-%m-%d" ))
82
+
83
+ # Upload configuration
84
+ UPLOAD_TO_S3 = os .getenv ("UPLOAD_TO_S3" , "false" ).lower () == "true"
85
+
86
+ # File configuration
87
+ OUTPUT_FILE = os .getenv ("OUTPUT_FILE" )
88
+ INVOICE_FILE = os .getenv ("INVOICE_FILE" )
89
+ POD_REPORT_FILE = os .getenv ("POD_REPORT_FILE" )
90
+ CLASS_INVOICE_FILE = os .getenv ("CLASS_INVOICE_FILE" )
91
+
92
+ # Ignore hours configuration (comma-separated timestamp ranges)
93
+ IGNORE_HOURS = os .getenv ("IGNORE_HOURS" , "" )
94
+
95
+ # =============================================================================
96
+ # RATES AND BILLING CONFIGURATION
97
+ # =============================================================================
98
+
99
+ # Rate source configuration
100
+ USE_NERC_RATES = os .getenv ("USE_NERC_RATES" , "false" ).lower () == "true"
101
+
102
+ # Individual rates (Decimal values)
103
+ RATE_CPU_SU = os .getenv ("RATE_CPU_SU" )
104
+ RATE_GPU_V100_SU = os .getenv ("RATE_GPU_V100_SU" )
105
+ RATE_GPU_A100SXM4_SU = os .getenv ("RATE_GPU_A100SXM4_SU" )
106
+ RATE_GPU_A100_SU = os .getenv ("RATE_GPU_A100_SU" )
107
+ RATE_GPU_H100_SU = os .getenv ("RATE_GPU_H100_SU" )
108
+
109
+ # Legacy rates dictionary (for backward compatibility)
110
+ # Note: This would need to import constants if used, but it's marked as legacy
111
+ RATES = {
112
+ # "NVIDIA-A100-40GB": Decimal(os.getenv("GPU_A100_RATE")) if os.getenv("GPU_A100_RATE") else None,
113
+ }
114
+
115
+ # =============================================================================
116
+ # BUSINESS LOGIC CONFIGURATION
117
+ # =============================================================================
118
+
119
+ # Namespaces that support class-based reporting
120
+ NAMESPACES_WITH_CLASSES = os .getenv ("NAMESPACES_WITH_CLASSES" , "rhods-notebooks" ).split ("," )
121
+
122
+ # Default filename patterns
123
+ DEFAULT_FILENAME_PATTERNS = {
124
+ "INVOICE_FILE" : "NERC OpenShift {report_month}.csv" ,
125
+ "POD_REPORT_FILE" : "Pod NERC OpenShift {report_month}.csv" ,
126
+ "CLASS_INVOICE_FILE" : "NERC OpenShift Classes {report_month}.csv" ,
127
+ "OUTPUT_FILE_SINGLE" : "metrics-{report_date}.json" ,
128
+ "OUTPUT_FILE_RANGE" : "metrics-{start_date}-to-{end_date}.json" ,
129
+ }
0 commit comments