-
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] Client list using search API #4660
[infra-proxy-service] Client list using search API #4660
Conversation
Deploy preview for chef-automate processing. Building with commit 0372e2e https://app.netlify.com/sites/chef-automate/deploys/602540ed5a19eb0007787efc |
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.
Please let me know if any doubts
// GetClients get clients list | ||
func (s *Server) GetClients(ctx context.Context, req *request.Clients) (*response.Clients, error) { | ||
c, err := s.createClient(ctx, req.OrgId, req.ServerId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
clients, err := c.client.Clients.List() | ||
res, err := c.SearchClients(req.SearchQuery) |
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.
can this be not like this : c.client.Clients.Search()
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.
making c.client.Clients.Search()
is like adding the changes into https://github.com/go-chef/chef/blob/master/client.go
but here we need to handle some cases based on our need, so added like this.
It would be some refactoring needed for making search API call for other objects like environments, roles, and data bag 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.
Although I don't believe in creating Tech Debut for future. But if still you want to only add code in this repo, then
You could create a separate file to extend features of ApiClientService and use that function which will still be c.client.Clients.Search()
Also, I could not see any unit tests.
Please let me know if I am mistaken.
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.
Sure will take a look how we can achieve it, 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.
@vivek-yadav now, using query, err := c.client.Search.NewQuery("INDEX", "SEARCH_TERM")
for searching please review it again, Thanks!
this is the curl request for search |
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.
I think these defers are going to get stacked until the function returns. This is probably not good style, but can have some real consequences, such as this code wouldn't be able to reuse any of the http connections while in the loop
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 information @jaym , will rectify this
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 search all looping entirely, not using res1.Body.Close()
.
Hey @vsingh-msys is it possible to add some integration tests for these APIs? |
From a product perspective I think this functionality could be potentially confusing. It is getting a list of clients from the infra-server but it might differ from the list of clients in automate. Would it make more sense to have automate be the source of truth for clients and pull any missing clients in from infra server? |
@kmacgugan, yeah it is a bit of confusing terms with reference to Automate client runs. In Automate infra views, clients mean an API client which used to provide auth to communicate between nodes and infra clients as it falls under infra-proxy-service might we can distinguish it named based on chef-server API https://docs.chef.io/server/api_chef_server/#get-10 & manage also naming the same. @jonong1972 any suggestions ^^^ |
@vsingh-msys @kmacgugan I'm confused on the question. I'm reading two different items here. One is a back-end question the other is a naming question? |
18072fe
to
34cf711
Compare
@jonong1972 yes, one is for backend and another is for UI in chef manage, but both pointed the object, so in order to maintain the parity, keeping the same name. |
res, err := infraProxy.GetClients(ctx, req) | ||
assert.NoError(t, err) | ||
assert.NotNil(t, res) | ||
assert.Equal(t, int(res.Page), 0) |
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.
These tests are too specific to the sample data loaded. Let's make sure that we modify them when we are going to add edit/create apis.
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]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
Signed-off-by: Vivek Singh <[email protected]>
ffedd67
to
5b98415
Compare
Signed-off-by: Vivek Singh <[email protected]>
🔩 Description: What code changed, and why?
Client list using search API with pagination support.
It would not break the existing list API.
It will fetch all clients available in the system if no params are given.
Search query works with the following request params
search_query.q
: Search query string have to in the format like*:*
,name:*
orname:node-*
etc.search_query.page
: page number. [Updated 04-Feb-2020]search_query.per_page
: number of records per page. [Updated 04-Feb-2020]gRPC API
NOTE: integration test cases written based on prepopulated data using scripts.
⛓️ Related Resources
Fixes: #4628
👍 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
Client list API without a search query
✅ Checklist
📷 Screenshots, if applicable
Signed-off-by: Vivek Singh [email protected]
Aha! Link: https://chef.aha.io/epics/SH-E-393