Skip to content

Commit

Permalink
Add metrics for ec2 api calls made by CNI and expose via prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeokar committed Nov 17, 2022
1 parent f8bc3b8 commit 4525da0
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/cni-metrics-helper/metrics/cni_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ var InterestingCNIMetrics = map[string]metricsConvert{
actionFunc: metricsAdd,
data: &dataPoints{},
logToFile: true}}},
"awscni_ec2api_req_count": {
actions: []metricsAction{
{cwMetricName: "ec2ApiReqCount",
matchFunc: matchAny,
actionFunc: metricsAdd,
data: &dataPoints{},
logToFile: true}}},
"awscni_ec2api_error_count": {
actions: []metricsAction{
{cwMetricName: "ec2ApiErrCount",
matchFunc: matchAny,
actionFunc: metricsAdd,
data: &dataPoints{},
logToFile: true}}},
}

// CNIMetricsTarget defines data structure for kube-state-metric target
Expand Down
10 changes: 10 additions & 0 deletions cmd/cni-metrics-helper/metrics/cni_test1.data
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ awscni_assigned_ip_addresses 1
# HELP awscni_aws_api_error_count The number of times AWS API returns an error
# TYPE awscni_aws_api_error_count counter
awscni_aws_api_error_count{api="DeleteNetworkInterface",error="InvalidParameterValue"} 14
# HELP awscni_ec2api_req_count The number of requests made to EC2 APIs by CNI
# TYPE awscni_ec2api_req_count counter
awscni_ec2api_req_count{fn="AssignPrivateIpAddresses"} 1
awscni_ec2api_req_count{fn="AttachNetworkInterface"} 1
awscni_ec2api_req_count{fn="CreateNetworkInterface"} 1
awscni_ec2api_req_count{fn="DeleteNetworkInterface"} 1
awscni_ec2api_req_count{fn="DescribeInstances"} 1
awscni_ec2api_req_count{fn="DescribeNetworkInterfaces"} 13
awscni_ec2api_req_count{fn="DetachNetworkInterface"} 1
awscni_ec2api_req_count{fn="ModifyNetworkInterfaceAttribute"} 2
# HELP awscni_aws_api_latency_ms AWS API call latency in ms
# TYPE awscni_aws_api_latency_ms summary
awscni_aws_api_latency_ms{api="AssignPrivateIpAddresses",error="false",quantile="0.5"} NaN
Expand Down
8 changes: 8 additions & 0 deletions cmd/cni-metrics-helper/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func TestAPIServerMetric(t *testing.T) {
// verify awscni_assigned_ip_addresses value
assert.Equal(t, 1.0, actions[0].data.curSingleDataPoint)

// verify awscni_ec2api_req_count value
actions = InterestingCNIMetrics["awscni_ec2api_req_count"].actions
assert.Equal(t, 21.0, actions[0].data.curSingleDataPoint)

// verify awscni_ec2api_error_count value
actions = InterestingCNIMetrics["awscni_ec2api_error_count"].actions
assert.Equal(t, 0.0, actions[0].data.curSingleDataPoint)

actions = InterestingCNIMetrics["awscni_total_ip_addresses"].actions
// verify awscni_total_ip_addresses value
assert.Equal(t, 10.0, actions[0].data.curSingleDataPoint)
Expand Down
Loading

0 comments on commit 4525da0

Please sign in to comment.