-
Notifications
You must be signed in to change notification settings - Fork 453
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
[dtest] Fix API incompatibilities in docker harness #2849
Changes from 2 commits
3247dcc
f867b1c
f537edc
239b63b
05afdad
f4d1154
2bcb115
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ package resources | |
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
|
@@ -31,7 +31,9 @@ import ( | |
|
||
"github.com/m3db/m3/src/query/generated/proto/admin" | ||
|
||
dockertest "github.com/ory/dockertest" | ||
"github.com/gogo/protobuf/jsonpb" | ||
"github.com/gogo/protobuf/proto" | ||
"github.com/ory/dockertest" | ||
"go.uber.org/zap" | ||
) | ||
|
||
|
@@ -112,7 +114,7 @@ func (c *coordinator) GetNamespace() (admin.NamespaceGetResponse, error) { | |
return admin.NamespaceGetResponse{}, errClosed | ||
} | ||
|
||
url := c.resource.getURL(7201, "api/v1/namespace") | ||
url := c.resource.getURL(7201, "api/v1/services/m3db/namespace") | ||
logger := c.resource.logger.With( | ||
zapMethod("getNamespace"), zap.String("url", url)) | ||
|
||
|
@@ -135,7 +137,7 @@ func (c *coordinator) GetPlacement() (admin.PlacementGetResponse, error) { | |
return admin.PlacementGetResponse{}, errClosed | ||
} | ||
|
||
url := c.resource.getURL(7201, "api/v1/placement") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
url := c.resource.getURL(7201, "api/v1/services/m3db/placement") | ||
logger := c.resource.logger.With( | ||
zapMethod("getPlacement"), zap.String("url", url)) | ||
|
||
|
@@ -239,13 +241,7 @@ func (c *coordinator) CreateDatabase( | |
zapMethod("createDatabase"), zap.String("url", url), | ||
zap.String("request", addRequest.String())) | ||
|
||
b, err := json.Marshal(addRequest) | ||
if err != nil { | ||
logger.Error("failed to marshal", zap.Error(err)) | ||
return admin.DatabaseCreateResponse{}, err | ||
} | ||
|
||
resp, err := http.Post(url, "application/json", bytes.NewReader(b)) | ||
resp, err := makePostRequest(logger, url, &addRequest) | ||
if err != nil { | ||
logger.Error("failed post", zap.Error(err)) | ||
return admin.DatabaseCreateResponse{}, err | ||
|
@@ -273,13 +269,7 @@ func (c *coordinator) AddNamespace( | |
zapMethod("addNamespace"), zap.String("url", url), | ||
zap.String("request", addRequest.String())) | ||
|
||
b, err := json.Marshal(addRequest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Also, when I changed the marshaling, linter kicked in and forced me to make some additional refactorings. |
||
if err != nil { | ||
logger.Error("failed to marshal", zap.Error(err)) | ||
return admin.NamespaceGetResponse{}, err | ||
} | ||
|
||
resp, err := http.Post(url, "application/json", bytes.NewReader(b)) | ||
resp, err := makePostRequest(logger, url, &addRequest) | ||
if err != nil { | ||
logger.Error("failed post", zap.Error(err)) | ||
return admin.NamespaceGetResponse{}, err | ||
|
@@ -330,6 +320,26 @@ func (c *coordinator) WriteCarbon( | |
// return nil | ||
} | ||
|
||
func makePostRequest(logger *zap.Logger, url string, body proto.Message) (*http.Response, error) { | ||
data := bytes.NewBuffer(nil) | ||
if err := (&jsonpb.Marshaler{}).Marshal(data, body); err != nil { | ||
logger.Error("failed to marshal", zap.Error(err)) | ||
|
||
return &http.Response{}, fmt.Errorf("failed to marshal: %w", err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe just return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, url, data) | ||
if err != nil { | ||
logger.Error("failed to construct request", zap.Error(err)) | ||
|
||
return &http.Response{}, fmt.Errorf("failed to construct request: %w", err) | ||
} | ||
|
||
req.Header.Add("Content-Type", "application/json") | ||
|
||
return http.DefaultClient.Do(req) | ||
} | ||
|
||
func (c *coordinator) query( | ||
verifier GoalStateVerifier, query string, | ||
) 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.
Removed in 1.0 https://github.com/m3db/m3/blame/a3dff4325159919c061c5b0d0b72c99b671159dd/CHANGELOG.md#L28