Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

config: use shared config for loading Agent 5 paths #528

Merged
merged 7 commits into from
Nov 26, 2018
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
977 changes: 966 additions & 11 deletions Gopkg.lock

Large diffs are not rendered by default.

18 changes: 4 additions & 14 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,6 @@
name = "github.com/cihub/seelog"
version = "2.6.0"

[[constraint]]
name = "github.com/go-ini/ini"
version = "1.25.2"

[[constraint]]
name = "github.com/gogo/protobuf"
revision = "d76fbc1373015ced59b43ac267f28d546b955683"

[[constraint]]
name = "github.com/shirou/gopsutil"
version = "2.17.1"
Expand All @@ -40,10 +32,8 @@
name = "github.com/stretchr/testify"
version = "1.2.1"

[[constraint]]
name = "gopkg.in/yaml.v2"
revision = "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b"

# conflicts with datadog-agent:
[[override]]
name = "gopkg.in/yaml.v2"
revision = "d670f9405373e636a5a2765eea47fac0c9bc91a4"
name = "github.com/gogo/protobuf"
revision = "d76fbc1373015ced59b43ac267f28d546b955683"

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ binaries:

ci:
# task used by CI
GOOS=windows go build ./cmd/trace-agent # ensure windows builds
# will no longer cross-compile due to cgo:
# GOOS=windows go build ./cmd/trace-agent # ensure windows builds
go get -u golang.org/x/lint/golint
golint -set_exit_status=1 ./cmd/trace-agent ./filters ./api ./testutil ./info ./quantile ./obfuscate ./sampler ./statsd ./watchdog ./writer ./flags ./osutil
INTEGRATION=1 go test -v -race ./...
Expand Down
29 changes: 14 additions & 15 deletions config/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"strings"
"time"

"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/config/legacy"
"github.com/DataDog/datadog-trace-agent/flags"
"github.com/DataDog/datadog-trace-agent/osutil"
writerconfig "github.com/DataDog/datadog-trace-agent/writer/config"
Expand Down Expand Up @@ -144,22 +146,12 @@ func New() *AgentConfig {
MaxConnections: 200, // in practice, rarely goes over 20
WatchdogInterval: time.Minute,

Ignore: make(map[string][]string),
Ignore: make(map[string][]string),
AnalyzedRateByServiceLegacy: make(map[string]float64),
AnalyzedSpansByService: make(map[string]map[string]float64),
}
}

// LoadIni reads the contents of the given INI file into the config.
func (c *AgentConfig) LoadIni(path string) error {
conf, err := NewIni(path)
if err != nil {
return err
}
c.loadIniConfig(conf)
return nil
}

// Validate validates if the current configuration is good for the agent to start with.
func (c *AgentConfig) validate() error {
if len(c.Endpoints) == 0 || c.Endpoints[0].APIKey == "" {
Expand Down Expand Up @@ -213,19 +205,20 @@ func (c *AgentConfig) acquireHostname() error {
// and a valid configuration can be returned based on defaults and environment variables. If a
// valid configuration can not be obtained, an error is returned.
func Load(path string) (*AgentConfig, error) {
cfg, err := loadFile(path)
cfg, err := prepareConfig(path)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
} else {
log.Infof("Loaded configuration: %s", cfg.ConfigPath)
}
cfg.applyDatadogConfig()
cfg.loadEnv()
return cfg, cfg.validate()
}

func loadFile(path string) (*AgentConfig, error) {
func prepareConfig(path string) (*AgentConfig, error) {
cfgPath := path
if cfgPath == flags.DefaultConfigPath && !osutil.Exists(cfgPath) && osutil.Exists(agent5Config) {
// attempting to load inexistent default path, but found existing Agent 5
Expand All @@ -236,13 +229,19 @@ func loadFile(path string) (*AgentConfig, error) {
cfg := New()
switch filepath.Ext(cfgPath) {
case ".ini", ".conf":
if err := cfg.LoadIni(cfgPath); err != nil {
ac, err := legacy.GetAgentConfig(cfgPath)
if err != nil {
return cfg, err
}
if err := legacy.FromAgentConfig(ac); err != nil {
return cfg, err
}
case ".yaml":
if err := cfg.loadYamlConfig(cfgPath); err != nil {
config.Datadog.SetConfigFile(cfgPath)
if err := config.Load(); err != nil {
return cfg, err
}
cfg.DDAgentBin = defaultDDAgentBin
default:
return cfg, errors.New("unrecognised file extension (need .yaml, .ini or .conf)")
}
Expand Down
Loading