Skip to content

Commit

Permalink
Always publish Service Connect Metrics (#3786)
Browse files Browse the repository at this point in the history
  • Loading branch information
Realmonia authored Jul 13, 2023
1 parent 255ed43 commit 9999b1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
19 changes: 15 additions & 4 deletions agent/stats/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ func (engine *DockerStatsEngine) StartMetricsPublish() {
select {
case <-engine.publishMetricsTicker.C:
seelog.Debugf("publishMetricsTicker triggered. Sending telemetry messages to tcsClient through channel")
if includeServiceConnectStats {
seelog.Debugf("service connect metrics included")
}
go engine.publishMetrics(includeServiceConnectStats)
go engine.publishHealth()
case <-engine.ctx.Done():
Expand Down Expand Up @@ -543,16 +546,22 @@ func (engine *DockerStatsEngine) GetInstanceMetrics(includeServiceConnectStats b
containerMetrics, err := engine.taskContainerMetricsUnsafe(taskArn)
if err != nil {
seelog.Debugf("Error getting container metrics for task: %s, err: %v", taskArn, err)
// skip collecting service connect related metrics, if task is not service connect enabled
if !isServiceConnectTask {
// skip collecting service connect related metrics, if task is not service connect enabled.
// when task metrics and health metrics are both disabled and there is a service connect task,
// and we should not include service connect this time, we also need to skip following execution
// to avoid invalid metrics sent to TCS
if !isServiceConnectTask || !includeServiceConnectStats {
continue
}
}

if len(containerMetrics) == 0 {
seelog.Debugf("Empty containerMetrics for task, ignoring, task: %s", taskArn)
// skip collecting service connect related metrics, if task is not service connect enabled
if !isServiceConnectTask {
// skip collecting service connect related metrics, if task is not service connect enabled.
// when task metrics and health metrics are both disabled and there is a service connect task,
// and we should not include service connect this time, we also need to skip following execution
// to avoid invalid metrics sent to TCS
if !isServiceConnectTask || !includeServiceConnectStats {
continue
}
}
Expand All @@ -575,6 +584,7 @@ func (engine *DockerStatsEngine) GetInstanceMetrics(includeServiceConnectStats b
if serviceConnectStats, ok := engine.taskToServiceConnectStats[taskArn]; ok {
if !serviceConnectStats.HasStatsBeenSent() {
taskMetric.ServiceConnectMetricsWrapper = serviceConnectStats.GetStats()
seelog.Debugf("Adding service connect stats for task : %s", taskArn)
serviceConnectStats.SetStatsSent(true)
}
}
Expand All @@ -584,6 +594,7 @@ func (engine *DockerStatsEngine) GetInstanceMetrics(includeServiceConnectStats b

if len(taskMetrics) == 0 {
// Not idle. Expect taskMetrics to be there.
seelog.Debugf("Return empty metrics error")
return nil, nil, EmptyMetricsError
}

Expand Down
3 changes: 1 addition & 2 deletions agent/stats/reporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ func NewDockerTelemetrySession(
return nil, cfgParseErr
}
if ok {
logger.Warn("Metrics were disabled, not starting the telemetry session")
return nil, nil
logger.Warn("Both metrics and health were disabled, but still starting the telemetry session for service connect metrics")
}

agentVersion, agentHash, containerRuntimeVersion := generateVersionInfo(taskEngine)
Expand Down
4 changes: 2 additions & 2 deletions agent/stats/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestNewDockerTelemetrySession(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
mockEngine := mock_engine.NewMockTaskEngine(ctrl)
mockEngine.EXPECT().Version().Return(testDockerVersion, nil)
mockEngine.EXPECT().Version().Return(testDockerVersion, nil).AnyTimes()
testCases := []struct {
name string
cfg *config.Config
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestNewDockerTelemetrySession(t *testing.T) {
AcceptInsecureCert: false,
DockerEndpoint: testDockerEndpoint,
},
expectedSession: false,
expectedSession: true,
expectedError: false,
},
}
Expand Down

0 comments on commit 9999b1d

Please sign in to comment.