Skip to content

Commit

Permalink
Merge pull request #492 from SeldonIO/491-ambassador-v1api
Browse files Browse the repository at this point in the history
ambassador v1 api
  • Loading branch information
ukclivecox committed Apr 8, 2019
2 parents 41655e1 + 956c835 commit 5f4d0d6
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private String getAmbassadorAnnotation(SeldonDeployment mlDep,String serviceName
final String customRegexHeader = mlDep.getSpec().getAnnotationsOrDefault(Constants.AMBASSADOR_REGEX_HEADER_ANNOTATION, null);

final String restMapping = "---\n"+
"apiVersion: ambassador/v0\n" +
"apiVersion: ambassador/v1\n" +
"kind: Mapping\n" +
"name: seldon_"+mlDep.getMetadata().getName()+"_rest_mapping\n" +
"prefix: /seldon/"+serviceNameExternal+"/\n" +
Expand All @@ -530,7 +530,7 @@ private String getAmbassadorAnnotation(SeldonDeployment mlDep,String serviceName
(StringUtils.isNotEmpty(weight) ? ("weight: "+ weight + "\n") : "") +
(StringUtils.isNotEmpty(shadowing) ? ("shadow: true\n") : "");
final String grpcMapping = "---\n"+
"apiVersion: ambassador/v0\n" +
"apiVersion: ambassador/v1\n" +
"kind: Mapping\n" +
"name: "+mlDep.getMetadata().getName()+"_grpc_mapping\n" +
"grpc: true\n" +
Expand All @@ -546,7 +546,7 @@ private String getAmbassadorAnnotation(SeldonDeployment mlDep,String serviceName
(StringUtils.isNotEmpty(shadowing) ? ("shadow: true\n") : "");

final String restMappingNamespaced = "---\n"+
"apiVersion: ambassador/v0\n" +
"apiVersion: ambassador/v1\n" +
"kind: Mapping\n" +
"name: seldon_"+namespace+"_"+mlDep.getMetadata().getName()+"_rest_mapping\n" +
"prefix: /seldon/"+namespace+"/"+serviceNameExternal+"/\n" +
Expand All @@ -558,7 +558,7 @@ private String getAmbassadorAnnotation(SeldonDeployment mlDep,String serviceName
(StringUtils.isNotEmpty(shadowing) ? ("shadow: true\n") : "");

final String grpcMappingNamespaced = "---\n"+
"apiVersion: ambassador/v0\n" +
"apiVersion: ambassador/v1\n" +
"kind: Mapping\n" +
"name: "+namespace+"_"+mlDep.getMetadata().getName()+"_grpc_mapping\n" +
"grpc: true\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void checkAmbassadorCanary() throws IOException, SeldonDeploymentExceptio
System.out.println(ambassadorConfig);
Assert.assertTrue(ambassadorConfig.indexOf("weight: 25\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("prefix: /seldon/default/example/\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v0")==4);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v1")==4);
}

@Test
Expand All @@ -61,7 +61,7 @@ public void checkAmbassadorShadow() throws IOException, SeldonDeploymentExceptio
System.out.println(ambassadorConfig);
Assert.assertTrue(ambassadorConfig.indexOf("shadow: true\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("prefix: /seldon/default/example/\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v0")==4);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v1")==4);
}

@Test
Expand All @@ -79,7 +79,7 @@ public void checkAmbassadorHeader() throws IOException, SeldonDeploymentExceptio
System.out.println(ambassadorConfig);
Assert.assertTrue(ambassadorConfig.indexOf(" location: london\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("prefix: /seldon/default/example/\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v0")==4);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v1")==4);
}

@Test
Expand All @@ -97,7 +97,7 @@ public void checkAmbassadorCustomConfig() throws IOException, SeldonDeploymentEx
System.out.println(ambassadorConfig);
Assert.assertTrue(ambassadorConfig.indexOf("1234")==0);
Assert.assertFalse(ambassadorConfig.indexOf("prefix: /seldon/default/example/\n")>0);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v0")==-1);
Assert.assertTrue(ambassadorConfig.indexOf("apiVersion: ambassador/v1")==-1);
}

}
2 changes: 1 addition & 1 deletion doc/source/graph/ambassador.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ To understand more about the Ambassador configuration for this see [their docs o
The above discussed configurations should cover most cases but there maybe a case where you want to have a very particular Ambassador configuration under your control. You can acheieve this by adding your confguration as an annotation to your Seldon Deployment resource.

* `seldon.io/ambassador-config:<configuration>` : The custom ambassador configuration
* Example: `"seldon.io/ambassador-config":"apiVersion: ambassador/v0\nkind: Mapping\nname: seldon_example_rest_mapping\nprefix: /mycompany/ml/\nservice: production-model-example.seldon:8000\ntimeout_ms: 3000"`
* Example: `"seldon.io/ambassador-config":"apiVersion: ambassador/v1\nkind: Mapping\nname: seldon_example_rest_mapping\nprefix: /mycompany/ml/\nservice: production-model-example.seldon:8000\ntimeout_ms: 3000"`

A worked example for [custom Ambassador config](../examples/ambassador_custom.html) is provided.

2 changes: 2 additions & 0 deletions doc/source/workflow/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Check if the pods are running successfully.
If your model is running and you are using Ambassador for ingress and are having problems check the diagnostics page of Ambassador. See [here](https://www.getambassador.io/reference/diagnostics/). You can then fnd out what path your model can be found under to ensure the URL you are using is correct.
If your ambassador isn't running at all then check the pod logs with `kubectl logs <pod_name>`. Note that if ambassador is installed with cluster-wide scope then its rbac should also not be namespaced, otherwise a there will be a permissions error.
## I get 500s when calling my model over the API
Check the logs of your running model pods.
Expand Down
2 changes: 1 addition & 1 deletion examples/ambassador/custom/model_custom_ambassador.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"spec": {
"name": "production-model",
"annotations": {
"seldon.io/ambassador-config":"apiVersion: ambassador/v0\nkind: Mapping\nname: seldon_example_rest_mapping\nprefix: /mycompany/ml/\nservice: production-model-example.seldon:8000\ntimeout_ms: 3000"
"seldon.io/ambassador-config":"apiVersion: ambassador/v1\nkind: Mapping\nname: seldon_example_rest_mapping\nprefix: /mycompany/ml/\nservice: production-model-example.seldon:8000\ntimeout_ms: 3000"
},
"predictors": [
{
Expand Down
5 changes: 5 additions & 0 deletions helm-charts/seldon-core/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ambassador:
enabled: false
image:
tag: 0.53.1
replicaCount: 1
resources:
limits:
Expand All @@ -25,6 +27,9 @@ ambassador:
rbac:
create: true
namespaced: true
securityContext:
runAsUser: 0
runAsGroup: 0
# scope will be cluster wide unless below is set
# env:
# AMBASSADOR_SINGLE_NAMESPACE: "true"
Expand Down
4 changes: 2 additions & 2 deletions testing/scripts/k8s_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def create_seldon_clusterwide_ksonnet(request):
wait_seldon_ready()
setup_finalizer_ksonnet(request)

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def port_forward(request):
print("Setup: Port forward")
p1 = Popen("kubectl port-forward $(kubectl get pods -n seldon -l app=seldon-apiserver-container-app -o jsonpath='{.items[0].metadata.name}') -n seldon 8002:8080",stdout=subprocess.PIPE,shell=True, preexec_fn=os.setsid)
Expand All @@ -120,7 +120,7 @@ def fin():

request.addfinalizer(fin)

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def port_forward_docker_repo(request):
print("port-forward docker")
p1 = Popen("POD_NAME=$(kubectl get pods -l app=docker-private-registry -n default |sed -e '1d'|awk '{print $1}') && kubectl port-forward ${POD_NAME} 5000:5000 -n default",stdout=subprocess.PIPE,shell=True, preexec_fn=os.setsid)
Expand Down
10 changes: 5 additions & 5 deletions testing/scripts/seldon_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_token(oauth_key,oauth_secret,namespace,endpoint):
token = response.json()["access_token"]
return token

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def rest_request_api_gateway(oauth_key,oauth_secret,namespace,endpoint="localhost:8002",data_size=5,rows=1,data=None):
token = get_token(oauth_key,oauth_secret,namespace,endpoint)
if data is None:
Expand All @@ -42,7 +42,7 @@ def rest_request_api_gateway(oauth_key,oauth_secret,namespace,endpoint="localhos
json=payload)
return response

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def grpc_request_api_gateway(oauth_key,oauth_secret,namespace,rest_endpoint="localhost:8002",grpc_endpoint="localhost:8003",data_size=5,rows=1,data=None):
token = get_token(oauth_key,oauth_secret,namespace,rest_endpoint)
if data is None:
Expand All @@ -63,7 +63,7 @@ def grpc_request_api_gateway(oauth_key,oauth_secret,namespace,rest_endpoint="loc
response = stub.Predict(request=request,metadata=metadata)
return response

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def rest_request_ambassador(deploymentName,namespace,endpoint="localhost:8003",data_size=5,rows=1,data=None):
if data is None:
shape, arr = create_random_data(data_size,rows)
Expand All @@ -81,7 +81,7 @@ def rest_request_ambassador(deploymentName,namespace,endpoint="localhost:8003",d
json=payload)
return response

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def rest_request_ambassador_auth(deploymentName,namespace,username,password,endpoint="localhost:8003",data_size=5,rows=1,data=None):
if data is None:
shape, arr = create_random_data(data_size,rows)
Expand All @@ -101,7 +101,7 @@ def rest_request_ambassador_auth(deploymentName,namespace,username,password,endp
auth=HTTPBasicAuth(username, password))
return response

@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=7)
@retry(wait_exponential_multiplier=1000, wait_exponential_max=10000, stop_max_attempt_number=5)
def grpc_request_ambassador(deploymentName,namespace,endpoint="localhost:8004",data_size=5,rows=1,data=None):
if data is None:
shape, arr = create_random_data(data_size,rows)
Expand Down

0 comments on commit 5f4d0d6

Please sign in to comment.