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

cmd/trace-agent: default to YAML config #435

Merged
merged 8 commits into from Jun 21, 2018
Merged

cmd/trace-agent: default to YAML config #435

merged 8 commits into from Jun 21, 2018

Conversation

gbbr
Copy link
Contributor

@gbbr gbbr commented Jun 18, 2018

  • Small refactor of configuration code
  • Adds packages flags and osutil
  • Always default to Agent YAML config unless it's not there and we have a legacy config available.

@gbbr gbbr force-pushed the gbbr/update-conf branch 4 times, most recently from 904e9da to 10b5d86 Compare June 18, 2018 11:15
@gbbr gbbr requested a review from LotharSee June 18, 2018 11:24
@gbbr gbbr changed the title cmd/trace-agent: only default to INI file when it's the only option. cmd/trace-agent: default to YAML config Jun 18, 2018
@gbbr gbbr added this to the next milestone Jun 19, 2018
// command-line arguments
// TODO: load from the .yaml automatically if there
flag.StringVar(&opts.configFile, "config", "/etc/dd-agent/datadog.conf", "Datadog Agent config file location")
flag.StringVar(&opts.legacyConfigFile, "ddconfig", "/etc/dd-agent/trace-agent.ini", "Deprecated extra configuration option.")
Copy link

@LotharSee LotharSee Jun 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for context, the ddconfig config is from before the packaging with the Agent 5 (when the trace-agent was its own .deb) ; so it should be fair to remove it.

However, we will want to also remove the whole logic which goes with opts.legacyConfigFile.

@gbbr gbbr force-pushed the gbbr/update-conf branch 7 times, most recently from 1618606 to eb82541 Compare June 19, 2018 19:59
@@ -113,7 +113,6 @@ func NewAgent(ctx context.Context, conf *config.AgentConfig) *Agent {
conf: conf,
dynConf: dynConf,
ctx: ctx,
die: die,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed something, but how could a.die

a.die("exceeded max memory (current=%d, max=%d)", wi.Mem.Alloc, int64(a.conf.MaxMemory))
work without this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know! This is weird!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.

config/agent.go Outdated
func NewAgentConfig(conf *File, legacyConf *File, agentYaml *YamlAgentConfig) (*AgentConfig, error) {
c := NewDefaultAgentConfig()
var err error
const legacyConfigFile = "/etc/dd-agent/datadog.conf"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's call it agent5 something of legacy, as it'd help understand it is still legit/relevant.
  • Windows need a different value. We could however avoid implementing this specific case by just checking how we package the Agent5 on Windows today and if it comes with the -config option.

config/agent.go Outdated
err = mergeIniConfig(c, conf)
// validate validates the given configuration, filling in any missing defaults
// and merging any environment variables into it.
func validate(c *AgentConfig) (*AgentConfig, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd expect validate to only deal with errors/defaults and not the mergeEnv, as this is a real feature more than a simple validation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agree, this is confusing. It's just a temporary mid-refactor stage. Wasn't sure what to do with these yet.

@gbbr
Copy link
Contributor Author

gbbr commented Jun 20, 2018

Thanks! All your comments are valid and I will address them. Note that I’ve marked the PR as WIP. In case it’s spamming you, you might want to unsubscribe until it’s ready for review. Otherwise, all comments are always welcome!

@gbbr gbbr force-pushed the gbbr/update-conf branch 9 times, most recently from bbd0707 to 16d5061 Compare June 20, 2018 09:40
gbbr added 4 commits June 20, 2018 11:58
This change marks the INI configuration as deprecated and defaults the
trace agent configuration to the YAML one. It also removes the
previously deprecated `-ddconfig` flag (in version 5).
@gbbr gbbr force-pushed the gbbr/update-conf branch 6 times, most recently from b369a13 to bf24147 Compare June 20, 2018 10:14
@gbbr gbbr requested a review from truthbk June 20, 2018 10:16
@gbbr
Copy link
Contributor Author

gbbr commented Jun 20, 2018

@truthbk added you to check the following:

  • (config/agent.go).Load to confirm that the new settings are backwards compatible. They should be.
  • (config/agent.go).(*AgentConfig).acquireHostname for removing the Python shell code.

config/agent.go Outdated
ErrMissingHostname = errors.New("failed to automatically set the hostname, you must specify it via configuration for or the DD_HOSTNAME env var")
)

const (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move these to merge_env.go to make it more readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Done.

Copy link
Member

@truthbk truthbk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just added a note regarding one of the error messages, but feel free to ignore.

config/agent.go Outdated
}
c.HostName = hostname
default:
return cfg, errors.New("unrecognised file extension (need .yaml)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand you're trying to deprecate .ini, .conf extensions, but this might be a little confusing since ini and conf extensions are actually supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Done.

@gbbr gbbr merged commit c269811 into master Jun 21, 2018
@gbbr gbbr deleted the gbbr/update-conf branch June 21, 2018 06:41
gbbr added a commit that referenced this pull request Jul 12, 2018
* cmd/trace-agent: refactor config and default to yaml (with fallback)

This change marks the INI configuration as deprecated and defaults the
trace agent configuration to the YAML one. It also removes the
previously deprecated `-ddconfig` flag (in version 5).

* cmd/trace-agent: minimize init() functions and factor out shared flags.
* fallback to legacy config if it's the only option
* osutil, flags: add new packages to separate concerns.
* config: improve config package.
* move env constants to merge_env.go
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants