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

Add replace-existing-checks param to the api package #6496 #7136

Merged
merged 2 commits into from
Feb 3, 2020
Merged

Add replace-existing-checks param to the api package #6496 #7136

merged 2 commits into from
Feb 3, 2020

Conversation

fouadz
Copy link
Contributor

@fouadz fouadz commented Jan 25, 2020

Add replace-existing-checks param to the API package #6496

@hashicorp-cla
Copy link

hashicorp-cla commented Jan 25, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@hanshasselberg hanshasselberg left a comment

Choose a reason for hiding this comment

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

Thank you for your work @fouadz! There is another PR for feature #6541, which has a flag in ServiceRegistration which I would prefer to have instead of another function. But yours definitely has the better test coverage! :)

What do you think about the flag instead of the function?

Thanks!

@hanshasselberg hanshasselberg added the waiting-reply Waiting on response from Original Poster or another individual in the thread label Jan 27, 2020
@fouadz
Copy link
Contributor Author

fouadz commented Jan 27, 2020

Hi @i0rek

This is my view based on very limited knowledge of the codebase.

The AgentServiceRegistration struct perfectly matches what you expect from the API payload.
One can be confused in thinking the API now supports replace_existing_checks in the payload.

Example:

{
  "service":  {
   "name": "web",
   "tags": ["rails"],
   "port": 80,
   "replace_existing_checks": true
  }
  ....
}

Also, we have to ensure that we support the new field everywhere else in the code.
We may also have to ignore or hide the field from results. I assume that's why @Aestek added the "-"

ReplaceExistingChecks bool json:"-"

However, I don't mind changing to a flag instead, your call.

Thanks!

@ghost ghost removed waiting-reply Waiting on response from Original Poster or another individual in the thread labels Jan 27, 2020
@hanshasselberg
Copy link
Member

Thats a good point! After checking what we did before, I suggest you add an new function that can be extended in future: ServiceRegisterOpts similar to

consul/api/agent.go

Lines 512 to 552 in 61d8778

// Members returns the known gossip members. The WAN
// flag can be used to query a server for WAN members.
func (a *Agent) Members(wan bool) ([]*AgentMember, error) {
r := a.c.newRequest("GET", "/v1/agent/members")
if wan {
r.params.Set("wan", "1")
}
_, resp, err := requireOK(a.c.doRequest(r))
if err != nil {
return nil, err
}
defer resp.Body.Close()
var out []*AgentMember
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return out, nil
}
// MembersOpts returns the known gossip members and can be passed
// additional options for WAN/segment filtering.
func (a *Agent) MembersOpts(opts MembersOpts) ([]*AgentMember, error) {
r := a.c.newRequest("GET", "/v1/agent/members")
r.params.Set("segment", opts.Segment)
if opts.WAN {
r.params.Set("wan", "1")
}
_, resp, err := requireOK(a.c.doRequest(r))
if err != nil {
return nil, err
}
defer resp.Body.Close()
var out []*AgentMember
if err := decodeBody(resp, &out); err != nil {
return nil, err
}
return out, nil
}
.

What do you think?

@fouadz
Copy link
Contributor Author

fouadz commented Jan 29, 2020

I like the idea, I will check how to implement the suggested fix tonight.
Thank you @i0rek

…ew struct to hold service registration options. #6496
Copy link
Member

@hanshasselberg hanshasselberg 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! Thanks for your work and time to get this done!

@hanshasselberg hanshasselberg merged commit ef63999 into hashicorp:master Feb 3, 2020
@fouadz fouadz deleted the add-replace-existing-checks-api branch February 4, 2020 05:06
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.

None yet

3 participants