Skip to content

Commit

Permalink
Fixed Kubecost empty data issue; no file write on empty data (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarl-tornroos authored Jan 4, 2024
1 parent dcf5703 commit 3c2e4bd
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.9.1

- Addressed an issue with Kubecost where it returns "empty" data for selected date ranges. Also ensured that no data is written to files in cases where the data is empty.

## v1.9

- Added new env var REQUEST_TIMEOUT to manage the timeout of the requests. Default value is 5 minutes.
Expand Down
4 changes: 2 additions & 2 deletions helm-chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ description: Kubecost exporter helm chart for Kubernetes
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.9.0
version: 1.9.1

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.9"
appVersion: "1.9.1"
Binary file added helm-chart/cbi-oi-kubecost-exporter-1.9.1.tgz
Binary file not shown.
2 changes: 1 addition & 1 deletion helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
image:
repository: public.ecr.aws/flexera/cbi-oi-kubecost-exporter
pullPolicy: Always
tag: "1.9"
tag: "1.9.1"

imagePullSecrets: []

Expand Down
34 changes: 22 additions & 12 deletions index.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
apiVersion: v1
entries:
cbi-oi-kubecost-exporter:
- apiVersion: v2
appVersion: 1.9.1
created: "2024-01-03T11:01:29.556099+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 773cc828783dd12211cccf149cda5b3c95e5d5bf7bf507d73559ef5f0f66f13a
name: cbi-oi-kubecost-exporter
type: application
urls:
- helm-chart/cbi-oi-kubecost-exporter-1.9.1.tgz
version: 1.9.1
- apiVersion: v2
appVersion: "1.9"
created: "2023-12-19T18:36:33.695219-06:00"
created: "2024-01-03T11:01:29.555855+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 312f1c8f469adbed664530059526b69c023c017f71cc6c7b8bd9aed523ef22d6
name: cbi-oi-kubecost-exporter
Expand All @@ -13,7 +23,7 @@ entries:
version: 1.9.0
- apiVersion: v2
appVersion: "1.8"
created: "2023-12-19T18:36:33.695014-06:00"
created: "2024-01-03T11:01:29.55561+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 3fc398d0ae6d2c44c9196d262042394763fc7df49f05bd97764637a9becaad11
name: cbi-oi-kubecost-exporter
Expand All @@ -23,7 +33,7 @@ entries:
version: 1.8.0
- apiVersion: v2
appVersion: "1.7"
created: "2023-12-19T18:36:33.694691-06:00"
created: "2024-01-03T11:01:29.555385+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 90fbd649c651fa2ad66d0705aced6cbecd908206c59c135ee585ce12188cd287
name: cbi-oi-kubecost-exporter
Expand All @@ -33,7 +43,7 @@ entries:
version: 1.7.0
- apiVersion: v2
appVersion: "1.6"
created: "2023-12-19T18:36:33.694356-06:00"
created: "2024-01-03T11:01:29.555155+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: f998790d9229fce36398ef487edf6685a9a29e359dd2c78191c4d16344d47acd
name: cbi-oi-kubecost-exporter
Expand All @@ -43,7 +53,7 @@ entries:
version: 1.6.0
- apiVersion: v2
appVersion: "1.5"
created: "2023-12-19T18:36:33.693792-06:00"
created: "2024-01-03T11:01:29.55493+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: a0503a1af7b86a8f0769009de5a71a3613e8503a5f59cf86874d483f0f5f2abb
name: cbi-oi-kubecost-exporter
Expand All @@ -53,7 +63,7 @@ entries:
version: 1.5.0
- apiVersion: v2
appVersion: "1.4"
created: "2023-12-19T18:36:33.693267-06:00"
created: "2024-01-03T11:01:29.554707+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 5b296e921178d84717345be19b92a4eea0c9ca1c65410128dec596692220c8e2
name: cbi-oi-kubecost-exporter
Expand All @@ -63,7 +73,7 @@ entries:
version: 1.4.2
- apiVersion: v2
appVersion: "1.4"
created: "2023-12-19T18:36:33.692944-06:00"
created: "2024-01-03T11:01:29.554482+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: ab6992a0af9f24d5c090db71679b7f274f3576b1cfbe91325e0d6e9af317657e
name: cbi-oi-kubecost-exporter
Expand All @@ -73,7 +83,7 @@ entries:
version: 1.4.1
- apiVersion: v2
appVersion: "1.4"
created: "2023-12-19T18:36:33.692588-06:00"
created: "2024-01-03T11:01:29.55424+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 870030e989ba274f8b0f9d122a4ada24a4d29ef2c071408bf46d86e18942effd
name: cbi-oi-kubecost-exporter
Expand All @@ -83,7 +93,7 @@ entries:
version: 1.4.0
- apiVersion: v2
appVersion: "1.3"
created: "2023-12-19T18:36:33.692231-06:00"
created: "2024-01-03T11:01:29.553983+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: 0d967927bfab5f4bb6d40ce062710679e98b145c4b3f38709c0bf5d216ad8606
name: cbi-oi-kubecost-exporter
Expand All @@ -93,7 +103,7 @@ entries:
version: 1.3.0
- apiVersion: v2
appVersion: "1.2"
created: "2023-12-19T18:36:33.691385-06:00"
created: "2024-01-03T11:01:29.553419+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: d0c724c7bb085a1801e27f60ff748bc69aba14425cfd27fd132f99966692ed80
name: cbi-oi-kubecost-exporter
Expand All @@ -103,12 +113,12 @@ entries:
version: 1.2.0
- apiVersion: v2
appVersion: "1.1"
created: "2023-12-19T18:36:33.691004-06:00"
created: "2024-01-03T11:01:29.553164+02:00"
description: Kubecost exporter helm chart for Kubernetes
digest: c6f2681575b704b5934efea2357921896d55c4ad5e09692f31ab92b9e614cfea
name: cbi-oi-kubecost-exporter
type: application
urls:
- helm-chart/cbi-oi-kubecost-exporter-1.1.0.tgz
version: 1.1.0
generated: "2023-12-19T18:36:33.69011-06:00"
generated: "2024-01-03T11:01:29.552764+02:00"
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,18 @@ func (a *App) updateFromKubecost() {
}

// If the data obtained is empty, skip the iteration, because it might overwrite a previously obtained file for the same range time
_, previousFileCreated := a.filesToUpload[monthOfData][csvFile]
if len(data) == 0 && previousFileCreated {
log.Printf("File %s has already been created and kubecost no longer has data for this same date range, skipping \n", csvFile)
dataExist := false
for _, allocation := range j.Data {
if len(allocation) > 0 {
dataExist = true
}
}

if dataExist == false {
log.Printf(
"Kubecost doesn't have data for date range %s to %s, skipping\n",
d.Format("2006-01-02T15:04:05Z"),
tomorrow.Format("2006-01-02T15:04:05Z"))
continue
}

Expand Down

0 comments on commit 3c2e4bd

Please sign in to comment.