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

Remove the default route configuration #198

Merged
merged 11 commits into from
May 20, 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
4 changes: 0 additions & 4 deletions api/api/openapi.bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1883,7 +1883,6 @@ components:
- values
operator: in
error: error
default_route: default_route
version: 5
log_config:
custom_metrics_enabled: true
Expand Down Expand Up @@ -2018,8 +2017,6 @@ components:
items:
$ref: '#/components/schemas/Route'
type: array
default_route:
type: string
experiment_engine:
$ref: '#/components/schemas/ExperimentConfig'
resource_request:
Expand Down Expand Up @@ -2737,7 +2734,6 @@ components:
ensembler:
$ref: '#/components/schemas/RouterEnsemblerConfig'
required:
- default_route_id
- experiment_engine
- log_config
- routes
Expand Down
3 changes: 0 additions & 3 deletions api/api/specs/routers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ components:
type: "array"
items:
$ref: "#/components/schemas/Route"
default_route:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this was ever meant to be there, it should have only been default_route_id. Removing it.

type: "string"
experiment_engine:
$ref: "experiment-engines.yaml#/components/schemas/ExperimentConfig"
resource_request:
Expand Down Expand Up @@ -605,7 +603,6 @@ components:
type: "object"
required:
- routes
- default_route_id
- experiment_engine
- timeout
- log_config
Expand Down
6 changes: 3 additions & 3 deletions api/e2e/test/01_create_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestCreateRouter(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestCreateRouter(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand All @@ -128,7 +128,7 @@ func TestCreateRouter(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand Down
2 changes: 1 addition & 1 deletion api/e2e/test/02_update_router_invalid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestUpdateRouterInvalidConfig(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand Down
2 changes: 1 addition & 1 deletion api/e2e/test/03_create_router_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestCreateRouterVersion(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand Down
6 changes: 3 additions & 3 deletions api/e2e/test/08_deploy_router_with_traffic_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestDeployRouterWithTrafficRules(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestDeployRouterWithTrafficRules(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
},
{
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestDeployRouterWithTrafficRules(t *testing.T) {
"data": {
"version": "control"
},
"is_default": true,
"is_default": false,
"route": "control"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"timeout": "5s"
}
],
"default_route_id": "control",
"experiment_engine": {
"type": "proprietary",
"config": {
Expand Down
1 change: 0 additions & 1 deletion api/e2e/test/testdata/create_router_version.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"timeout": "5s"
}
],
"default_route_id": "control",
"experiment_engine": {
"type": "nop"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"routes": ["treatment-b"]
}
],
"default_route_id": "control",
"experiment_engine": {
"type": "nop"
},
Expand Down
1 change: 0 additions & 1 deletion api/e2e/test/testdata/update_router_high_cpu.json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"timeout": "5s"
}
],
"default_route_id": "control",
"experiment_engine": {
"type": "nop"
},
Expand Down
8 changes: 6 additions & 2 deletions api/turing/api/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type CreateOrUpdateRouterRequest struct {
// RouterConfig defines the properties of the specific router version
type RouterConfig struct {
Routes models.Routes `json:"routes" validate:"required"`
DefaultRouteID string `json:"default_route_id" validate:"required"`
DefaultRouteID *string `json:"default_route_id"`
TrafficRules models.TrafficRules `json:"rules" validate:"dive"`
ExperimentEngine *ExperimentEngineConfig `json:"experiment_engine" validate:"required,dive"`
ResourceRequest *models.ResourceRequest `json:"resource_request"`
Expand Down Expand Up @@ -114,13 +114,17 @@ func (r RouterConfig) BuildRouterVersion(
expSvc service.ExperimentsService,
ensemblersSvc service.EnsemblersService,
) (rv *models.RouterVersion, err error) {
var defaultRouteID string
if r.DefaultRouteID != nil {
defaultRouteID = *r.DefaultRouteID
}
rv = &models.RouterVersion{
RouterID: router.ID,
Router: router,
Image: defaults.Image,
Status: models.RouterVersionStatusPending,
Routes: r.Routes,
DefaultRouteID: r.DefaultRouteID,
DefaultRouteID: defaultRouteID,
TrafficRules: r.TrafficRules,
ExperimentEngine: &models.ExperimentEngine{
Type: r.ExperimentEngine.Type,
Expand Down
35 changes: 32 additions & 3 deletions api/turing/api/request/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func makeTuringExperimentConfig(clientPasskey string) json.RawMessage {
return expEngineConfig
}

var defaultRouteID string = "default"
var validRouterConfig = RouterConfig{
Routes: []*models.Route{
{
Expand All @@ -74,7 +75,7 @@ var validRouterConfig = RouterConfig{
Timeout: "6s",
},
},
DefaultRouteID: "default",
DefaultRouteID: &defaultRouteID,
ExperimentEngine: &ExperimentEngineConfig{
Type: "standard",
Config: makeTuringExperimentConfig("dummy_passkey"),
Expand Down Expand Up @@ -141,7 +142,7 @@ var invalidRouterConfig = RouterConfig{
Timeout: "6s",
},
},
DefaultRouteID: "default",
DefaultRouteID: &defaultRouteID,
ExperimentEngine: &ExperimentEngineConfig{
Type: "standard",
Config: makeTuringExperimentConfig("dummy_passkey"),
Expand Down Expand Up @@ -220,7 +221,6 @@ func TestRequestBuildRouter(t *testing.T) {
}

func TestRequestBuildRouterVersionLoggerConfiguration(t *testing.T) {

baseRequest := CreateOrUpdateRouterRequest{
Environment: "env",
Name: "router",
Expand Down Expand Up @@ -459,6 +459,35 @@ func TestRequestBuildRouterVersionWithUnavailablePyFuncEnsembler(t *testing.T) {
assert.Nil(t, got)
}

func TestRequestBuildRouterVersionNoDefaultRoute(t *testing.T) {
defaults := &config.RouterDefaults{
Image: "routerimage",
}
router := &models.Router{
ProjectID: models.ID(1),
EnvironmentName: "env",
Name: "router",
Status: "pending",
}
cfg := RouterConfig{
Routes: []*models.Route{
{
ID: "default",
Type: "PROXY",
Endpoint: "endpoint",
Timeout: "6s",
},
},
Timeout: "10s",
ExperimentEngine: &ExperimentEngineConfig{Type: "nop"},
LogConfig: &LogConfig{ResultLoggerType: "nop"},
}

rv, err := cfg.BuildRouterVersion(router, defaults, nil, nil, nil)
assert.NoError(t, err)
assert.Equal(t, "", rv.DefaultRouteID)
}

func TestBuildExperimentEngineConfig(t *testing.T) {
// Set up mock Crypto service
cs := &mocks.CryptoService{}
Expand Down
4 changes: 3 additions & 1 deletion api/turing/cluster/servicebuilder/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,11 @@ func buildFiberConfigMap(
) (*cluster.ConfigMap, error) {
// Create the properties map for fiber's routing strategy or fanIn
propsMap := map[string]interface{}{
"default_route_id": ver.DefaultRouteID,
"experiment_engine": ver.ExperimentEngine.Type,
}
if ver.DefaultRouteID != "" {
propsMap["default_route_id"] = ver.DefaultRouteID
}
if ver.ExperimentEngine.Type != models.ExperimentEngineTypeNop {
expEngineProps := experimentCfg
// Tell router, that the experiment runner is implemented as RPC plugin
Expand Down
74 changes: 74 additions & 0 deletions api/turing/cluster/servicebuilder/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func TestNewRouterService(t *testing.T) {
require.NoError(t, err)
cfgmapExpEngine, err := tu.ReadFile(filepath.Join(testDataBasePath, "router_configmap_exp_engine.yml"))
require.NoError(t, err)
cfgmapNoDefaultRoute, err := tu.ReadFile(filepath.Join(testDataBasePath, "router_configmap_no_default_route.yml"))
require.NoError(t, err)

// Define tests
tests := map[string]testSuiteNewService{
Expand Down Expand Up @@ -515,6 +517,78 @@ func TestNewRouterService(t *testing.T) {
UserContainerLimitRequestFactor: 1.5,
},
},
"success | no default route": {
filePath: filepath.Join(testDataBasePath, "router_version_no_default_route.json"),
expRawConfig: json.RawMessage(`{}`),
expected: &cluster.KnativeService{
BaseService: &cluster.BaseService{
Name: "test-svc-turing-router-1",
Namespace: "test-project",
Image: "asia.gcr.io/gcp-project-id/turing-router:latest",
CPURequests: resource.MustParse("400m"),
MemoryRequests: resource.MustParse("512Mi"),
LivenessHTTPGetPath: "/v1/internal/live",
ReadinessHTTPGetPath: "/v1/internal/ready",
ConfigMap: &cluster.ConfigMap{
Name: "test-svc-turing-fiber-config-1",
FileName: "fiber.yml",
Data: string(cfgmapNoDefaultRoute),
Labels: map[string]string{
"app": "test-svc",
"environment": "",
"orchestrator": "turing",
"stream": "test-stream",
"team": "test-team",
},
},
Envs: []corev1.EnvVar{
{Name: "APP_NAME", Value: "test-svc-1.test-project"},
{Name: "APP_ENVIRONMENT", Value: "test-env"},
{Name: "ROUTER_TIMEOUT", Value: "5s"},
{Name: "APP_JAEGER_COLLECTOR_ENDPOINT", Value: "jaeger-endpoint"},
{Name: "ROUTER_CONFIG_FILE", Value: "/app/config/fiber.yml"},
{Name: "APP_SENTRY_ENABLED", Value: "true"},
{Name: "APP_SENTRY_DSN", Value: "sentry-dsn"},
{Name: "APP_LOGLEVEL", Value: "INFO"},
{Name: "APP_CUSTOM_METRICS", Value: "false"},
{Name: "APP_JAEGER_ENABLED", Value: "false"},
{Name: "APP_RESULT_LOGGER", Value: "nop"},
{Name: "APP_FIBER_DEBUG_LOG", Value: "false"},
},
Labels: map[string]string{
"app": "test-svc",
"environment": "",
"orchestrator": "turing",
"stream": "test-stream",
"team": "test-team",
},
Volumes: []corev1.Volume{
{
Name: routerConfigMapVolume,
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: "test-svc-turing-fiber-config-1",
},
},
},
},
},
VolumeMounts: []corev1.VolumeMount{
{
Name: routerConfigMapVolume,
MountPath: routerConfigMapMountPath,
},
},
},
ContainerPort: 8080,
MinReplicas: 2,
MaxReplicas: 4,
TargetConcurrency: 1,
QueueProxyResourcePercentage: 20,
UserContainerLimitRequestFactor: 1.5,
},
},
"failure missing bigquery": {
filePath: filepath.Join(testDataBasePath, "router_version_missing_bigquery.json"),
err: "Missing BigQuery logger config",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
id: test-svc
routes:
- endpoint: http://www.mocky.io/v2/5e4caccc310000e2cad8c071
id: control
timeout: 2s
type: PROXY
strategy:
properties:
experiment_engine: nop
type: fiber.DefaultTuringRoutingStrategy
type: EAGER_ROUTER
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"router": {
"project_id": 10,
"environment_name": "id-dev",
"name": "test-svc"
},
"version": 1,
"status": "deployed",
"image": "asia.gcr.io/gcp-project-id/turing-router:latest",
"routes": [
{
"id": "control",
"type": "PROXY",
"endpoint": "http://www.mocky.io/v2/5e4caccc310000e2cad8c071",
"timeout": "2s"
}
],
"experiment_engine": {
"type": "nop"
},
"resource_request": {
"min_replica": 2,
"max_replica": 4,
"cpu_request": "400m",
"memory_request": "512Mi"
},
"timeout": "5s",
"log_config": {
"log_level": "INFO",
"custom_metrics_enabled": false,
"fiber_debug_log_enabled": false,
"jaeger_enabled": false,
"result_logger_type": "nop"
}
}
Loading