Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always report service connect metrics when both health and task metrics are disabled #3786

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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