Skip to content

Commit

Permalink
Add metrics to acs for eni provisioning workflow monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Cheng authored and chacheng21 committed Dec 11, 2024
1 parent 7a2750b commit 9410bbf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 1 addition & 2 deletions ecs-agent/acs/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,7 @@ func (s *session) startSessionOnce(ctx context.Context) error {
s.firstDiscoverPollEndpointTime = time.Now()
}

discoverPollEndpointMetric := s.metricsFactory.New(metrics.ACSDiscoverPollEndpointDurationName)
acsEndpoint, err := s.ecsClient.DiscoverPollEndpoint(s.containerInstanceARN)
discoverPollEndpointMetric.Done(err)

if err != nil {
logger.Error("ACS: Unable to discover poll endpoint", logger.Fields{
Expand All @@ -253,6 +251,7 @@ func (s *session) startSessionOnce(ctx context.Context) error {
})
return err
}
s.metricsFactory.New(metrics.DiscoverPollEndpointDurationName).WithGauge(s.ecsClient.GetDiscoverPollEndpointDuration()).Done(nil)

client := s.clientFactory.New(
s.acsURL(acsEndpoint),
Expand Down
8 changes: 7 additions & 1 deletion ecs-agent/api/ecs/client/ecs_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type ecsClient struct {
shouldExcludeIPv6PortBinding bool
sascCustomRetryBackoff func(func() error) error
stscAttachmentCustomRetryBackoff func(func() error) error
discoverPollEndpointDuration time.Duration
}

// NewECSClient creates a new ECSClient interface object.
Expand Down Expand Up @@ -747,7 +748,7 @@ func (client *ecsClient) discoverPollEndpoint(containerInstanceArn string,
}
}
}

discoverPollEndpointStartTime := time.Now()
// Cache miss or expired, invoke the ECS DiscoverPollEndpoint API.
logger.Debug("Invoking DiscoverPollEndpoint", logger.Fields{
field.ContainerInstanceARN: containerInstanceArn,
Expand Down Expand Up @@ -777,6 +778,7 @@ func (client *ecsClient) discoverPollEndpoint(containerInstanceArn string,
return nil, err
}

client.discoverPollEndpointDuration = time.Since(discoverPollEndpointStartTime)
// Cache the response from ECS.
client.pollEndpointCache.Set(containerInstanceArn, output)
return output, nil
Expand Down Expand Up @@ -870,3 +872,7 @@ func trimString(inputString string, maxLen int) string {
return inputString
}
}

func (client *ecsClient) GetDiscoverPollEndpointDuration() time.Duration {
return client.discoverPollEndpointDuration
}
4 changes: 4 additions & 0 deletions ecs-agent/api/ecs/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
package ecs

import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"

Expand Down Expand Up @@ -62,6 +64,8 @@ type ECSClient interface {
UpdateContainerInstancesState(instanceARN, status string) error
// GetHostResources retrieves a map that map the resource name to the corresponding resource
GetHostResources() (map[string]*ecs.Resource, error)
// GetDiscoverPollEndpointDuration retrieves the time it takes for the DiscoverPollEndpoint call
GetDiscoverPollEndpointDuration() time.Duration
}

// ECSSDK is an interface that specifies the subset of the AWS Go SDK's ECS
Expand Down
6 changes: 3 additions & 3 deletions ecs-agent/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ const (
TCSDisconnectTimeoutMetricName = agentAvailabilityNamespace + ".TCSDisconnectTimeout"

// ACS Session Metrics
acsStartSessionNamespace = "ACSStartSession"
ACSDiscoverPollEndpointDurationName = acsStartSessionNamespace + ".DiscoverPollEndpointDuration"
ACSConnectionMetricDurationName = acsStartSessionNamespace + ".ACSConnectEndpointDuration"
acsStartSessionNamespace = "ACSStartSession"
DiscoverPollEndpointDurationName = acsStartSessionNamespace + ".DiscoverPollEndpointDuration"
ACSConnectionMetricDurationName = acsStartSessionNamespace + ".ACSConnectEndpointDuration"

dbClientMetricNamespace = "Data"
GetNetworkConfigurationByTaskMetricName = dbClientMetricNamespace + ".GetNetworkConfigurationByTask"
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/aws/amazon-ecs-agent/ecs-agent

go 1.22.7

0 comments on commit 9410bbf

Please sign in to comment.