-
Notifications
You must be signed in to change notification settings - Fork 114
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
[infra-proxy-service] Environments list using search API with pagination #4659
[infra-proxy-service] Environments list using search API with pagination #4659
Conversation
Deploy preview for chef-automate ready! Built with commit 60bfc86 |
// Environment represents the search based deserialized Environment type | ||
type Environment struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only fetching the desired data using search API
query = chef.SearchQuery{ | ||
Index: "environment", | ||
Query: "*:*", | ||
Start: 0, | ||
Rows: inc, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default query string to fetch the first time, other records get appended.
sort.Slice(cl, func(i, j int) bool { | ||
return cl[i].Name < cl[j].Name | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to sort here
return result, ParseAPIError(err) | ||
} | ||
|
||
defer res1.Body.Close() // nolint: errcheck |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer in loop can be problematic. Same comment made on your other pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove it entirely, not required anymore
}, nil | ||
} | ||
|
||
// SearchEnvironments gets environment list from Chef Infra Server search API. | ||
func (c *ChefClient) SearchEnvironments(searchQuery *request.SearchQuery) (EnvironmentResult, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we are doing the same functionality across environment, client, data-bag. Can we reuse this method ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be some reusability left with these PR but for that, we some need something into master, I have planned for that but not now thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored the code, now using c.client.Seach.Query
instead of raw query. thanks!
Hey @vsingh-msys is it possible to add some integration tests for these APIs? |
@@ -5,11 +5,22 @@ option go_package = "github.com/chef/automate/api/external/infra_proxy/request"; | |||
|
|||
import "google/protobuf/struct.proto"; | |||
|
|||
message SearchQuery { | |||
// The search query used to identify a list of items. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a lot more information on what constitutes a query.
Your PR preamble gives some...
"... has to be in the format :, name:* or name:chef-env-* etc."
but that is insufficient. What do you mean by "etc." ? Must there always be a colon? Can there be more than one colon. If a wildcard can exist in *:*
then surely we could also do "*:chef-env", but there is no example of that.
It is OK to have examples, but also need to explain the requirements.
What I see from this small set of examples:
- Format must be
x:y
where x is ?? and y is ??. x
may be a field name (what fields??) or a wildcard.y
may be a complete value (what values??), a value prefix ending with a wildcard, or a wildcard by itself.
That is just my inference; please adjust this to accurately reflect the requirements.
(This applies to several PRs and several proto files in each PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here in the environment list, currently targeting for searching with the name only.
Have taken reference from chef-manage so if nothing is provided for search use *:*
for wildcard
otherwise use name:SEARCH_PATTERN
like example.
For more context on search pattern chef search support key:search_pattern
ref: https://docs.chef.io/chef_search/#query-syntax
where key
is a field name that is found in the JSON description of an indexable object on the Chef Infra Server (a role, node, client, environment, or data bag) and search_pattern defines what will be searched for, using one of the following search patterns: exact, wildcard, range, or fuzzy matching. Both key and search_pattern are case-sensitive; key
has limited support for multiple character wildcard matching using an asterisk ("*") (and as long as it is not the first character).
message SearchQuery { | ||
// The search query used to identify a list of items. | ||
string q = 1; | ||
// The number of result pages to return. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR preamble disagrees, stating start
is the "offset of the records" which I think is correct and L11 here is incorrect. But what units is offset
? I am guessing that is "pages" where a page is defined by the rows
property?
(This applies to several PRs and several proto files in each PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh yeah, will match and updated it accordingly.
Also, I tried to match parity with chef server API to named the exact same. ref https://docs.chef.io/server/api_chef_server/#get-47
Automate uses most of the places per_page
, page
variables for pagination. do we need to rename it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I missed that; good catch. Looking over the existing ones in the rest of the code base, the description for page
is wrong on most of them.
Let's go with this, please:
// Starting page for the results.
int32 page = 23;
// Number of results on each page.
int32 per_page = 24;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the renames, but you missed my last comment above: the comment on page
is wrong in a couple places where you have copied it. Needs to be as shown above, "Starting page for the results."
1e6989f
to
42e8ce3
Compare
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
591ed6c
to
60bfc86
Compare
🔩 Description: What code changed, and why?
Environment list API now also work with paganization and searching with the name.
If we won't pass any params it will fetch all environments available in the system.
Search query works with the following request params
search_query.q
: Search query string have to in the format like*:*
,name:*
orname:chef-env-*
etc.search_query.page
: offset of the records. [Updated 08-Feb-2020]search_query.per_page
: per page records need to fetch. [Updated 08-Feb-2020]gRPC request
⛓️ Related Resources
Fixes: #4627
👍 Definition of Done
👟 How to Build and Test the Change
Steps to build:
rebuild components/infra-proxy-service
rebuild components/automate-gateway
Steps to test:
To add data using 3rd internal steps https://github.com/chef/automate/blob/master/dev-docs/adding-data/adding_test_data.md#adding-data-to-infra-views
Environment list API without filter query
✅ Checklist
📷 Screenshots, if applicable
Signed-off-by: Vivek Singh [email protected]
Aha! Link: https://chef.aha.io/epics/SH-E-392