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

Config mgmt Get Node Metadata Counts #3360

Merged
merged 12 commits into from
Apr 21, 2020
Merged

Conversation

lancewf
Copy link
Contributor

@lancewf lancewf commented Apr 14, 2020

🔩 Description: What code changed, and why?

Adding a new endpoint that for a node's field type provides distinct values and counts.

  For each type of field requested this returns distinct values the amount of each. For example, 
  if the 'platform' field is requested 'windows' 10, 'redhat' 5, and 'ubuntu' 8 could be returned. 
  The number next to each represents the number of nodes with that type of platform.

⛓️ Related Resources

#3344

👟 How to Build and Test the Change

  1. build components/config-mgmt-service && build components/automate-gateway && start_all_services
  2. Add three nodes with the below commands.
    1.generate_chef_run_example | jq --arg s "failure" --arg p "windows" '.status = $s | .node.automatic.platform=$p' | send_chef_data_raw
    1.generate_chef_run_example | jq --arg s "success" --arg p "linux" '.status = $s | .node.automatic.platform=$p' | send_chef_data_raw
    1.generate_chef_run_example | jq --arg s "failure" --arg p "macos" '.status = $s | .node.automatic.platform=$p' | send_chef_data_raw
  3. Call the new endpoint with curl -s -f --insecure -H "api-token: $(get_api_token)" "https://localhost/api/v0/cfgmgmt/nodes_field_value_counts?terms=platform&terms=status" | jq
  4. Ensure the response looks like below.
{
  "fields": [
    {
      "terms": [
        {
          "term": "macos 8.9",
          "count": 1
        },
        {
          "term": "linux 8.9",
          "count": 1
        },
        {
          "term": "windows 8.9",
          "count": 1
        }
      ],
      "field": "platform"
    },
    {
      "terms": [
        {
          "term": "success",
          "count": 1
        },
        {
          "term": "failure",
          "count": 2
        }
      ],
      "field": "status"
    }
  ]
}

✅ Checklist

Lance Finfrock added 4 commits April 14, 2020 16:40
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@lancewf lancewf force-pushed the lancewf/cfg_mgmt_field_term_counts branch from 6a31ba6 to c749489 Compare April 20, 2020 16:16
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@lancewf lancewf force-pushed the lancewf/cfg_mgmt_field_term_counts branch from 9002121 to f98ade1 Compare April 20, 2020 20:05
@@ -26,5 +26,5 @@ type BackendError struct {

// NewBackendError - create a new backend error
func NewBackendError(format string, args ...interface{}) *BackendError {
return &BackendError{New(Backend, fmt.Sprint(format, args))}
return &BackendError{New(Backend, fmt.Sprintf(format, args...))}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The arguments were not being used before.

Lance Finfrock added 4 commits April 20, 2020 13:46
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
…mt_field_term_counts

Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
Lance Finfrock added 2 commits April 20, 2020 17:48
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@lancewf lancewf marked this pull request as ready for review April 21, 2020 02:02
/*
GetNodesFieldValueCounts

Returns a list fields with value counts
Copy link

@vjeffrey vjeffrey Apr 21, 2020

Choose a reason for hiding this comment

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

nit: "list of fields" ?
maybe include an example (of response and request) for clarity?

Choose a reason for hiding this comment

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

maybe also add a sentence about how the counts are affected by the filters? (e.g. counts respect all filters except their own or some other wording that makes sense?)

[19][default:/src:130]# curl -s -f --insecure -H "api-token: $(get_api_token)" "https://localhost/api/v0/cfgmgmt/nodes_field_value_counts?terms=platform&terms=status" | jq
{
  "fields": [
    {
      "terms": [
        {
          "term": "mac_os_x 10.11.5",
          "count": 28
        },
        {
          "term": "linux 8.9",
          "count": 1
        },
        {
          "term": "macos 8.9",
          "count": 1
        },
        {
          "term": "windows 8.9",
          "count": 1
        }
      ],
      "field": "platform"
    },
    {
      "terms": [
        {
          "term": "missing",
          "count": 29
        },
        {
          "term": "failure",
          "count": 2
        }
      ],
      "field": "status"
    }
  ]
}
[20][default:/src:0]# curl -s -f --insecure -H "api-token: $(get_api_token)" "https://localhost/api/v0/cfgmgmt/nodes_field_value_counts?terms=platform&terms=status&filter=platform:linux*" | jq
{
  "fields": [
    {
      "terms": [
        {
          "term": "mac_os_x 10.11.5",
          "count": 28
        },
        {
          "term": "linux 8.9",
          "count": 1
        },
        {
          "term": "macos 8.9",
          "count": 1
        },
        {
          "term": "windows 8.9",
          "count": 1
        }
      ],
      "field": "platform"
    },
    {
      "terms": [
        {
          "term": "missing",
          "count": 1
        }
      ],
      "field": "status"
    }
  ]
}

@vjeffrey
Copy link

working well locally! i tried a few other api calls too:

[10][default:/src:0]# curl -s -f --insecure -H "api-token: $(get_api_token)" "https://localhost/api/v0/cfgmgmt/nodes_field_value_counts?terms=environment" | jq
{
  "fields": [
    {
      "terms": [
        {
          "term": "_default",
          "count": 28
        },
        {
          "term": "B",
          "count": 3
        }
      ],
      "field": "environment"
    }
  ]
}
[11][default:/src:0]# curl -s -f --insecure -H "api-token: $(get_api_token)" "https://localhost/api/v0/cfgmgmt/nodes_field_value_counts?terms=chef_version" | jq
{
  "fields": [
    {
      "terms": [
        {
          "term": "12.12.6",
          "count": 28
        },
        {
          "term": "12.6.0",
          "count": 3
        }
      ],
      "field": "chef_version"
    }
  ]
}

```
*/
rpc GetNodesFieldValueCounts(cfgmgmt.request.NodesFieldValueCounts) returns (cfgmgmt.response.NodesFieldValueCounts) {
option (google.api.http).get = "/cfgmgmt/nodes_field_value_counts";
Copy link

@vjeffrey vjeffrey Apr 21, 2020

Choose a reason for hiding this comment

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

@chef/ux-team do you have any strong opinions about this api?

i can't think of anything clearer than nodes_field_value_counts but i also kinda stared at it sideways for a min after reading the endpoint it

Copy link
Contributor

Choose a reason for hiding this comment

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

these are some random thoughts i had about this...
(but i dont have strong opinions)

  • i could not look at the endpoint name and understand what it was for
  • i think term might better work as value
  • and field as type
  • then maybe node_metadata_counts as the name

Choose a reason for hiding this comment

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

ooooh, i like node_metadata_counts !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I have had a lot of problems naming this function. Also even talking about what it does. I will update it to the above suggestions.

@lancewf
Copy link
Contributor Author

lancewf commented Apr 21, 2020

I renamed all the function names and parameters. I also added more comments and descriptions to the functions.

@lancewf lancewf force-pushed the lancewf/cfg_mgmt_field_term_counts branch from ff50714 to 6d38c9a Compare April 21, 2020 20:02
@lancewf lancewf changed the title Config mgmt field term counts Config mgmt Get Node Metadata Counts Apr 21, 2020
Signed-off-by: Lance Finfrock <lfinfrock@chef.io>
@lancewf lancewf force-pushed the lancewf/cfg_mgmt_field_term_counts branch from 6d38c9a to 32f1a64 Compare April 21, 2020 20:12
@lancewf lancewf merged commit 2041ab1 into master Apr 21, 2020
@chef-expeditor chef-expeditor bot deleted the lancewf/cfg_mgmt_field_term_counts branch April 21, 2020 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants