Skip to content

Commit

Permalink
utils prometheusmetrics: switch AddIPCnt to be a counter
Browse files Browse the repository at this point in the history
  • Loading branch information
dshehbaj committed Oct 28, 2024
1 parent 2977ae2 commit 193aec9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lib/pq v1.10.9 // indirect
Expand Down
13 changes: 13 additions & 0 deletions pkg/ipamd/rpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (

pb "github.com/aws/amazon-vpc-cni-k8s/rpc"

"github.com/aws/amazon-vpc-cni-k8s/utils/prometheusmetrics"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -238,6 +241,12 @@ func TestServer_AddNetwork(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Reset the counter for each test case
prometheusmetrics.AddIPCnt = prometheus.NewCounter(prometheus.CounterOpts{
Name: "awscni_add_ip_req_count",
Help: "Number of add IP address requests",
})

m := setup(t)
defer m.ctrl.Finish()

Expand Down Expand Up @@ -302,6 +311,10 @@ func TestServer_AddNetwork(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, tt.want, resp)
}

// Add more detailed assertion messages
assert.Equal(t, float64(1), testutil.ToFloat64(prometheusmetrics.AddIPCnt),
"AddIPCnt should be incremented exactly once for test case: %s", tt.name)
})
}
}
4 changes: 2 additions & 2 deletions utils/prometheusmetrics/prometheusmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ var (
},
[]string{"fn"},
)
AddIPCnt = prometheus.NewGauge(
prometheus.GaugeOpts{
AddIPCnt = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "awscni_add_ip_req_count",
Help: "The number of add IP address requests",
},
Expand Down

0 comments on commit 193aec9

Please sign in to comment.