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

W.I.P. PR2: New functions created to query for each item - calling of functions in importer.pp #10

Merged
merged 23 commits into from Jan 7, 2021

Conversation

liamjohnsexton
Copy link
Collaborator

Hey guys,

In this pull request:

  • Added function to query for puppet servers on the estate

  • Added function to query for puppetdb_hosts on the estate

  • Added function to query for postgres_hosts on the estate (this one I'm not too confident on, essentially copied the code for querying the puppetdb_hosts, but changed to look for nodes with the class pe_postgresql::server::install attached)

  • Changed the code in importer.pp to call each of these functions and save them to their respective variable names, then calling these variables in the puppet_metrics_dashboard class

Copy link
Contributor

@dylanratcliffe dylanratcliffe 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. Only thing I would change is making the variables parameters so that it's easy to customise


#in the below class

$puppet_severs = rsan::get_puppet_servers()
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we expose these as parameters instead of just declaring as variables? That way someone should be able to call the class like so and override the defaults if they need to:

class { 'rsan::importer':
  puppet_servers => ['server1.company.com', 'server2.company.com'],
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in this instance, I'd be looking to do something like:

class { 'rsan::importer':
  puppet_servers  => $puppet_servers,
  puppetdb_hosts => $puppetdb_hosts,
  postgres_hosts   => $postgres_hosts,
}

Is that right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well that's what the user would do when the use RSAN. In order for you to allow them to do that you'll need to allow the rsan::importer class to accept parameters that the user passes i.e.

class rsan::importer (
  String $some_param = "hello",
) {

@@ -0,0 +1,18 @@
function rsan::get_postgres_hosts() {
if $settings::storeconfigs {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this makes this whole thing conditional on $settings::storeconfigs, which is a snippet from another place in code this was copied from. This does not need to be conditional

expired is null
}
}').map |$data| { $data['certname'] }
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

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

as there is no longer a conditional the exception of not having a postgres host returned needs handled differently

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hey Marty, would this mean I need to implement some sort of error catch? So if puppetdb_query returns nothing/an error - make an exception to set

$postgres_hosts = []

}
}').map |$data| { $data['certname'] }
} else {
$postgres_hosts = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

$postgres_hosts would need to be returned in a format
puppet_metrics_dashboard:: postgres_host_list expects

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in this case, puppet_metrics_dashboard::postgres_host would need to be an array of elements, with each element being a postgres host. I've been looking at https://puppet.com/docs/puppet/7.0/lang_data_type.html

Initially, part of me thinks that I need to some thing like:

function rsan::get_postgres_hosts() {
    $postgres_hosts => Array #this is the bit im thinking of adding in
    $postgres_hosts =
                puppetdb_query('resources[certname] {
                    type = "Class" and
                    title = "Pe_postgresql::Server::Install" and
                    nodes {
                      deactivated is null and
                      expired is null
                    }
                  }').map |$data| { $data['certname'] }
  }

My thinking is that by setting the data type beforehand - puppetdb_query will fill in the elements to that array as appropriate?

But I've also come across https://puppet.com/docs/puppet/7.0/lang_data_type.html#lang_data_type_usage

Where there is the 'Type' function. In this instance, I would do something like get the data type from the $postgres_hosts after the puppetdb_query is finished, then if the data type of $postgres_hosts =/ array, I set it as so?

@@ -0,0 +1,11 @@
function rsan::get_puppet_servers() {
$puppet_servers =
Copy link
Collaborator

Choose a reason for hiding this comment

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

there is a syntax issue here, best PDK validate

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Syntax issue on this should be solved in my next commit from my local repo :)

@@ -0,0 +1,11 @@
function rsan::get_puppet_servers() {
$puppet_servers =
Copy link
Collaborator

Choose a reason for hiding this comment

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

$puppet_servers needs to be in a format

puppet_metrics_dashboard::master_list expects

@@ -0,0 +1,17 @@
function rsan::get_puppetdb_hosts() {
if $settings::storeconfigs {
Copy link
Collaborator

Choose a reason for hiding this comment

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

same comments on the condition here

}
}').map |$data| { $data['certname'] }
} else {
$puppetdb_hosts = []
Copy link
Collaborator

Choose a reason for hiding this comment

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

puppetdb_hosts has to be returned in the correct format for

puppet_metrics_dashboard::puppetdb_list

@m0dular
Copy link
Contributor

m0dular commented Dec 9, 2020

This functionality already exists in the enterprise_tasks repo, for examples finding postgres nodes here. Can we make that module a dependency of this project instead of rewriting functionality?

Also, the postgres query does not work because it doesn't capitalize each element of the class name.

@MartyEwings
Copy link
Collaborator

@m0dular Thanks for the input, that does look like a good solution.

The PRS here are for review and collaboration and are not meant to be a final code.

Would you like to added to the codeowners for review or added to the project?

@liamjohnsexton liamjohnsexton changed the title PR2: New functions created to query for each item - calling of functions in importer.pp W.I.P. PR2: New functions created to query for each item - calling of functions in importer.pp Dec 15, 2020
@MartyEwings MartyEwings added the enhancement New feature or request label Dec 17, 2020
@MartyEwings MartyEwings added this to To Do in RSAN Development via automation Dec 17, 2020
@MartyEwings MartyEwings added this to the Feature Complete - No VPN milestone Dec 17, 2020
@MartyEwings MartyEwings linked an issue Dec 17, 2020 that may be closed by this pull request
@MartyEwings MartyEwings merged commit 1f0d2f9 into main Jan 7, 2021
RSAN Development automation moved this from To Do to complete Jan 7, 2021
@MartyEwings MartyEwings deleted the metricfeature branch January 11, 2021 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

Feature - Live Telemetry display
4 participants