-
Notifications
You must be signed in to change notification settings - Fork 834
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from cliveseldon/config
Allow Annotations to allow customizations
- Loading branch information
Showing
38 changed files
with
1,757 additions
and
142 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
api-frontend/src/main/java/io/seldon/apife/config/AnnotationsConfig.java
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,81 @@ | ||
package io.seldon.apife.config; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* | ||
* @author clive | ||
* Utility class to load annotations from kubernetes file for use by other components as config during startup | ||
* | ||
*/ | ||
@Component | ||
public class AnnotationsConfig { | ||
protected static Logger logger = LoggerFactory.getLogger(AnnotationsConfig.class.getName()); | ||
final String ANNOTATIONS_FILE = "/etc/podinfo/annotations"; | ||
|
||
final Map<String,String> annotations = new ConcurrentHashMap<>(); | ||
|
||
String readFile(String path, Charset encoding) throws IOException | ||
{ | ||
byte[] encoded = Files.readAllBytes(Paths.get(path)); | ||
return new String(encoded, encoding); | ||
} | ||
|
||
public AnnotationsConfig() throws IOException | ||
{ | ||
loadAnnotations(); | ||
} | ||
|
||
private void processAnnotation(String line) | ||
{ | ||
final String[] parts = line.split("="); | ||
if (parts.length == 2) | ||
{ | ||
final String value = parts[1].substring(1, parts[1].length()-1); //remove start and end quote | ||
annotations.put(parts[0], value); | ||
} | ||
else | ||
logger.warn("Failed to parse annotation {}",line); | ||
} | ||
|
||
private void loadAnnotations() | ||
{ | ||
try | ||
{ | ||
File f = new File(ANNOTATIONS_FILE); | ||
if(f.exists() && !f.isDirectory()) | ||
{ | ||
try (BufferedReader r = Files.newBufferedReader(Paths.get(ANNOTATIONS_FILE), StandardCharsets.UTF_8)) | ||
{ | ||
r.lines().forEach(this::processAnnotation); | ||
} | ||
} | ||
} catch (IOException e) { | ||
logger.error("Failed to load annotations file "+ANNOTATIONS_FILE,e); | ||
} | ||
logger.info("Annotations {}",annotations); | ||
} | ||
|
||
public boolean has(String key) | ||
{ | ||
return annotations.containsKey(key); | ||
} | ||
|
||
public String get(String key) | ||
{ | ||
return annotations.get(key); | ||
} | ||
|
||
} |
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,9 @@ | ||
# Annotation Based Configuration | ||
|
||
You can configure aspects of Seldon Core via annotations in the SeldonDeployment resource. Please create an issue if you would like some configuration added. | ||
|
||
# Available Annotations | ||
|
||
* ```seldon.io/grpc-max-message-size``` : Maximum gRPC message size | ||
* Location : SeldonDeployment.spec.annotations | ||
* [Example](../notebooks/resources/model_grpc_size.json) |
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,85 @@ | ||
# GRPC Max Message Size | ||
|
||
GRPC has a default max message size of 4MB. If you need to run models whose input features or output predictions are larger than this you can congifure Seldon Core to run with gRPC server/clients that handle a larger mesage size with annotations. | ||
|
||
Add the annotation ```seldon.io/grpc-max-message-size``` with the number of bytes of the largest expected message. For example the SeldonDeployment resource below sets this to 10MB: | ||
|
||
``` | ||
{ | ||
"apiVersion": "machinelearning.seldon.io/v1alpha2", | ||
"kind": "SeldonDeployment", | ||
"metadata": { | ||
"labels": { | ||
"app": "seldon" | ||
}, | ||
"name": "seldon-deployment-example" | ||
}, | ||
"spec": { | ||
"annotations": { | ||
"project_name": "FX Market Prediction", | ||
"deployment_version": "v1", | ||
"seldon.io/grpc-max-message-size":"10485760" | ||
}, | ||
"name": "test-deployment", | ||
"oauth_key": "oauth-key", | ||
"oauth_secret": "oauth-secret", | ||
"predictors": [ | ||
{ | ||
"componentSpecs": [{ | ||
"spec": { | ||
"containers": [ | ||
{ | ||
"image": "seldonio/mock_classifier_grpc:1.0", | ||
"imagePullPolicy": "IfNotPresent", | ||
"name": "classifier", | ||
"resources": { | ||
"requests": { | ||
"memory": "1Mi" | ||
} | ||
} | ||
} | ||
], | ||
"terminationGracePeriodSeconds": 20 | ||
} | ||
}], | ||
"graph": { | ||
"children": [], | ||
"name": "classifier", | ||
"endpoint": { | ||
"type" : "GRPC" | ||
}, | ||
"type": "MODEL" | ||
}, | ||
"name": "fx-market-predictor", | ||
"replicas": 1, | ||
"annotations": { | ||
"predictor_version" : "v1" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
## API OAUTH Gateway | ||
|
||
If you are using the default API OAUTH Gateway you will also need to update your Helm or Ksonnet install: | ||
|
||
For Helm add to your Helm values, for example: | ||
|
||
``` | ||
apife: | ||
annotations: | ||
seldon.io/grpc-max-message-size: "10485760" | ||
``` | ||
|
||
For Ksonnet set the parameters grpcMaxMessageSize: | ||
|
||
``` | ||
ks param set seldon-core grpcMaxMessageSize '10485760' --as-string | ||
``` | ||
|
||
## Example | ||
|
||
To see a worked example, run the Jupyter notebook [here](../notebooks/max_grpc_msg_size.ipynb). |
Oops, something went wrong.