Skip to content

Commit

Permalink
Add latency metrics for DiscoverPollEndpoint and ACS
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles Cheng committed Dec 12, 2024
1 parent dd3ad7e commit 745cd40
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions ecs-agent/acs/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ type session struct {
disconnectJitter time.Duration
inactiveInstanceReconnectDelay time.Duration
lastConnectedTime time.Time
firstACSConnectionTime time.Time
firstDiscoverPollEndpointTime time.Time
}

// NewSession creates a new Session.
Expand Down Expand Up @@ -158,6 +160,8 @@ func NewSession(containerInstanceARN string,
disconnectJitter: wsclient.DisconnectJitterMax,
inactiveInstanceReconnectDelay: inactiveInstanceReconnectDelay,
lastConnectedTime: time.Time{},
firstACSConnectionTime: time.Time{},
firstDiscoverPollEndpointTime: time.Time{},
}
}

Expand Down Expand Up @@ -234,6 +238,10 @@ func (s *session) Start(ctx context.Context) error {
// startSessionOnce creates a session with ACS and handles requests using the passed
// in arguments.
func (s *session) startSessionOnce(ctx context.Context) error {
if s.GetFirstDiscoverPollEndpointTime().IsZero() {
s.firstDiscoverPollEndpointTime = time.Now()
}

acsEndpoint, err := s.ecsClient.DiscoverPollEndpoint(s.containerInstanceARN)
if err != nil {
logger.Error("ACS: Unable to discover poll endpoint", logger.Fields{
Expand All @@ -253,6 +261,7 @@ func (s *session) startSessionOnce(ctx context.Context) error {

// Invoke Connect method as soon as we create client. This will ensure all the
// request handlers to be associated with this client have a valid connection.
acsConnectionMetric := s.metricsFactory.New(metrics.ACSConnectionMetricDurationName)
disconnectTimer, err := client.Connect(metrics.ACSDisconnectTimeoutMetricName, s.disconnectTimeout,
s.disconnectJitter)
if err != nil {
Expand All @@ -262,8 +271,13 @@ func (s *session) startSessionOnce(ctx context.Context) error {
})
return err
}
acsConnectionMetric.Done(err)
defer disconnectTimer.Stop()

if s.GetFirstACSConnectionTime().IsZero() {
s.firstACSConnectionTime = time.Now()
}

// Record the timestamp of the last connection to ACS.
s.lastConnectedTime = time.Now()

Expand Down Expand Up @@ -475,3 +489,11 @@ func formatDockerVersion(dockerVersionValue string) string {
func (s *session) GetLastConnectedTime() time.Time {
return s.lastConnectedTime
}

func (s *session) GetFirstACSConnectionTime() time.Time {
return s.firstACSConnectionTime
}

func (s *session) GetFirstDiscoverPollEndpointTime() time.Time {
return s.firstDiscoverPollEndpointTime
}
Loading

0 comments on commit 745cd40

Please sign in to comment.