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

move to batch placement remove API #312

Merged
merged 7 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/controller/m3admin_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (c errorPlacementClient) Add([]*placementpb.Instance) error {
return c.err
}

func (c errorPlacementClient) Remove(string) error {
func (c errorPlacementClient) Remove([]string) error {
return c.err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/m3admin_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func TestErrorPlacementClient(t *testing.T) {
err = cl.Add([]*placementpb.Instance{{}})
assert.Equal(t, clErr, err)

err = cl.Remove("foo")
err = cl.Remove([]string{"foo"})
assert.Equal(t, clErr, err)

err = cl.Replace("foo", placementpb.Instance{})
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/update_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ func (c *M3DBController) shrinkPlacementForSet(
}

c.logger.Info("removing pod from placement", zap.String("instance", removeInst.ID()))
return c.adminClient.placementClientForCluster(cluster).Remove(removeInst.ID())
return c.adminClient.placementClientForCluster(cluster).Remove([]string{removeInst.ID()})
}

// findPodInstanceToRemove returns the pod (and associated placement instace)
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/update_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,14 +695,14 @@ func TestShrinkPlacementForSet(t *testing.T) {
pl := placementFromPods(t, cluster, pods, deps.idProvider)

// Expect the last pod to be removed.
placementMock.EXPECT().Remove(`{"name":"cluster-zones-rep0-2","uid":"2"}`)
placementMock.EXPECT().Remove([]string{`{"name":"cluster-zones-rep0-2","uid":"2"}`})
err = controller.shrinkPlacementForSet(cluster, set, pl)
assert.NoError(t, err)

// If there are more pods in the set then in the placement, we expect the last
// in the set to be removed.
pl = placementFromPods(t, cluster, pods[:2], deps.idProvider)
placementMock.EXPECT().Remove(`{"name":"cluster-zones-rep0-1","uid":"1"}`)
placementMock.EXPECT().Remove([]string{`{"name":"cluster-zones-rep0-1","uid":"1"}`})
err = controller.shrinkPlacementForSet(cluster, set, pl)
assert.NoError(t, err)
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/m3admin/placement/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package placement

import (
"errors"
"fmt"
"net/http"

"github.com/m3db/m3db-operator/pkg/m3admin"
Expand All @@ -38,7 +37,7 @@ const (
placementBaseURL = "/api/v1/services/m3db/placement"
placementInitURL = placementBaseURL + "/init"
placementReplaceURL = placementBaseURL + "/replace"
placementRemoveFmt = placementBaseURL + "/%s"
placementRemoveURL = placementBaseURL + "/remove"
placementSetURL = placementBaseURL + "/set"
)

Expand Down Expand Up @@ -129,9 +128,12 @@ func (p *placementClient) Add(instances []*placementpb.Instance) error {
return nil
}

func (p *placementClient) Remove(id string) error {
url := fmt.Sprintf(p.url+placementRemoveFmt, id)
return p.client.DoHTTPJSONPBRequest(http.MethodDelete, url, nil, nil)
func (p *placementClient) Remove(instanceIds []string) error {
url := p.url + placementRemoveURL
req := &admin.PlacementRemoveRequest{
InstanceIds: instanceIds,
}
return p.client.DoHTTPJSONPBRequest(http.MethodPost, url, req, nil)
}

func (p *placementClient) Replace(leavingInstanceID string, newInst placementpb.Instance) error {
Expand Down
8 changes: 4 additions & 4 deletions pkg/m3admin/placement/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/m3admin/placement/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestGetErr(t *testing.T) {

func TestRemove(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.String() != "/api/v1/services/m3db/placement/instFoo" || r.Method != http.MethodDelete {
if r.URL.String() != "/api/v1/services/m3db/placement/remove" || r.Method != http.MethodPost {
w.WriteHeader(404)
return
}
Expand All @@ -211,7 +211,7 @@ func TestRemove(t *testing.T) {
defer s.Close()

client := newPlacementClient(t, s.URL)
err := client.Remove("instFoo")
err := client.Remove([]string{"instFoo"})
assert.NoError(t, err)
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/m3admin/placement/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ type Client interface {
Set(request *admin.PlacementSetRequest) error
// Get will provide the current placement
Get() (placement m3placement.Placement, err error)
// Delete will delete the current placment
// Delete will delete the current placement
Delete() error
// Add will add an instance to the placement
Add(instances []*placementpb.Instance) error
// Remove removes a given instance with the given ID from the placement.
Remove(id string) error
// Remove removes instances with the given IDs from the placement.
Remove(instanceIds []string) error
// Replace replaces one instance with another.
Replace(leavingInstanceID string, newInstance placementpb.Instance) error
}