Skip to content

Commit

Permalink
Add metrics for DiscoverPollEndpoint and ACSSession
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and BinBin He committed Dec 23, 2024
1 parent 01caac7 commit 66d1d3a
Show file tree
Hide file tree
Showing 10 changed files with 229 additions and 7 deletions.

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.

17 changes: 16 additions & 1 deletion ecs-agent/acs/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
Expand Down Expand Up @@ -99,6 +99,7 @@ type session struct {
disconnectJitter time.Duration
inactiveInstanceReconnectDelay time.Duration
lastConnectedTime time.Time
firstACSConnectionTime time.Time
}

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

Expand Down Expand Up @@ -253,17 +255,26 @@ 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.
acsConnectionStartTime := time.Now()
disconnectTimer, err := client.Connect(metrics.ACSDisconnectTimeoutMetricName, s.disconnectTimeout,
s.disconnectJitter)

// Metric created for determining whether ACS connection is successful or not
s.metricsFactory.New(metrics.ACSSessionCallName).Done(err)
if err != nil {
logger.Error("Failed to connect to ACS", logger.Fields{
"containerInstanceARN": s.containerInstanceARN,
field.Error: err,
})
return err
}
s.metricsFactory.New(metrics.ACSSessionCallDurationName).WithGauge(time.Since(acsConnectionStartTime)).Done(nil)
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 +486,7 @@ func formatDockerVersion(dockerVersionValue string) string {
func (s *session) GetLastConnectedTime() time.Time {
return s.lastConnectedTime
}

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

0 comments on commit 66d1d3a

Please sign in to comment.