Skip to content

Commit 9999b1d

Browse files
authored
Always publish Service Connect Metrics (#3786)
1 parent 255ed43 commit 9999b1d

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

agent/stats/engine.go

+15-4
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,9 @@ func (engine *DockerStatsEngine) StartMetricsPublish() {
461461
select {
462462
case <-engine.publishMetricsTicker.C:
463463
seelog.Debugf("publishMetricsTicker triggered. Sending telemetry messages to tcsClient through channel")
464+
if includeServiceConnectStats {
465+
seelog.Debugf("service connect metrics included")
466+
}
464467
go engine.publishMetrics(includeServiceConnectStats)
465468
go engine.publishHealth()
466469
case <-engine.ctx.Done():
@@ -543,16 +546,22 @@ func (engine *DockerStatsEngine) GetInstanceMetrics(includeServiceConnectStats b
543546
containerMetrics, err := engine.taskContainerMetricsUnsafe(taskArn)
544547
if err != nil {
545548
seelog.Debugf("Error getting container metrics for task: %s, err: %v", taskArn, err)
546-
// skip collecting service connect related metrics, if task is not service connect enabled
547-
if !isServiceConnectTask {
549+
// skip collecting service connect related metrics, if task is not service connect enabled.
550+
// when task metrics and health metrics are both disabled and there is a service connect task,
551+
// and we should not include service connect this time, we also need to skip following execution
552+
// to avoid invalid metrics sent to TCS
553+
if !isServiceConnectTask || !includeServiceConnectStats {
548554
continue
549555
}
550556
}
551557

552558
if len(containerMetrics) == 0 {
553559
seelog.Debugf("Empty containerMetrics for task, ignoring, task: %s", taskArn)
554-
// skip collecting service connect related metrics, if task is not service connect enabled
555-
if !isServiceConnectTask {
560+
// skip collecting service connect related metrics, if task is not service connect enabled.
561+
// when task metrics and health metrics are both disabled and there is a service connect task,
562+
// and we should not include service connect this time, we also need to skip following execution
563+
// to avoid invalid metrics sent to TCS
564+
if !isServiceConnectTask || !includeServiceConnectStats {
556565
continue
557566
}
558567
}
@@ -575,6 +584,7 @@ func (engine *DockerStatsEngine) GetInstanceMetrics(includeServiceConnectStats b
575584
if serviceConnectStats, ok := engine.taskToServiceConnectStats[taskArn]; ok {
576585
if !serviceConnectStats.HasStatsBeenSent() {
577586
taskMetric.ServiceConnectMetricsWrapper = serviceConnectStats.GetStats()
587+
seelog.Debugf("Adding service connect stats for task : %s", taskArn)
578588
serviceConnectStats.SetStatsSent(true)
579589
}
580590
}
@@ -584,6 +594,7 @@ func (engine *DockerStatsEngine) GetInstanceMetrics(includeServiceConnectStats b
584594

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

agent/stats/reporter/reporter.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ func NewDockerTelemetrySession(
7373
return nil, cfgParseErr
7474
}
7575
if ok {
76-
logger.Warn("Metrics were disabled, not starting the telemetry session")
77-
return nil, nil
76+
logger.Warn("Both metrics and health were disabled, but still starting the telemetry session for service connect metrics")
7877
}
7978

8079
agentVersion, agentHash, containerRuntimeVersion := generateVersionInfo(taskEngine)

agent/stats/reporter/reporter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestNewDockerTelemetrySession(t *testing.T) {
4242
ctrl := gomock.NewController(t)
4343
defer ctrl.Finish()
4444
mockEngine := mock_engine.NewMockTaskEngine(ctrl)
45-
mockEngine.EXPECT().Version().Return(testDockerVersion, nil)
45+
mockEngine.EXPECT().Version().Return(testDockerVersion, nil).AnyTimes()
4646
testCases := []struct {
4747
name string
4848
cfg *config.Config
@@ -82,7 +82,7 @@ func TestNewDockerTelemetrySession(t *testing.T) {
8282
AcceptInsecureCert: false,
8383
DockerEndpoint: testDockerEndpoint,
8484
},
85-
expectedSession: false,
85+
expectedSession: true,
8686
expectedError: false,
8787
},
8888
}

0 commit comments

Comments
 (0)