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

postgres: template file renders invalid file in some cases #379

Closed
theckman opened this issue Nov 13, 2016 · 0 comments
Closed

postgres: template file renders invalid file in some cases #379

theckman opened this issue Nov 13, 2016 · 0 comments

Comments

@theckman
Copy link

theckman commented Nov 13, 2016

Hello,

I've run in to some issues with the template file used to render the check.d configuration for Postgres. Specifically, the file is unpacking the attributes (by hand) in to YAML. Unfortunately, there are a few cases where this file is doing the wrong thing.

The first issue I ran in to is that when using the relations attribute (Array), the template expects each entry to be a string[1]. This is at odds with the spec because a relation can be defined like so:

relations:
  - relation_name: table
    schemas:
      - a
      - b

Trying to use an Array of Hashes gives me:

relations:
  - {"relation_name"=>"table","schemas"=>["a","b"]}

The second issue is that the template doesn't allow the descriptors to be an empty array[2], and omitting the key is a error according to dd-agent info. If you try to provide an empty Array for descriptors, and assuming relation is false, it renders the file as such which triggers a parsing error:

descriptors:
relation: false

I'd expect it to render like this:

descriptors: []
relation: false

My suggested fix would be to change templates/default/postgres.yaml.erb to use .to_yaml to render the specific keys and avoid trying to manually unpack attributes in to YAML:

# .to_a is used to convert the attributes so that they don't marshal custom tags
<%= { "init_config" => {}, "instances" => @instances.to_a }.to_yaml %>

Unfortunately, the template that's being rendered does some things that alter attributes to provide the correct key name[3] or provide a default value[4]. This means changing this file to use .to_yaml would introduce breaking changes.

To mitigate one of these concerns, one option would be that we can patch dd-agent to default to port 5432[5] (as well as default to localhost while we're there too).

That still leaves the host => server mismatch[3] as a breaking change. To mitigate that, we could update the postgres recipe to iterate over the instances and munge the values to either set defaults or map the names to the right values. But this feels gross to me.

What do you think? In theory, what would be needed to release a breaking change and how long would it take to see a release contain the changes?

[1] github.com/DataDog/chef-datadog/templates/default/postgres.yaml.erb#L23-L26
[2] github.com/DataDog/chef-datadog/templates/default/postgres.yaml.erb#L43-L46
[3] github.com/DataDog/chef-datadog/templates/default/postgres.yaml.erb#L6
[4] github.com/DataDog/chef-datadog/templates/default/postgres.yaml.erb#L7
[5] github.com/DataDog/dd-agent/checks.d/postgres.py#L661

miketheman added a commit that referenced this issue Nov 13, 2016
Converts the postgres template to using the "simpler" rendering
solution, instead of manually unpacking positional values in YAML.

Using in-template replacement logic, we can modify the values in-place
at the time of rendering.
This does increase memory overhead slightly, as the `instances` object
is copied once, as it starts out as a `Chef::ImmutableArray` that prevents
modification.

- Adds spec tests for specific uses brought up in #379.
- Updates in-recipe documentation to show that one can use either
`server` or `host` values
- Removes a breaking change TODO

Resolves #379

Signed-off-by: Mike Fiedler <miketheman@gmail.com>
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

No branches or pull requests

1 participant