Skip to content

Allow digging into fields of facts when they are a hash on old puppets#656

Merged
albertvaka merged 3 commits intomasterfrom
albertvaka/facts-dig
Oct 6, 2020
Merged

Allow digging into fields of facts when they are a hash on old puppets#656
albertvaka merged 3 commits intomasterfrom
albertvaka/facts-dig

Conversation

@albertvaka
Copy link
Copy Markdown
Contributor

@albertvaka albertvaka commented Oct 5, 2020

What does this PR do?

If a facts_to_tags tag looks like a hash path (eg: 'networking.domain'),
dig that path into the hash and use the inner value for the tag.

For backwards compatibility, if the name looks like a hash path
but there's a fact that's an exact string match (eg: there's a fact named
'networking.domain') then that will be used for the tag.

Note that on Puppet 6.0 and later getvar already behaves like this,
so this only makes it work on old Puppets.

Motivation

Feature request.

@albertvaka albertvaka requested a review from a team as a code owner October 5, 2020 16:31
@albertvaka albertvaka force-pushed the albertvaka/facts-dig branch 5 times, most recently from d5a251f to 35b5de1 Compare October 5, 2020 17:14
If a `facts_to_tags` tag looks like a hash path (eg: 'networking.domain'),
dig that path into the hash and use the inner value for the tag.

For backwards compatibility, if the name looks like a hash path
but there's a fact that's an exact string match (eg: there's a fact named
'networking.domain') then that will be used for the tag.
@albertvaka albertvaka force-pushed the albertvaka/facts-dig branch from 35b5de1 to 39d8c27 Compare October 5, 2020 17:26
@albertvaka albertvaka changed the title Allow digging into fields of facts when they are a hash Allow digging into fields of facts when they are a hash on old Puppet Oct 5, 2020
@albertvaka albertvaka changed the title Allow digging into fields of facts when they are a hash on old Puppet Allow digging into fields of facts when they are a hash Oct 5, 2020
@albertvaka albertvaka changed the title Allow digging into fields of facts when they are a hash Allow digging into fields of facts when they are a hash on old puppets Oct 5, 2020
agent_major_version: 6,
puppet_run_reports: true,
facts_to_tags: ['osfamily', 'facts_array'],
facts_to_tags: ['osfamily', 'facts_array', 'facts_hash.actor.first_name', 'looks.like.a.path'],
Copy link
Copy Markdown
Member

@mx-psi mx-psi Oct 6, 2020

Choose a reason for hiding this comment

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

What should the output be with something like facts_hash.path.like.key and:

'facts_hash' => {
  'path.like.key' => 'something',
},

? I am not sure what is it that we want in that case.

Docs say this should be referenced as 'facts_hash."path.like.key"'; we could add a test with that.

Copy link
Copy Markdown
Contributor Author

@albertvaka albertvaka Oct 6, 2020

Choose a reason for hiding this comment

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

In general, I would say that keys like path.like.key shouldn't be used... This PR handles this case only to not break backwards compatibility (in case someone is using weird keys like that), but I don't think we need to support every edge case down that rabbit hole. Otherwise..

'facts_hash' => {
  'path.like.key' => {
     "actual.hash" => "I'm evil"
  }
},

Docs say this should be referenced as 'facts_hash."path.like.key"'; we could add a test with that.

Which docs? That syntax doesn't work with the current code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Docs say this should be referenced as 'facts_hash."path.like.key"'; we could add a test with that.

Which docs? That syntax doesn't work with the current code.

The Puppet 6.18 get function docs, just above the one you link in the PR's description (getvar calls get at some point).

My point with this was that if what we want is to truly replicate getvar behavior we should deal with this; it's fine for me if we don't, it doesn't look like a very likely case.

Copy link
Copy Markdown
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

🚀 !

@albertvaka albertvaka merged commit b84ab7d into master Oct 6, 2020
@albertvaka albertvaka deleted the albertvaka/facts-dig branch October 6, 2020 13:46
cegeka-jenkins pushed a commit to cegeka/puppet-datadog_agent that referenced this pull request Feb 5, 2026
DataDog#656)

If a facts_to_tags tag looks like a hash path (eg: 'networking.domain'),
dig that path into the hash and use the inner value for the tag.

For backwards compatibility, if the name looks like a hash path
but there's a fact that's an exact string match (eg: there's a fact named
'networking.domain') then that will be used for the tag.

Note that on Puppet 6.0 and later `getvar` already behaves like this,
so this only makes it work on old Puppets.
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.

2 participants