Skip to content

Commit

Permalink
emit metric for EC2 describeInstance calls
Browse files Browse the repository at this point in the history
Signed-off-by: Jyoti Mahapatra <jyotima@amazon.com>
  • Loading branch information
jyotimahapatra committed Feb 10, 2022
1 parent 057fa8f commit 264a477
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 11 additions & 5 deletions pkg/ec2provider/ec2provider.go
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/sirupsen/logrus"
"sigs.k8s.io/aws-iam-authenticator/pkg"
"sigs.k8s.io/aws-iam-authenticator/pkg/httputil"
"sigs.k8s.io/aws-iam-authenticator/pkg/metrics"
)

const (
Expand Down Expand Up @@ -54,13 +55,15 @@ type ec2Requests struct {
}

type ec2ProviderImpl struct {
ec2 ec2iface.EC2API
privateDNSCache ec2PrivateDNSCache
ec2Requests ec2Requests
instanceIdsChannel chan string
ec2 ec2iface.EC2API
privateDNSCache ec2PrivateDNSCache
ec2Requests ec2Requests
instanceIdsChannel chan string
authenticatorMetrics metrics.Metrics
}

func New(roleARN string, qps int, burst int) EC2Provider {
func New(roleARN string, qps int, burst int, authenticatorMetrics metrics.Metrics
}) EC2Provider {
dnsCache := ec2PrivateDNSCache{
cache: make(map[string]string),
lock: sync.RWMutex{},
Expand All @@ -74,6 +77,7 @@ func New(roleARN string, qps int, burst int) EC2Provider {
privateDNSCache: dnsCache,
ec2Requests: ec2Requests,
instanceIdsChannel: make(chan string, maxChannelSize),
authenticatorMetrics: authenticatorMetrics,
}
}

Expand Down Expand Up @@ -193,6 +197,7 @@ func (p *ec2ProviderImpl) GetPrivateDNSName(id string) (string, error) {
}

logrus.Infof("Calling ec2:DescribeInstances for the InstanceId = %s ", id)
p.authenticatorMetrics.EC2DescribeInstanceCallCount.Inc()
// Look up instance from EC2 API
output, err := p.ec2.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: aws.StringSlice([]string{id}),
Expand Down Expand Up @@ -254,6 +259,7 @@ func (p *ec2ProviderImpl) StartEc2DescribeBatchProcessing() {
func (p *ec2ProviderImpl) getPrivateDnsAndPublishToCache(instanceIdList []string) {
// Look up instance from EC2 API
logrus.Infof("Making Batch Query to DescribeInstances for %v instances ", len(instanceIdList))
p.authenticatorMetrics.EC2DescribeInstanceCallCount.Inc()
output, err := p.ec2.DescribeInstances(&ec2.DescribeInstancesInput{
InstanceIds: aws.StringSlice(instanceIdList),
})
Expand Down
12 changes: 10 additions & 2 deletions pkg/metrics/metrics.go
Expand Up @@ -26,8 +26,9 @@ func Get() Metrics {

// Metrics are handles to the collectors for prometheus for the various metrics we are tracking.
type Metrics struct {
ConfigMapWatchFailures prometheus.Counter
Latency *prometheus.HistogramVec
ConfigMapWatchFailures prometheus.Counter
Latency *prometheus.HistogramVec
EC2DescribeInstanceCallCount prometheus.Counter
}

func CreateMetrics(reg prometheus.Registerer) Metrics {
Expand All @@ -49,5 +50,12 @@ func CreateMetrics(reg prometheus.Registerer) Metrics {
},
[]string{"result"},
),
EC2DescribeInstanceCallCount: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "ec2_describe_instances_call",
Help: "Number of EC2 describe instances calls.",
},
),
}
}

0 comments on commit 264a477

Please sign in to comment.