Skip to content

Commit

Permalink
fix(sqlinstance): if team dont have any database when can calculate t…
Browse files Browse the repository at this point in the history
…he metrics, safeguard against divide with 0.

Co-authored-by: Tommy Trøen <[email protected]>
  • Loading branch information
ybelMekk and tommytroen committed Apr 25, 2024
1 parent 65dd409 commit 1c24277
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions internal/sqlinstance/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,31 @@ func metricsSummary(instances []*model.SQLInstance) *model.SQLInstancesMetrics {
return &model.SQLInstancesMetrics{
Cost: cost,
CPU: model.SQLInstanceCPU{
Cores: cpuCores,
Utilization: cpuUtilization / numInstances,
Cores: cpuCores,
Utilization: func() float64 {
if numInstances == 0 {
return 0
}
return cpuUtilization / numInstances
}(),
},
Disk: model.SQLInstanceDisk{
QuotaBytes: diskQuota,
Utilization: diskUtilization / numInstances,
QuotaBytes: diskQuota,
Utilization: func() float64 {
if numInstances == 0 {
return 0
}
return diskUtilization / numInstances
}(),
},
Memory: model.SQLInstanceMemory{
QuotaBytes: memoryQuota,
Utilization: memoryUtilization / numInstances,
QuotaBytes: memoryQuota,
Utilization: func() float64 {
if numInstances == 0 {
return 0
}
return memoryUtilization / numInstances
}(),
},
}
}
Expand Down

0 comments on commit 1c24277

Please sign in to comment.