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

event type parameter for req logging #4

Merged
merged 5 commits into from
Mar 6, 2020
Merged
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
17 changes: 12 additions & 5 deletions servers/cloudevents/ceserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __str__(self):
default="tensorflow.http",
help='The protocol served by the model server')
parser.add_argument('--reply_url', type=str, default="", help='URL to send reply cloudevent')
parser.add_argument('--event_type', type=str, default="", help='e.g. io.seldon.serving.inference.outlier or org.kubeflow.serving.inference.outlier')
args, _ = parser.parse_known_args()

CESERVER_LOGLEVEL = os.environ.get('CESERVER_LOGLEVEL', 'INFO').upper()
Expand All @@ -46,7 +47,7 @@ def __str__(self):

class CEServer(object):
def __init__(self, protocol: Protocol = args.protocol, http_port: int = args.http_port,
reply_url: str = args.reply_url):
reply_url: str = args.reply_url, event_type: str = args.event_type):
"""
CloudEvents server

Expand All @@ -58,18 +59,21 @@ def __init__(self, protocol: Protocol = args.protocol, http_port: int = args.htt
http port to listen on
reply_url
reply url to send response event
event_type
type of event being handled (for req logging purposes)
"""
self.registered_model: CEModel = None
self.http_port = http_port
self.protocol = protocol
self.reply_url = reply_url
self._http_server: Optional[tornado.httpserver.HTTPServer] = None
self.event_type = event_type

def create_application(self):
return tornado.web.Application([
# Outlier detector
(r"/", EventHandler,
dict(protocol=self.protocol, model=self.registered_model, reply_url=self.reply_url)),
dict(protocol=self.protocol, model=self.registered_model, reply_url=self.reply_url, event_type=self.event_type)),
# Protocol Discovery API that returns the serving protocol supported by this server.
(r"/protocol", ProtocolHandler, dict(protocol=self.protocol)),
# Prometheus Metrics API that returns metrics for model servers
Expand Down Expand Up @@ -152,7 +156,7 @@ def sendCloudEvent(event: v02.Event, url: str):

class EventHandler(tornado.web.RequestHandler):

def initialize(self, protocol: str, model: CEModel, reply_url: str):
def initialize(self, protocol: str, model: CEModel, reply_url: str, event_type: str):
"""
Event Handler

Expand All @@ -164,11 +168,13 @@ def initialize(self, protocol: str, model: CEModel, reply_url: str):
The model to use
reply_url
The reply url to send model responses

event_type
The CE event type to be sent
"""
self.protocol = protocol
self.model = model
self.reply_url = reply_url
self.event_type = event_type

def post(self):
"""
Expand Down Expand Up @@ -221,7 +227,8 @@ def post(self):
SetData(responseStr).
SetEventID(resp_event_id).
SetSource(self.model.event_source()).
SetEventType(self.model.event_type())
SetEventType(self.event_type).
SetExtensions(event.Extensions())
)
logging.debug(json.dumps(revent.Properties()))
sendCloudEvent(revent, self.reply_url)
Expand Down