-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add create router version feature (#179)
* Add create router version endpoint * Edit error message * Update OpenAPI specs and API with new endpoint * Add tests for CreateRouterVersion * Add UI components for creating router versions without deployment * Refactor UI submit event * Add SDK method to create new router version * Add tests for create version SDK method * Refactor error handling * Rename buttons * Change button colours to shades of primary colour * Add custom CSS colours * Refactor variables in router view * Refactor confirmation messages * Update put operation to create router versions to a post operation * Add documentation for creating routers with the UI * Add SDK sample to reflect saving of router versions * Remove redundant words from OpenAPI spec descriptions * Rename UpdateSummary to RouterUpdateSummary for consistency * Rename callback functions for clarity * Refactor VersionComparisonView to receive two onSubmit handlers * Simplify edit a router sample * Refactor create_version to now be a classmethod of RouterVersion * Refactor CreateRouterVersion endpoint to use RouterVersionConfig * Edit UI to use refactored schema for creating router version * Refactor create_version to now be a classmethod of RouterVersion * Pin cloudpickle to requirements * Add e2e test for creating router versions * Fix e2e test * Fix e2e test bug * Refactor OpenAPI specs and SDK * Simplify router version creation * Refactor CreateOrUpdateRouterRequest * Add convenience method to create routers to Router class * Fix lint comments
- Loading branch information
1 parent
d18df98
commit 2d9310e
Showing
41 changed files
with
1,327 additions
and
441 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
//go:build e2e | ||
// +build e2e | ||
|
||
package e2e | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/tidwall/gjson" | ||
|
||
"github.com/gojek/turing/api/turing/models" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
/* | ||
Pre: | ||
testCreateRouter run successfully. | ||
Steps: | ||
Create a router version with a valid router config | ||
b. GET router version 3 > shows status "undeployed" | ||
c. GET router > config still shows version 1 | ||
d. Test cluster state that all deployments exist | ||
e. Make a request to the router, validate the response. | ||
*/ | ||
func TestCreateRouterVersion(t *testing.T) { | ||
// Read existing router that MUST have already exists from previous create router e2e test | ||
// Router name is assumed to follow this format: e2e-experiment-{{.TestID}} | ||
routerName := "e2e-experiment-" + globalTestContext.TestID | ||
t.Log(fmt.Sprintf("Retrieving router with name '%s' created from previous test step", routerName)) | ||
existingRouter, err := getRouterByName( | ||
globalTestContext.httpClient, globalTestContext.APIBasePath, globalTestContext.ProjectID, routerName) | ||
require.NoError(t, err) | ||
|
||
// Read router config test data | ||
data := makeRouterPayload(filepath.Join("testdata", "create_router_version.json.tmpl"), globalTestContext) | ||
|
||
// Update router | ||
url := fmt.Sprintf( | ||
"%s/projects/%d/routers/%d/versions", | ||
globalTestContext.APIBasePath, | ||
globalTestContext.ProjectID, | ||
existingRouter.ID, | ||
) | ||
t.Log("Creating router version: POST " + url) | ||
req, err := http.NewRequest("POST", url, bytes.NewReader(data)) | ||
require.NoError(t, err) | ||
req.Header.Set("Content-Type", "application/json") | ||
resp, err := globalTestContext.httpClient.Do(req) | ||
require.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode, readBody(t, resp)) | ||
|
||
// Get router version 3 | ||
t.Log("Testing GET router version") | ||
routerVersion, err := getRouterVersion( | ||
globalTestContext.httpClient, | ||
globalTestContext.APIBasePath, | ||
globalTestContext.ProjectID, | ||
int(existingRouter.ID), | ||
3, | ||
) | ||
require.NoError(t, err) | ||
assert.Equal(t, models.RouterVersionStatusUndeployed, routerVersion.Status) | ||
|
||
t.Log("Ensure existing router did not update the version to the new version i.e. the version still unchanged at 1") | ||
router, err := getRouter( | ||
globalTestContext.httpClient, | ||
globalTestContext.APIBasePath, | ||
globalTestContext.ProjectID, | ||
int(existingRouter.ID), | ||
) | ||
require.NoError(t, err) | ||
require.NotNil(t, router.CurrRouterVersion) | ||
assert.Equal(t, 1, int(router.CurrRouterVersion.Version)) | ||
|
||
downstream, err := getRouterDownstream(globalTestContext.clusterClients, | ||
globalTestContext.ProjectName, | ||
fmt.Sprintf("%s-turing-router", router.Name)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, downstream, fmt.Sprintf("%s-turing-router-%d.%s.%s", | ||
router.Name, 1, globalTestContext.ProjectName, globalTestContext.KServiceDomain)) | ||
|
||
// Check that previous enricher, router, ensembler deployments exist | ||
t.Log("Checking cluster state") | ||
assert.True(t, isDeploymentExists( | ||
globalTestContext.clusterClients, | ||
globalTestContext.ProjectName, | ||
fmt.Sprintf("%s-turing-router-%d-0-deployment", router.Name, 1))) | ||
assert.True(t, isDeploymentExists( | ||
globalTestContext.clusterClients, | ||
globalTestContext.ProjectName, | ||
fmt.Sprintf("%s-turing-enricher-%d-0-deployment", router.Name, 1))) | ||
assert.True(t, isDeploymentExists( | ||
globalTestContext.clusterClients, | ||
globalTestContext.ProjectName, | ||
fmt.Sprintf("%s-turing-ensembler-%d-0-deployment", router.Name, 1))) | ||
|
||
// Make request to router | ||
t.Log("Testing router endpoint") | ||
router, err = getRouter( | ||
globalTestContext.httpClient, | ||
globalTestContext.APIBasePath, | ||
globalTestContext.ProjectID, | ||
int(router.ID), | ||
) | ||
require.NoError(t, err) | ||
assert.Equal(t, | ||
fmt.Sprintf( | ||
"http://%s-turing-router.%s.%s/v1/predict", | ||
router.Name, | ||
globalTestContext.ProjectName, | ||
globalTestContext.KServiceDomain, | ||
), | ||
router.Endpoint, | ||
) | ||
req, err = http.NewRequestWithContext( | ||
context.Background(), | ||
http.MethodPost, | ||
router.Endpoint, | ||
ioutil.NopCloser(bytes.NewReader([]byte(`{}`))), | ||
) | ||
require.NoError(t, err) | ||
resp, err = globalTestContext.httpClient.Do(req) | ||
require.NoError(t, err) | ||
responseBytes, err := ioutil.ReadAll(resp.Body) | ||
defer resp.Body.Close() | ||
require.NoError(t, err) | ||
actualResponse := gjson.GetBytes(responseBytes, "json.response").String() | ||
expectedResponse := `{ | ||
"experiment": {}, | ||
"route_responses": [ | ||
{ | ||
"data": { | ||
"version": "control" | ||
}, | ||
"is_default": true, | ||
"route": "control" | ||
} | ||
] | ||
}` | ||
assert.JSONEq(t, expectedResponse, actualResponse) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.