Skip to content

Commit

Permalink
Merge branch 'feat/delete-api' of github.com:zenovore/turing into fea…
Browse files Browse the repository at this point in the history
…t/delete-api
  • Loading branch information
Alexander committed Jun 4, 2023
2 parents 5d537c5 + e762915 commit 5144468
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 80 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ ClusterConfig:
TuringEncryptionKey: password
MLPConfig:
MerlinURL: http://localhost:8082/v1
MLPURL: http://localhost:8081/v1
MLPURL: http://localhost:8081
MLPEncryptionKey: password
TuringUIConfig:
ServingDirectory: ../ui/build
Expand Down Expand Up @@ -337,7 +337,7 @@ Then, update the config file `.env.development.local` as shown below.
```
REACT_APP_HOMEPAGE=/turing
REACT_APP_TURING_API=http://localhost:8080/v1
REACT_APP_MLP_API=http://localhost:8081/v1
REACT_APP_MLP_API=http://localhost:8081
REACT_APP_MERLIN_API=http://localhost:8082/v1
REACT_APP_OAUTH_CLIENT_ID=xxxxxxx.apps.googleusercontent.com
REACT_APP_DEFAULT_DOCKER_REGISTRY=docker.io
Expand Down
2 changes: 1 addition & 1 deletion api/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ VAULT_ADDRESS=http://vault.example.com:8200/
VAULT_TOKEN=

MERLIN_URL=http://mlp.example.com/api/merlin/v1
MLP_URL=http://mlp.example.com/api/v1
MLP_URL=http://mlp.example.com/api
MLP_ENCRYPTION_KEY=

TURING_ENCRYPTION_KEY=test_encryption_key
Expand Down
2 changes: 1 addition & 1 deletion api/config-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ClusterConfig:
TuringEncryptionKey: password
MLPConfig:
MerlinURL: http://localhost:8082/v1
MLPURL: http://localhost:8081/v1
MLPURL: http://localhost:8081
MLPEncryptionKey: password
TuringUIConfig:
ServingDirectory: ../ui/build
Expand Down
26 changes: 13 additions & 13 deletions api/e2e/test/router_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
WithJSON(json.RawMessage(`[{"client": {"id": 4}}, {"client": {"id": 7}}]`)).
Expect().Status(http.StatusOK).
JSON().Array().
Equal(JSONPayload("testdata/responses/router_proprietary_exp_batch_predict.json"))
IsEqual(JSONPayload("testdata/responses/router_proprietary_exp_batch_predict.json"))
})
})
})
Expand Down Expand Up @@ -116,13 +116,13 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
}, defaultDeploymentIntervals...).Should(Succeed())

version.
ValueEqual("status", api.Status.Failed).
ValueEqual("error", "Requested CPU is more than max permissible")
HasValue("status", api.Status.Failed).
HasValue("error", "Requested CPU is more than max permissible")
})

It("keeps previously deployed version active", func() {
router = api.GetRouter(apiE, routerCtx.ProjectID, routerCtx.ID)
router.Path("$.config.version").Equal(1)
router.Path("$.config.version").IsEqual(1)
})
})
})
Expand Down Expand Up @@ -197,8 +197,8 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
}, defaultDeploymentIntervals...).Should(Succeed())

version.
ValueEqual("status", api.Status.Failed).
ValueEqual("error", "Requested CPU is more than max permissible")
HasValue("status", api.Status.Failed).
HasValue("error", "Requested CPU is more than max permissible")
})

It("keeps previous valid version as router's current version", func() {
Expand Down Expand Up @@ -244,8 +244,8 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
}, defaultDeploymentIntervals...).Should(Succeed())

router.
ValueEqual("status", api.Status.Deployed).
Path("$.config.version").Equal(1)
HasValue("status", api.Status.Deployed).
Path("$.config.version").IsEqual(1)
})
})
})
Expand Down Expand Up @@ -276,7 +276,7 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
}, defaultDeploymentIntervals...).Should(Succeed())

version.
ValueEqual("status", api.Status.Deployed).
HasValue("status", api.Status.Deployed).
NotContainsKey("error")
})

Expand All @@ -290,8 +290,8 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp

It("updates router's configuration to the new version", func() {
api.GetRouter(apiE, routerCtx.ProjectID, routerCtx.ID).
ValueEqual("status", api.Status.Deployed).
Path("$.config.version").Equal(3)
HasValue("status", api.Status.Deployed).
Path("$.config.version").IsEqual(3)
})
})

Expand Down Expand Up @@ -320,7 +320,7 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
WithPath("routerId", routerCtx.ID).
Expect().Status(http.StatusBadRequest).
JSON().
Equal(json.RawMessage(`{
IsEqual(json.RawMessage(`{
"description": "invalid delete request",
"error": "router is currently deployed. Undeploy it first."
}`))
Expand Down Expand Up @@ -366,7 +366,7 @@ var _ = DeployedRouterContext("testdata/create_router_nop_logger_proprietary_exp
WithPath("routerId", routerCtx.ID).
Expect().Status(http.StatusNotFound).
JSON().
Equal(json.RawMessage(`{
IsEqual(json.RawMessage(`{
"description": "router not found",
"error": "record not found"
}`))
Expand Down
10 changes: 6 additions & 4 deletions api/e2e/test/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var _ = DeployedRouterContext("testdata/create_router_std_ensembler_proprietary_
WithJSON(json.RawMessage(`{"client": {"id": 4}}`)).
Expect().
Status(http.StatusOK).
JSON().Equal(json.RawMessage(`{"version": "control"}`))
JSON().IsEqual(json.RawMessage(`{"version": "control"}`))
})
})

Expand All @@ -48,7 +48,7 @@ var _ = DeployedRouterContext("testdata/create_router_std_ensembler_proprietary_
WithJSON(json.RawMessage(`{"client": {"id": 7}}`)).
Expect().
Status(http.StatusOK).
JSON().Equal(json.RawMessage(`{"version": "treatment-a"}`))
JSON().IsEqual(json.RawMessage(`{"version": "treatment-a"}`))
})
})
})
Expand All @@ -70,7 +70,8 @@ var _ = DeployedRouterContext("testdata/create_router_with_traffic_rules.json.tm
When("request satisfies the first traffic rule", func() {
It("responds with responses from `treatment-a` route", func() {
want = httpexpect.
NewValue(GinkgoT(), JSONPayload("testdata/responses/traffic_rules/traffic-rule-1.json")).
NewValue(GinkgoT(),
JSONPayload("testdata/responses/traffic_rules/traffic-rule-1.json")).
Object()

got = config.NewHTTPExpect(GinkgoT(), routerCtx.Endpoint).
Expand All @@ -87,7 +88,8 @@ var _ = DeployedRouterContext("testdata/create_router_with_traffic_rules.json.tm
When("request satisfies the second traffic rule", func() {
It("responds with responses from `treatment-b` route", func() {
want = httpexpect.
NewValue(GinkgoT(), JSONPayload("testdata/responses/traffic_rules/traffic-rule-2.json")).
NewValue(GinkgoT(),
JSONPayload("testdata/responses/traffic_rules/traffic-rule-2.json")).
Object()

got = config.NewHTTPExpect(GinkgoT(), routerCtx.Endpoint).
Expand Down
10 changes: 5 additions & 5 deletions api/e2e/test/routers_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func DeployedRouterContext(payloadTpl string, protocol routerConfig.Protocol, ar
}, defaultDeploymentIntervals...).Should(Succeed())

router.
ValueEqual("status", "deployed").
Value("config").Object().ValueEqual("version", 1)
HasValue("status", "deployed").
Value("config").Object().HasValue("version", 1)

endpoint, err := url.Parse(router.Value("endpoint").String().Raw())
Expect(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -292,12 +292,12 @@ func AssertResponsePayload(want, got *httpexpect.Object) {

if len(resp.Response.RouteResponses) > 0 {
got.
ValueEqual("request", want.Value("request").Raw()).
HasValue("request", want.Value("request").Raw()).
Value("response").Object().
ValueEqual("experiment", want.Path("$.response.experiment").Raw()).
HasValue("experiment", want.Path("$.response.experiment").Raw()).
Value("route_responses").Array().
ContainsOnly(want.Path("$.response.route_responses").Array().Raw()...)
} else {
got.Equal(want.Raw())
got.IsEqual(want.Raw())
}
}
3 changes: 1 addition & 2 deletions api/turing/api/appcontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ func NewAppContext(
cryptoService := service.NewCryptoService(cfg.TuringEncryptionKey)

// Init MLP service
mlpSvc, err := service.NewMLPService(cfg.MLPConfig.MLPURL, cfg.MLPConfig.MLPEncryptionKey,
cfg.MLPConfig.MerlinURL)
mlpSvc, err := service.NewMLPService(cfg.MLPConfig.MLPURL, cfg.MLPConfig.MerlinURL)
if err != nil {
return nil, errors.Wrapf(err, "Failed initializing MLP Service")
}
Expand Down
11 changes: 4 additions & 7 deletions api/turing/api/appcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ func TestNewAppContext(t *testing.T) {
EnvironmentConfigPath: "path-to-env-file.yaml",
},
MLPConfig: &config.MLPConfig{
MerlinURL: "http://mlp.example.com/api/merlin/v1",
MLPURL: "http://mlp.example.com/api/mlp/v1",
MLPEncryptionKey: "key",
MerlinURL: "http://mlp.example.com/api/merlin/v1",
MLPURL: "http://mlp.example.com/api/mlp/v1",
},
TuringEncryptionKey: "turing-key",
AlertConfig: &config.AlertConfig{
Expand Down Expand Up @@ -259,10 +258,9 @@ func TestNewAppContext(t *testing.T) {
},
)
monkey.Patch(service.NewMLPService,
func(mlpBasePath string, mlpEncryptionKey string, merlinBasePath string,
func(mlpBasePath string, merlinBasePath string,
) (service.MLPService, error) {
assert.Equal(t, testCfg.MLPConfig.MLPURL, mlpBasePath)
assert.Equal(t, testCfg.MLPConfig.MLPEncryptionKey, mlpEncryptionKey)
assert.Equal(t, testCfg.MLPConfig.MerlinURL, merlinBasePath)
return mlpSvc, nil
},
Expand Down Expand Up @@ -298,8 +296,7 @@ func TestNewAppContext(t *testing.T) {
)

// Create expected components
mlpService, err := service.NewMLPService(testCfg.MLPConfig.MLPURL,
testCfg.MLPConfig.MLPEncryptionKey, testCfg.MLPConfig.MerlinURL)
mlpService, err := service.NewMLPService(testCfg.MLPConfig.MLPURL, testCfg.MLPConfig.MerlinURL)
assert.NoError(t, err)
experimentService, err := service.NewExperimentsService(testCfg.Experiment)
assert.NoError(t, err)
Expand Down
5 changes: 2 additions & 3 deletions api/turing/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,8 @@ type GitlabConfig struct {

// MLPConfig captures the configuration used to connect to the Merlin/MLP API servers
type MLPConfig struct {
MerlinURL string `validate:"required"`
MLPURL string `validate:"required"`
MLPEncryptionKey string `validate:"required"`
MerlinURL string `validate:"required"`
MLPURL string `validate:"required"`
}

type MlflowConfig struct {
Expand Down
5 changes: 2 additions & 3 deletions api/turing/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,9 +892,8 @@ func TestConfigValidate(t *testing.T) {
TuringEncryptionKey: "secret",
AlertConfig: nil,
MLPConfig: &config.MLPConfig{
MerlinURL: "http://merlin.example.com",
MLPURL: "http://mlp.example.com",
MLPEncryptionKey: "secret",
MerlinURL: "http://merlin.example.com",
MLPURL: "http://mlp.example.com",
},
}

Expand Down
21 changes: 9 additions & 12 deletions api/turing/service/mlp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,23 @@ func newMerlinClient(googleClient *http.Client, basePath string) *merlinClient {
}

type mlpClient struct {
CryptoService
api *mlp.APIClient
}

func newMLPClient(googleClient *http.Client, basePath string, encryptionKey string) *mlpClient {
func newMLPClient(googleClient *http.Client, basePath string) *mlpClient {
cfg := mlp.NewConfiguration()
cfg.BasePath = basePath
cfg.HTTPClient = googleClient

return &mlpClient{
CryptoService: NewCryptoService(encryptionKey),
api: mlp.NewAPIClient(cfg),
api: mlp.NewAPIClient(cfg),
}
}

// NewMLPService returns a service that retrieves information that is shared across MLP projects
// from (currently) the Merlin API.
func NewMLPService(
mlpBasePath string,
mlpEncryptionKey string,
merlinBasePath string,
) (MLPService, error) {
// Create an HTTP client with Google default credential.
Expand All @@ -93,7 +90,7 @@ func NewMLPService(

svc := &mlpService{
merlinClient: newMerlinClient(httpClient, merlinBasePath),
mlpClient: newMLPClient(httpClient, mlpBasePath, mlpEncryptionKey),
mlpClient: newMLPClient(httpClient, mlpBasePath),
cache: cache.New(mlpCacheExpirySeconds*time.Second, mlpCacheCleanUpSeconds*time.Second),
}

Expand Down Expand Up @@ -142,13 +139,13 @@ func (service mlpService) GetProjects(name string) ([]mlp.Project, error) {
ctx, cancel := context.WithTimeout(context.Background(), mlpQueryTimeoutSeconds*time.Second)
defer cancel()

var options *mlp.ProjectApiProjectsGetOpts
var options *mlp.ProjectApiV1ProjectsGetOpts
if len(name) > 0 {
options = &mlp.ProjectApiProjectsGetOpts{
options = &mlp.ProjectApiV1ProjectsGetOpts{
Name: optional.NewString(name),
}
}
projects, resp, err := service.mlpClient.api.ProjectApi.ProjectsGet(ctx, options)
projects, resp, err := service.mlpClient.api.ProjectApi.V1ProjectsGet(ctx, options)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -193,7 +190,7 @@ func (service mlpService) GetSecret(projectID models.ID, name string) (string, e
ctx, cancel := context.WithTimeout(context.Background(), mlpQueryTimeoutSeconds*time.Second)
defer cancel()

secrets, resp, err := service.mlpClient.api.SecretApi.ProjectsProjectIdSecretsGet(ctx, int32(projectID))
secrets, resp, err := service.mlpClient.api.SecretApi.V1ProjectsProjectIdSecretsGet(ctx, int32(projectID))
if err != nil {
return "", err
}
Expand All @@ -202,7 +199,7 @@ func (service mlpService) GetSecret(projectID models.ID, name string) (string, e
}
for _, secret := range secrets {
if secret.Name == name {
return service.mlpClient.Decrypt(secret.Data)
return secret.Data, nil
}
}
return "", fmt.Errorf("secret %s not found in project %d", name, projectID)
Expand All @@ -212,7 +209,7 @@ func (service mlpService) refreshProjects() error {
ctx, cancel := context.WithTimeout(context.Background(), mlpQueryTimeoutSeconds*time.Second)
defer cancel()

projects, resp, err := service.mlpClient.api.ProjectApi.ProjectsGet(ctx, nil)
projects, resp, err := service.mlpClient.api.ProjectApi.V1ProjectsGet(ctx, nil)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 5144468

Please sign in to comment.