Skip to content

Commit

Permalink
feat: add support for cpu nanocore metric
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed Jun 7, 2024
1 parent a77059d commit 98bfa1f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions kubernetes/quantity.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ func _k8sCPUAsMillicores(objVal string) int64 {
var cpu int64
if strings.HasSuffix(objVal, "m") {

Check failure on line 14 in kubernetes/quantity.go

View workflow job for this annotation

GitHub Actions / lint

ifElseChain: rewrite if-else to switch statement (gocritic)
cpu = conv.ToInt64(strings.ReplaceAll(objVal, "m", ""))
} else if strings.HasSuffix(objVal, "n") {
cpu = conv.ToInt64(strings.ReplaceAll(objVal, "n", "")) / (1000 * 1000)
} else {
cpu = int64(conv.ToFloat64(objVal) * 1000)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/cel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ func TestCelK8sCPUResourceUnits(t *testing.T) {
{Input: `k8s.cpuAsMillicores("10m")`, Output: int64(10)},
{Input: `k8s.cpuAsMillicores("100m")`, Output: int64(100)},
{Input: `k8s.cpuAsMillicores("1000m")`, Output: int64(1000)},
{Input: `k8s.cpuAsMillicores("15n")`, Output: int64(0)},
{Input: `k8s.cpuAsMillicores("150n")`, Output: int64(0)},
{Input: `k8s.cpuAsMillicores("15000000n")`, Output: int64(15)},
{Input: `k8s.cpuAsMillicores("150000000n")`, Output: int64(150)},
{Input: `k8s.cpuAsMillicores("0.5")`, Output: int64(500)},
{Input: `k8s.cpuAsMillicores("1")`, Output: int64(1000)},
{Input: `k8s.cpuAsMillicores("1.5")`, Output: int64(1500)},
Expand Down

0 comments on commit 98bfa1f

Please sign in to comment.