Skip to content

Commit f65b6ad

Browse files
Make X-Ray telemetry opt-in (#15)
1 parent bede0a0 commit f65b6ad

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

cmd/localstack/main.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ import (
1515
)
1616

1717
type LsOpts struct {
18-
InteropPort string
19-
RuntimeEndpoint string
20-
RuntimeId string
21-
InitTracingPort string
22-
User string
23-
CodeArchives string
24-
HotReloadingPaths []string
25-
EnableDnsServer string
26-
LocalstackIP string
27-
InitLogLevel string
28-
EdgePort string
18+
InteropPort string
19+
RuntimeEndpoint string
20+
RuntimeId string
21+
InitTracingPort string
22+
User string
23+
CodeArchives string
24+
HotReloadingPaths []string
25+
EnableDnsServer string
26+
LocalstackIP string
27+
InitLogLevel string
28+
EdgePort string
29+
EnableXRayTelemetry string
2930
}
3031

3132
func GetEnvOrDie(env string) string {
@@ -48,10 +49,11 @@ func InitLsOpts() *LsOpts {
4849
InitLogLevel: GetenvWithDefault("LOCALSTACK_INIT_LOG_LEVEL", "debug"),
4950
EdgePort: GetenvWithDefault("EDGE_PORT", "4566"),
5051
// optional or empty
51-
CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"),
52-
HotReloadingPaths: strings.Split(GetenvWithDefault("LOCALSTACK_HOT_RELOADING_PATHS", ""), ","),
53-
EnableDnsServer: os.Getenv("LOCALSTACK_ENABLE_DNS_SERVER"),
54-
LocalstackIP: os.Getenv("LOCALSTACK_HOSTNAME"),
52+
CodeArchives: os.Getenv("LOCALSTACK_CODE_ARCHIVES"),
53+
HotReloadingPaths: strings.Split(GetenvWithDefault("LOCALSTACK_HOT_RELOADING_PATHS", ""), ","),
54+
EnableDnsServer: os.Getenv("LOCALSTACK_ENABLE_DNS_SERVER"),
55+
EnableXRayTelemetry: os.Getenv("LOCALSTACK_ENABLE_XRAY_TELEMETRY"),
56+
LocalstackIP: os.Getenv("LOCALSTACK_HOSTNAME"),
5557
}
5658
}
5759

@@ -67,6 +69,7 @@ func UnsetLsEnvs() {
6769
"LOCALSTACK_CODE_ARCHIVES",
6870
"LOCALSTACK_HOT_RELOADING_PATHS",
6971
"LOCALSTACK_ENABLE_DNS_SERVER",
72+
"LOCALSTACK_ENABLE_XRAY_TELEMETRY",
7073
"LOCALSTACK_INIT_LOG_LEVEL",
7174
// Docker container ID
7275
"HOSTNAME",
@@ -146,7 +149,7 @@ func main() {
146149

147150
// xray daemon
148151
xrayConfig := initConfig("http://" + lsOpts.LocalstackIP + ":" + lsOpts.EdgePort)
149-
d := initDaemon(xrayConfig)
152+
d := initDaemon(xrayConfig, lsOpts.EnableXRayTelemetry == "1")
150153
sandbox.AddShutdownFunc(func() {
151154
log.Debugln("Shutting down xray daemon")
152155
d.stop()

cmd/localstack/xraydaemon.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func initConfig(endpoint string) *cfg.Config {
8585
return xrayConfig
8686
}
8787

88-
func initDaemon(config *cfg.Config) *Daemon {
88+
func initDaemon(config *cfg.Config, enableTelemetry bool) *Daemon {
8989
if logFile != "" {
9090
var fileWriter io.Writer
9191
if *config.Logging.LogRotation {
@@ -133,8 +133,9 @@ func initDaemon(config *cfg.Config) *Daemon {
133133
awsConfig, session := conn.GetAWSConfigSession(&conn.Conn{}, config, config.RoleARN, config.Region, noMetadata)
134134
log.Infof("Using region: %v", aws.StringValue(awsConfig.Region))
135135

136-
log.Debugf("ARN of the AWS resource running the daemon: %v", config.ResourceARN)
137-
telemetry.Init(awsConfig, session, config.ResourceARN, noMetadata)
136+
if enableTelemetry {
137+
telemetry.Init(awsConfig, session, config.ResourceARN, noMetadata)
138+
}
138139

139140
// If calculated number of buffer is lower than our default, use calculated one. Otherwise, use default value.
140141
parameterConfig.Processor.BatchSize = util.GetMinIntValue(parameterConfig.Processor.BatchSize, buffers)
@@ -179,10 +180,14 @@ func (d *Daemon) close() {
179180
// Signal routines to finish
180181
// This will push telemetry and customer segments in parallel
181182
d.std.Close()
182-
telemetry.T.Quit <- true
183+
if telemetry.T != nil {
184+
telemetry.T.Quit <- true
185+
}
183186

184187
<-d.processor.Done
185-
<-telemetry.T.Done
188+
if telemetry.T != nil {
189+
<-telemetry.T.Done
190+
}
186191

187192
log.Debugf("Trace segment: received: %d, truncated: %d, processed: %d", atomic.LoadUint64(&d.count), d.std.TruncatedCount(), d.processor.ProcessedCount())
188193
log.Debugf("Shutdown finished. Current epoch in nanoseconds: %v", time.Now().UnixNano())
@@ -226,7 +231,7 @@ func (d *Daemon) poll() {
226231
fallbackPointerUsed = true
227232
}
228233
rlen := d.read(bufPointer)
229-
if rlen > 0 {
234+
if rlen > 0 && telemetry.T != nil {
230235
telemetry.T.SegmentReceived(1)
231236
}
232237
if rlen == 0 {
@@ -237,7 +242,9 @@ func (d *Daemon) poll() {
237242
}
238243
if fallbackPointerUsed {
239244
log.Warn("Segment dropped. Consider increasing memory limit")
240-
telemetry.T.SegmentSpillover(1)
245+
if telemetry.T != nil {
246+
telemetry.T.SegmentSpillover(1)
247+
}
241248
continue
242249
} else if rlen == -1 {
243250
return
@@ -250,7 +257,9 @@ func (d *Daemon) poll() {
250257
if len(slices[1]) == 0 {
251258
log.Warnf("Missing header or segment: %s", string(slices[0]))
252259
d.pool.Return(bufPointer)
253-
telemetry.T.SegmentRejected(1)
260+
if telemetry.T != nil {
261+
telemetry.T.SegmentRejected(1)
262+
}
254263
continue
255264
}
256265

@@ -264,7 +273,9 @@ func (d *Daemon) poll() {
264273
default:
265274
log.Warnf("Invalid header: %s", string(header))
266275
d.pool.Return(bufPointer)
267-
telemetry.T.SegmentRejected(1)
276+
if telemetry.T != nil {
277+
telemetry.T.SegmentRejected(1)
278+
}
268279
continue
269280
}
270281

0 commit comments

Comments
 (0)