Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pillar] Revamp pillar file structure & allow arbitrary keys in datadog.yaml #35

Merged
merged 3 commits into from
Oct 1, 2019

Conversation

KSerrania
Copy link
Contributor

@KSerrania KSerrania commented Sep 9, 2019

What does this PR do?

Separates the root pillar object datadog into two sub-objects:

  • config, which describes the contents of the datadog.yaml config file that will be installed on the minions,
  • install_settings, which contains various customisable parameters for the Agent install, such as the Agent version.

With this new structure, any arbitrary key can be put in config.
For now, what's in config is simply written in the datadog.yaml file, but making modifications before writing the file could also be possible in the future (if we want to check fields, for example).

Note: Agent 5 is using a .ini config file, and there's no ini renderer available easily, so we're using the old way with explicitly supported options (except a little cleaner: we're not matching regexes in a file we don't have control of). To comply with what was previously supported on Agent 5 on SaltStack, the api_key option is supported for now.

Motivation

Right now, to add a new option to the config, we need to explicitly add it to the datadog/config.sls state file to support it. Moreover, the way we're doing it is not satisfying: we take the file that's present on the minion (which can possibly be anything), and we match regexes to find the option and replace the corresponding line in the file (which can fail if the user manually changed the file).

Additional Notes

This is a breaking change, as the current pillar structure will not work anymore.

…og.yaml

Separates the root pillar object 'datadog' into two sub-objects:
- "config", which describes the contents of the datadog.yaml config file
that will be installed on the minions,
- "install_settings", which contains various customizable parameters
for the Agent install, such as the Agent version.

With this new structure, any arbitrary key can be put in "config",
and will be reflected in the minions' config files.
'install_settings': {
'agent_version': 'latest',
'pkg_name': 'datadog-agent',
'service_name': 'datadog-agent',
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense for pkg_name and service_name to be overridable by the user? I would remove them from here and just hardcode them (otherwise, we should document them?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were here when I started maintaining the repo, but I agree that they should be hardcoded. But I didn't want to mix the cleanup of the repo with this change ; I'll do the cleanup in another PR

{%- endif %}
{% endif %}

{% if 'checks_confd' not in datadog_settings %}
{% if 'checks_confd' not in datadog_install_settings %}
Copy link
Contributor

Choose a reason for hiding this comment

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

For config_folder and config_file I think the same as above: I don't see why the user would need to override them.

For checks_confd, this field overlaps with confd_path in datadog_config (which is read by the agent), so I wonder if we should merge them (otherwise, the user needs to change both)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above: I'll get rid of config_folder and config_file in a separate cleanup PR (they should not be used: if you use them, SaltStack will put the datadog.yaml file there, and the Agent will never find it, failing Agent starts).

For checks_confd, I have another planned change (after this PR is done) to make it use confd_path

@KSerrania KSerrania force-pushed the kserrania/revamp-pillar branch 5 times, most recently from 6be58c7 to 9217690 Compare September 30, 2019 13:53
{% set config_file_path = '%s/%s'|format(datadog_install_settings.config_folder, datadog_install_settings.config_file) -%}

{%- if not latest_agent_version and parsed_version[1] == '5' %}
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be parsed_version[0]?

Copy link
Contributor Author

@KSerrania KSerrania Oct 1, 2019

Choose a reason for hiding this comment

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

parsed_version[0] contains the full match of the regex defined here: https://github.com/DataDog/datadog-formula/pull/35/files#diff-541c639658b352ec59d46a0868aa02d2R35
parsed_version[1] contains the first capture group, which is the major version number

@@ -0,0 +1,10 @@
{% from "datadog/map.jinja" import datadog_config with context -%}

[Main]
Copy link
Contributor

@albertvaka albertvaka Oct 1, 2019

Choose a reason for hiding this comment

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

How was agent 5 working before without this file? :o

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We took the example file that the package provides (or the datadog.conf file directly if it exists on the host already), and replaced the fields we wanted to change using regexes. But this is error-prone, we relied on fields being present on the config file (which may not be the case if it was modified by the user)

@KSerrania KSerrania changed the base branch from master to 3.x October 1, 2019 13:33
@KSerrania KSerrania merged commit 6140a54 into 3.x Oct 1, 2019
@KSerrania KSerrania deleted the kserrania/revamp-pillar branch October 1, 2019 13:34
@KSerrania KSerrania mentioned this pull request Nov 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants