Skip to content

Commit

Permalink
Merge pull request #6 from electrolux-oss/list-length-check
Browse files Browse the repository at this point in the history
add a warning message when record names do not map to aggregation dim…
  • Loading branch information
gluckzhang authored Jul 22, 2024
2 parents ae80fda + 98afd34 commit 822abb3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def run_metrics_loop(self):
def fetch(self):
api = (
f"/allocation/summary?aggregate={','.join(self.aggregate)}&accumulate=true&chartType=costovertime&"
"costUnit=cumulative&external=false&filter=&idle=true&idleByNode=false&includeSharedCostBreakdown=true&"
"shareCost=0&shareIdle=true&shareLabels=&shareNamespaces=&shareSplit=weighted&shareTenancyCosts=true&"
"window=today"
"costUnit=cumulative&external=false&filter=&idle=true&idleByNode=false&includeSharedCostBreakdown=true&"
"shareCost=0&shareIdle=true&shareLabels=&shareNamespaces=&shareSplit=weighted&shareTenancyCosts=true&"
"window=today"
)
response = requests.get(self.endpoint + api)
if response.status_code != 200 or response.json().get("code") != 200:
Expand All @@ -47,11 +47,21 @@ def fetch(self):
for item in allocations:
aggregation_labels = {}
names = item.split("/")

if len(names) != len(self.aggregate):
logging.warning(
"Record names from a response should map to aggregation labels, expected %s, got %s"
% (self.aggregate, names)
)
continue

for i in range(len(self.aggregate)):
aggregation_labels[self.aggregate[i]] = names[i]

if self.extra_labels:
self.kubernetes_daily_cost_usd.labels(**aggregation_labels, **self.extra_labels).set(allocations[item]["totalCost"])
self.kubernetes_daily_cost_usd.labels(**aggregation_labels, **self.extra_labels).set(
allocations[item]["totalCost"]
)
else:
self.kubernetes_daily_cost_usd.labels(**aggregation_labels).set(allocations[item]["totalCost"])
logging.info(f"cost metric {self.name} updated successfully")

0 comments on commit 822abb3

Please sign in to comment.