Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Merged
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
58 changes: 30 additions & 28 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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())
}
Expand Down