From c3779eca509c0b30943035c8a12384ac47d474eb Mon Sep 17 00:00:00 2001 From: Daniel Redondo Date: Mon, 4 May 2020 21:29:04 +0200 Subject: [PATCH] fix metadata data race --- agent/agent.go | 58 ++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 23d18dd9..c4425c41 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -329,6 +329,31 @@ func NewAgent(options ...Option) (*Agent, error) { } agent.metadata[tags.Capabilities] = capabilities + enableRemoteConfig := false + if env.ScopeRunnerEnabled.Value { + // runner is enabled + capabilities[tags.Capabilities_RunnerCache] = true + if env.ScopeRunnerIncludeBranches.Value == nil && env.ScopeRunnerExcludeBranches.Value == nil { + // both include and exclude branches are not defined + enableRemoteConfig = true + } else if iBranch, ok := agent.metadata[tags.Branch]; ok { + branch := iBranch.(string) + included := sliceContains(env.ScopeRunnerIncludeBranches.Value, branch) + excluded := sliceContains(env.ScopeRunnerExcludeBranches.Value, branch) + enableRemoteConfig = included // By default we use the value inside the include slice + if env.ScopeRunnerExcludeBranches.Value != nil { + if included && excluded { + // If appears in both slices, write in the logger and disable the runner configuration + agent.logger.Printf("The branch '%v' appears in both included and excluded branches. The branch will be excluded.", branch) + enableRemoteConfig = false + } else { + // We enable the remote config if is include or not excluded + enableRemoteConfig = included || !excluded + } + } + } + } + if !agent.testingMode { if env.ScopeTestingMode.IsSet { agent.testingMode = env.ScopeTestingMode.Value @@ -342,14 +367,15 @@ func NewAgent(options ...Option) (*Agent, error) { } agent.panicAsFail = agent.panicAsFail || env.ScopeTestingPanicAsFail.Value - if agent.debugMode { - agent.logMetadata() - } - agent.flushFrequency = nonTestingModeFrequency if agent.testingMode { agent.flushFrequency = testingModeFrequency } + + if agent.debugMode { + agent.logMetadata() + } + agent.recorder = NewSpanRecorder(agent) var recorder tracer.SpanRecorder = agent.recorder if agent.optionalRecorders != nil { @@ -369,30 +395,6 @@ func NewAgent(options ...Option) (*Agent, error) { instrumentation.SetTracer(agent.tracer) instrumentation.SetLogger(agent.logger) instrumentation.SetSourceRoot(sourceRoot) - enableRemoteConfig := false - if env.ScopeRunnerEnabled.Value { - // runner is enabled - capabilities[tags.Capabilities_RunnerCache] = true - if env.ScopeRunnerIncludeBranches.Value == nil && env.ScopeRunnerExcludeBranches.Value == nil { - // both include and exclude branches are not defined - enableRemoteConfig = true - } else if iBranch, ok := agent.metadata[tags.Branch]; ok { - branch := iBranch.(string) - included := sliceContains(env.ScopeRunnerIncludeBranches.Value, branch) - excluded := sliceContains(env.ScopeRunnerExcludeBranches.Value, branch) - enableRemoteConfig = included // By default we use the value inside the include slice - if env.ScopeRunnerExcludeBranches.Value != nil { - if included && excluded { - // If appears in both slices, write in the logger and disable the runner configuration - agent.logger.Printf("The branch '%v' appears in both included and excluded branches. The branch will be excluded.", branch) - enableRemoteConfig = false - } else { - // We enable the remote config if is include or not excluded - enableRemoteConfig = included || !excluded - } - } - } - } if enableRemoteConfig { instrumentation.SetRemoteConfiguration(agent.loadRemoteConfiguration()) }