Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics for ec2 api calls made by CNI and expose via prometheus #2142

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be create tags isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's added to be tracked. But it looks like when I took the logs that function was probably not hit until then. Do we want to explicitly check for that scenario ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, we are incrementing the value.

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
jaydeokar marked this conversation as resolved.
Show resolved Hide resolved
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