Skip to content

Commit

Permalink
- removing references to XP/Litmus from the codebase (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanwozniak authored Jan 28, 2022
1 parent f1fa940 commit 89818ca
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 202 deletions.
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ The `turing-integration-test` MLP project is used by the CI to exercise the end
#### Local
**Note:** Swarm mode must be enabled for this section.
1. Set the required env vars in `.env.development`, namely the `MLP_ECRYPTION_KEY` and `VAULT_TOKEN`
2. Set an MLP project id and the corresponding name in `e2e/local/.env.testing`. Set a unique `TEST_ID` (to prevent conflicts with CI runs / local runs triggered by other users). Set the `TEST_LITMUS_PASSKEY` and `TEST_XP_PASSKEY` values to the passkey of the client id in the Litmus/XP integration environment, respectively. The env var `MODEL_CLUSTER_NAME` is used to indicate the cluster in which resources are expected to be created, and will be used to initialise the cluster client for validation. Thus, this cluster name must correspond to the `environment_name` property in the test data (under `e2e/test/testdata`) and has been configured so.
2. Set an MLP project id and the corresponding name in `e2e/local/.env.testing`. Set a unique `TEST_ID` (to prevent conflicts with CI runs / local runs triggered by other users). The env var `MODEL_CLUSTER_NAME` is used to indicate the cluster in which resources are expected to be created, and will be used to initialise the cluster client for validation. Thus, this cluster name must correspond to the `environment_name` property in the test data (under `e2e/test/testdata`) and has been configured so.
3. Run `make test-e2e-local`. This will deploy a local docker swarm set up for serving the Turing API and will run the end to end tests from the local environment, against it. The local services are destroyed after the tests.

## Folder structure of Turing API
Expand Down
19 changes: 12 additions & 7 deletions api/turing/api/deployment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (c RouterDeploymentController) deployRouterVersion(
routerVersion *models.RouterVersion,
eventsCh *service.EventChannel,
) (string, error) {
var routerServiceAccountKey, enricherServiceAccountKey, ensemblerServiceAccountKey, experimentPasskey string
var routerServiceAccountKey, enricherServiceAccountKey, ensemblerServiceAccountKey string
var experimentConfig json.RawMessage
var err error

Expand Down Expand Up @@ -190,16 +190,22 @@ func (c RouterDeploymentController) deployRouterVersion(

expSvc := c.BaseController.AppContext.ExperimentsService
if routerVersion.ExperimentEngine.Type != models.ExperimentEngineTypeNop {

experimentConfig = routerVersion.ExperimentEngine.Config
if expSvc.IsStandardExperimentManager(routerVersion.ExperimentEngine.Type) {
// Convert the config to the standard type
expConfig, err := manager.ParseStandardExperimentConfig(routerVersion.ExperimentEngine.Config)
standardExperimentConfig, err := manager.ParseStandardExperimentConfig(experimentConfig)
if err != nil {
return "", c.updateRouterVersionStatusToFailed(err, routerVersion)
}
// If passkey has been set, decrypt it
if expConfig.Client.Passkey != "" {
experimentPasskey, err = c.CryptoService.Decrypt(expConfig.Client.Passkey)
if standardExperimentConfig.Client.Passkey != "" {
standardExperimentConfig.Client.Passkey, err =
c.CryptoService.Decrypt(standardExperimentConfig.Client.Passkey)
if err != nil {
return "", c.updateRouterVersionStatusToFailed(err, routerVersion)
}

experimentConfig, err = json.Marshal(standardExperimentConfig)
if err != nil {
return "", c.updateRouterVersionStatusToFailed(err, routerVersion)
}
Expand All @@ -209,7 +215,7 @@ func (c RouterDeploymentController) deployRouterVersion(
// Get the deployable Router Config for the experiment
experimentConfig, err = c.ExperimentsService.GetExperimentRunnerConfig(
routerVersion.ExperimentEngine.Type,
routerVersion.ExperimentEngine.Config,
experimentConfig,
)
if err != nil {
return "", c.updateRouterVersionStatusToFailed(err, routerVersion)
Expand All @@ -234,7 +240,6 @@ func (c RouterDeploymentController) deployRouterVersion(
enricherServiceAccountKey,
ensemblerServiceAccountKey,
experimentConfig,
experimentPasskey,
eventsCh,
)

Expand Down
55 changes: 35 additions & 20 deletions api/turing/api/deployment_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"database/sql"
"encoding/json"
"errors"
"fmt"
"testing"

merlin "github.com/gojek/merlin/client"
mlp "github.com/gojek/mlp/api/client"
"github.com/gojek/turing/api/turing/models"
"github.com/gojek/turing/api/turing/service"
"github.com/gojek/turing/api/turing/service/mocks"
"github.com/gojek/turing/engines/experiment/manager"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
Expand All @@ -33,12 +35,15 @@ func TestDeployVersionSuccess(t *testing.T) {
ServiceAccountSecret: "svc-acct-secret",
},
}
nopExpCfg := &models.ExperimentEngine{
Type: "nop",
}
expCfg := json.RawMessage(`{"client": {"id": "1", "passkey": "test-passkey"}}`)
nopExpCfg := &models.ExperimentEngine{Type: "nop"}

testEngineType := "test-manager"
testPassKey := "test-passkey"
testDecPassKey := "test-passkey-dec"

expCfg := json.RawMessage(fmt.Sprintf(`{"client": {"id": "1", "passkey": "%s"}}`, testPassKey))
expWithPassKeyCfg, _ := json.Marshal(
manager.TuringExperimentConfig{Client: manager.Client{ID: "1", Passkey: testDecPassKey}})

expEnabledCfg := &models.ExperimentEngine{
Type: testEngineType,
Expand All @@ -47,11 +52,12 @@ func TestDeployVersionSuccess(t *testing.T) {

// Define tests
tests := map[string]struct {
routerVersion *models.RouterVersion
pendingVersion *models.RouterVersion
validVersion *models.RouterVersion
expCfg json.RawMessage
decryptedPasskey string
routerVersion *models.RouterVersion
pendingVersion *models.RouterVersion
validVersion *models.RouterVersion
expCfgWithPassKey json.RawMessage
expRunnerCfg json.RawMessage
decryptedPasskey string
}{
"nop_experiment": {
routerVersion: &models.RouterVersion{
Expand All @@ -78,7 +84,7 @@ func TestDeployVersionSuccess(t *testing.T) {
ExperimentEngine: nopExpCfg,
Status: "deployed",
},
expCfg: json.RawMessage(nil),
expRunnerCfg: json.RawMessage(nil),
},
"experiment_enabled": {
routerVersion: &models.RouterVersion{
Expand All @@ -105,8 +111,9 @@ func TestDeployVersionSuccess(t *testing.T) {
ExperimentEngine: expEnabledCfg,
Status: "deployed",
},
expCfg: json.RawMessage(`{"engine": "test"}`),
decryptedPasskey: "test-passkey-dec",
expCfgWithPassKey: expWithPassKeyCfg,
expRunnerCfg: json.RawMessage(`{"engine": "test"}`),
decryptedPasskey: testDecPassKey,
},
}

Expand All @@ -124,12 +131,7 @@ func TestDeployVersionSuccess(t *testing.T) {
es.On("Save", mock.Anything).Return(nil)

cs := &mocks.CryptoService{}
cs.On("Decrypt", "test-passkey").Return("test-passkey-dec", nil)

exps := &mocks.ExperimentsService{}
exps.On("IsStandardExperimentManager", "nop").Return(false)
exps.On("IsStandardExperimentManager", mock.Anything).Return(true)
exps.On("GetExperimentRunnerConfig", testEngineType, expCfg).Return(json.RawMessage(`{"engine": "test"}`), nil)
cs.On("Decrypt", testPassKey).Return(testDecPassKey, nil)

// Run tests and validate
for name, data := range tests {
Expand All @@ -138,13 +140,26 @@ func TestDeployVersionSuccess(t *testing.T) {
defer eventsCh.Close()

// Set up test-specific mock services
exps := &mocks.ExperimentsService{}
exps.
On(
"IsStandardExperimentManager",
data.routerVersion.ExperimentEngine.Type,
).Return(true)
exps.
On(
"GetExperimentRunnerConfig",
data.routerVersion.ExperimentEngine.Type,
data.expCfgWithPassKey,
).Return(data.expRunnerCfg, nil)

rvs := &mocks.RouterVersionsService{}
rvs.On("Save", data.pendingVersion).Return(data.pendingVersion, nil)
rvs.On("Save", data.validVersion).Return(data.validVersion, nil)

ds := &mocks.DeploymentService{}
ds.On("DeployRouterVersion", project, environment, data.pendingVersion, "service-acct",
"", "", data.expCfg, data.decryptedPasskey, eventsCh).Return("test-url", nil)
"", "", data.expRunnerCfg, eventsCh).Return("test-url", nil)

// Create test controller
ctrl := RouterDeploymentController{
Expand Down Expand Up @@ -253,7 +268,7 @@ func TestRollbackVersionSuccess(t *testing.T) {

ds := &mocks.DeploymentService{}
ds.On("DeployRouterVersion", project, environment, newVer, testSvcAcct,
"", "", json.RawMessage(nil), "", mock.Anything).Return("", errors.New("error"))
"", "", json.RawMessage(nil), mock.Anything).Return("", errors.New("error"))
ds.On("UndeployRouterVersion", project, environment, newVer, mock.Anything).
Return(nil)

Expand Down
25 changes: 0 additions & 25 deletions api/turing/cluster/servicebuilder/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ const (
envEnricherTimeout = "ENRICHER_TIMEOUT"
envEnsemblerEndpoint = "ENSEMBLER_ENDPOINT"
envEnsemblerTimeout = "ENSEMBLER_TIMEOUT"
envLitmusPasskey = "LITMUS_PASSKEY"
envXpPasskey = "XP_PASSKEY"
envLogLevel = "APP_LOGLEVEL"
envFiberDebugLog = "APP_FIBER_DEBUG_LOG"
envCustomMetrics = "APP_CUSTOM_METRICS"
Expand Down Expand Up @@ -214,29 +212,6 @@ func (sb *clusterSvcBuilder) buildRouterEnvs(
}...)
}

// Add Experiment Engine config
if ver.ExperimentEngine.Type != models.ExperimentEngineTypeNop {
var envVarName string
switch ver.ExperimentEngine.Type {
case models.ExperimentEngineTypeLitmus:
envVarName = envLitmusPasskey
case models.ExperimentEngineTypeXp:
envVarName = envXpPasskey
}
// Add env var
envs = append(envs, corev1.EnvVar{
Name: envVarName,
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: secretName,
},
Key: secretKeyNameExperiment,
},
},
})
}

// Process Log config
logConfig := ver.LogConfig
envs = append(envs, []corev1.EnvVar{
Expand Down
44 changes: 0 additions & 44 deletions api/turing/cluster/servicebuilder/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ func TestNewRouterService(t *testing.T) {
{Name: "ROUTER_CONFIG_FILE", Value: "/app/config/fiber.yml"},
{Name: "APP_SENTRY_ENABLED", Value: "true"},
{Name: "APP_SENTRY_DSN", Value: "sentry-dsn"},
{
Name: "LITMUS_PASSKEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "service-account",
},
Key: "experiment_passkey",
},
},
},
{Name: "APP_LOGLEVEL", Value: "INFO"},
{Name: "APP_CUSTOM_METRICS", Value: "false"},
{Name: "APP_JAEGER_ENABLED", Value: "false"},
Expand Down Expand Up @@ -274,17 +263,6 @@ func TestNewRouterService(t *testing.T) {
{Name: "ROUTER_CONFIG_FILE", Value: "/app/config/fiber.yml"},
{Name: "APP_SENTRY_ENABLED", Value: "true"},
{Name: "APP_SENTRY_DSN", Value: "sentry-dsn"},
{
Name: "LITMUS_PASSKEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "service-account",
},
Key: "experiment_passkey",
},
},
},
{Name: "APP_LOGLEVEL", Value: "INFO"},
{Name: "APP_CUSTOM_METRICS", Value: "false"},
{Name: "APP_JAEGER_ENABLED", Value: "false"},
Expand Down Expand Up @@ -373,17 +351,6 @@ func TestNewRouterService(t *testing.T) {
{Name: "ROUTER_CONFIG_FILE", Value: "/app/config/fiber.yml"},
{Name: "APP_SENTRY_ENABLED", Value: "true"},
{Name: "APP_SENTRY_DSN", Value: "sentry-dsn"},
{
Name: "LITMUS_PASSKEY",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "service-account",
},
Key: "experiment_passkey",
},
},
},
{Name: "APP_LOGLEVEL", Value: "INFO"},
{Name: "APP_CUSTOM_METRICS", Value: "false"},
{Name: "APP_JAEGER_ENABLED", Value: "false"},
Expand Down Expand Up @@ -472,17 +439,6 @@ func TestNewRouterService(t *testing.T) {
{Name: "ROUTER_CONFIG_FILE", Value: "/app/config/fiber.yml"},
{Name: "APP_SENTRY_ENABLED", Value: "true"},
{Name: "APP_SENTRY_DSN", Value: "sentry-dsn"},
{
Name: "",
ValueFrom: &corev1.EnvVarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "service-account",
},
Key: "experiment_passkey",
},
},
},
{Name: "APP_LOGLEVEL", Value: "INFO"},
{Name: "APP_CUSTOM_METRICS", Value: "false"},
{Name: "APP_JAEGER_ENABLED", Value: "false"},
Expand Down
24 changes: 10 additions & 14 deletions api/turing/cluster/servicebuilder/service_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ import (
const (
secretVolume = "svc-acct-secret-volume"
secretMountPath = "/var/secret/"
// Kubernetes secret key name for usage in: router, ensembler, enricher, experiment-engine.
// Kubernetes secret key name for usage in: router, ensembler, enricher.
// They will share the same Kubernetes secret for every RouterVersion deployment.
// Hence, the key name should be used to retrieve different credentials.
secretKeyNameRouter = "router-service-account.json"
secretKeyNameEnsembler = "ensembler-service-account.json"
secretKeyNameEnricher = "enricher-service-account.json"
secretKeyNameExperiment = "experiment_passkey"
secretKeyNameRouter = "router-service-account.json"
secretKeyNameEnsembler = "ensembler-service-account.json"
secretKeyNameEnricher = "enricher-service-account.json"
)

var ComponentTypes = struct {
Expand Down Expand Up @@ -108,7 +107,6 @@ type ClusterServiceBuilder interface {
routerServiceAccountKey string,
enricherServiceAccountKey string,
ensemblerServiceAccountKey string,
experimentPasskey string,
) *cluster.Secret
GetRouterServiceName(ver *models.RouterVersion) string
}
Expand Down Expand Up @@ -289,22 +287,20 @@ func (sb *clusterSvcBuilder) NewEnsemblerService(
})
}

// NewSecret creates a new `cluster.Secret` secret from the given service accounts and/or experiment-engine keys.
// If [router/enricher/ensembler]ServiceAccountKey or experimentPasskey is empty no secret key will be created
// for that component. This happens when user does not specify experiment-engine pass key or service accounts.
// NewSecret creates a new `cluster.Secret` secret from the given service accounts.
// If [router/enricher/ensembler]ServiceAccountKey is empty no secret key will be created
// for that component. This happens when user does not specify service accounts.
func (sb *clusterSvcBuilder) NewSecret(
routerVersion *models.RouterVersion,
project *mlp.Project,
routerServiceAccountKey string,
enricherServiceAccountKey string,
ensemblerServiceAccountKey string,
experimentPasskey string,
) *cluster.Secret {
data := map[string]string{
secretKeyNameRouter: routerServiceAccountKey,
secretKeyNameEnricher: enricherServiceAccountKey,
secretKeyNameEnsembler: ensemblerServiceAccountKey,
secretKeyNameExperiment: experimentPasskey,
secretKeyNameRouter: routerServiceAccountKey,
secretKeyNameEnricher: enricherServiceAccountKey,
secretKeyNameEnsembler: ensemblerServiceAccountKey,
}
return &cluster.Secret{
Name: fmt.Sprintf(
Expand Down
Loading

0 comments on commit 89818ca

Please sign in to comment.