kubecost / disk-autoscaler

Resize Kubernetes PersistentVolumes automatically based on Kubecost recommendations.
Apache License 2.0
47 stars 1 forks source link

Audit mode with default true #21

Closed avrodrigues5 closed 4 months ago

avrodrigues5 commented 4 months ago

What does this PR change?

  1. Introduces audit mode run for Disk auto scaler
  2. adds caching in front of API call to Kubecost API
  3. Recommended bytes is calculated by convert targetutilization to headroom percentage expected by kubecost API
  4. Interchanges namespace and deployment in custom error.
  5. Kubernetes REST client settings are set to Queries per second of 20 and Burst of 10. This is still low to avoid log message having Kubernetes request.go warning about waiting to get the kubernetes object.

Does this PR rely on any other PRs?

None

How does this PR impact users?

Default will be audit mode, unless it set to false the Disk auto scaling wouldnt perform any scaling up and scaling down operations

Links to Issues or tickets this PR addresses or fixes

closes #4

What risks are associated with merging this PR? What is required to fully test this PR?

The audit mode is a safe option as default so its better for user

How was this PR tested?

When run in audit mode logs will look like below

2024-05-16T22:44:17Z INF Namespace: steven, Deployment: steven-prometheus-server, PVC: steven-prometheus-server, PV: pvc-8fb7e7f6-83ef-444a-b337-0c6698cc9f90, Target Utilization: 70%, current size is: 32Gi, recommended size is: 1Gi, and expected monthly savings is: $3.10
2024-05-16T22:44:17Z INF Namespace: thanos, Deployment: thanos-compactor, PVC: thanos-compactor, PV: pvc-5f174e0f-8245-4023-880e-d44383ba4c2a, Target Utilization: 70%, current size is: 8Gi, recommended size is: 1Gi, and expected monthly savings is: $0.70
2024-05-16T22:44:19Z INF Namespace: disk-scaler-demo, Deployment: ubuntu-deployment-scale-up, PVC: scale-up-pvc, PV: pvc-bd21b08e-7f68-4798-b1db-16577a5d9772, Target Utilization: 70%, current size is: 6Gi, recommended size is: 6Gi, and expected monthly savings is: $-0.08
2024-05-16T22:44:19Z INF Namespace: thomasn-guardduty-tmp, Deployment: thomasn-guardduty-tmp-cost-analyzer, PVC: thomasn-guardduty-tmp-cost-analyzer, PV: pvc-589ada18-bd52-41e6-a768-a2da2e12e67d, Target Utilization: 70%, current size is: 32Gi, recommended size is: 2Gi, and expected monthly savings is: $3.00
2024-05-16T22:44:20Z INF Namespace: thomasn-guardduty-tmp, Deployment: thomasn-guardduty-tmp-prometheus-server, PVC: thomasn-guardduty-tmp-prometheus-server, PV: pvc-7f3bde56-5ad0-43bb-b7a7-61e6878200d9, Target Utilization: 70%, current size is: 32Gi, recommended size is: 1Gi, and expected monthly savings is: $3.10
2024-05-16T22:44:21Z INF Namespace: ecr-test, Deployment: ecr-test-cost-analyzer, PVC: ecr-test-cost-analyzer, PV: pvc-cfa8a9c3-88e6-4bbc-8511-9bdeb5e89141, Target Utilization: 70%, current size is: 32Gi, recommended size is: 1Gi, and expected monthly savings is: $3.10
2024-05-16T22:44:21Z INF Namespace: thomasn-nightly-dev, Deployment: thomasn-nightly-dev-cost-analyzer, PVC: thomasn-nightly-dev-cost-analyzer, PV: pvc-691a99a8-ad61-4432-b125-fd136e8de168, Target Utilization: 70%, current size is: 32Gi, recommended size is: 2Gi, and expected monthly savings is: $3.00

Without audit mode tested for scale up and scale down operation

avrodrigues5 commented 4 months ago

Can you please copy that logged output in audit mode as a code block, not screenshot? We should add this to the README.

Done

chipzoller commented 4 months ago

@avrodrigues5 please review latest README changes.

dwbrown2 commented 4 months ago

Really cool! Just a future idea, could be nice to show % savings and maybe even a total expected savings amount.