Skip to content

Conversation

roidelapluie
Copy link
Member

We have been Puppet user for 10 years and we are users of
https://github.com/camptocamp/prometheus-puppetdb-sd

However, that file_sd implementation contains business logic and
assumptions around e.g. the modules which you are using.

This pull request adds a simple PuppetDB service discovery, which will
enable more use cases than the mentioned sd.

cc @raphink @mcanevet

Signed-off-by: Julien Pivotto roidelapluie@inuits.eu

@roidelapluie roidelapluie marked this pull request as draft June 1, 2021 20:13
@roidelapluie
Copy link
Member Author

We are using this in production.

@mcanevet would you have some time to try this out as well?

@roidelapluie roidelapluie marked this pull request as ready for review June 9, 2021 14:41
@mcanevet
Copy link

mcanevet commented Jun 9, 2021

@roidelapluie do you have a pre-built docker image with this patch so that I don't have to build one?

@roidelapluie
Copy link
Member Author

docker pull quay.io/roidelapluie/prometheus-linux-amd64:puppetdb-sd

@saimonn
Copy link

saimonn commented Jul 23, 2021

@roidelapluie Thanks for this PR.
I've tested your image in our environment, and it works as expected.

NB: I just had to remove the suffix /pdb/api/v4 from the url, as it seems to already be added here. Should the test (also here and in other places) be adjusted accordingly ?

@roidelapluie
Copy link
Member Author

This is ready for review, and tests are green.

@juliusv
Copy link
Member

juliusv commented Sep 1, 2021

@roidelapluie Hi, I'm on vacation starting tomorrow until Sept 14 and won't be able to get to this before then. But happy to take a look after!

@roidelapluie
Copy link
Member Author

@roidelapluie Hi, I'm on vacation starting tomorrow until Sept 14 and won't be able to get to this before then. But happy to take a look after!

Enjoy!

@roidelapluie
Copy link
Member Author

@roidelapluie Hi, I'm on vacation starting tomorrow until Sept 14 and won't be able to get to this before then. But happy to take a look after!

Friendly ping :)

Copy link
Member

@juliusv juliusv left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple of nits :)

return err
}
if c.URL == "" {
return fmt.Errorf("url missing")
Copy link
Member

Choose a reason for hiding this comment

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

To make it consistent with file_sd:

Suggested change
return fmt.Errorf("url missing")
return fmt.Errorf("URL is missing")

return err
}
if parsedURL.Scheme != "http" && parsedURL.Scheme != "https" {
return fmt.Errorf("url scheme must be http or https")
Copy link
Member

Choose a reason for hiding this comment

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

Same:

Suggested change
return fmt.Errorf("url scheme must be http or https")
return fmt.Errorf("URL scheme must be 'http' or 'https'")

case string:
labelValue = value
case bool:
labelValue = fmt.Sprintf("%t", value)
Copy link
Member

Choose a reason for hiding this comment

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

Btw., you can use strconv.FormatBool() here:

Suggested change
labelValue = fmt.Sprintf("%t", value)
labelValue = strconv.FormatBool(value)

case string:
values[i] = value
case bool:
values[i] = fmt.Sprintf("%t", value)
Copy link
Member

Choose a reason for hiding this comment

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

dito

* `__meta_puppetdb_resource`: a SHA-1 hash of the resource’s type, title, and parameters, for identification
* `__meta_puppetdb_type`: the resource type
* `__meta_puppetdb_title`: the resource title
* `__meta_puppetdb_exported`: whether or not the resource is exported (true, false)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `__meta_puppetdb_exported`: whether or not the resource is exported (true, false)
* `__meta_puppetdb_exported`: whether or not the resource is exported (`"true"` or `"false"`)

* `__meta_puppetdb_exported`: whether or not the resource is exported (true, false)
* `__meta_puppetdb_tags`: comma separated list of resource tags
* `__meta_puppetdb_file`: the manifest file in which the resource was declared
* `__meta_puppetdb_environment`: the environment of the node associated to the resource
Copy link
Member

Choose a reason for hiding this comment

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

"associated with"?

* `__meta_puppetdb_tags`: comma separated list of resource tags
* `__meta_puppetdb_file`: the manifest file in which the resource was declared
* `__meta_puppetdb_environment`: the environment of the node associated to the resource
* `__meta_puppetdb_parameter_<parametername>`: the parameters of the resouces
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* `__meta_puppetdb_parameter_<parametername>`: the parameters of the resouces
* `__meta_puppetdb_parameter_<parametername>`: the parameters of the resources

# https://puppet.com/docs/puppetdb/latest/api/query/v4/pql.html
query: <string>

# Whether to include the parameters as labels.
Copy link
Member

Choose a reason for hiding this comment

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

To make it even clearer:

Suggested change
# Whether to include the parameters as labels.
# Whether to include the parameters as meta labels.

@roidelapluie
Copy link
Member Author

I have addressed the comments

@juliusv
Copy link
Member

juliusv commented Sep 16, 2021

@roidelapluie could it be that you need to rebase on the latest main to make the Netflify checks work?

@juliusv
Copy link
Member

juliusv commented Sep 16, 2021

Other than that, 👍

@juliusv
Copy link
Member

juliusv commented Sep 16, 2021

...but IMO it'd also be ok to merge it with Netlify failing, since it doesn't touch anything UI-related.

We have been Puppet user for 10 years and we are users of
https://github.com/camptocamp/prometheus-puppetdb-sd

However, that file_sd implementation contains business logic and
assumptions around e.g. the modules which you are using.

This pull request adds a simple PuppetDB service discovery, which will
enable more use cases than the upstream sd.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
@roidelapluie
Copy link
Member Author

Rebased & squashed :)

@juliusv
Copy link
Member

juliusv commented Sep 16, 2021

Hmm, now the Netlify deploy got cancelled with Canceled build due to no content change.

I think it's fine though. Merging :)

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.

4 participants