def test_proto_seldon_runtime_data_route(cls, client_gets_metrics): user_object = cls() seldon_metrics = SeldonMetrics() app = SeldonModelGRPC(user_object, seldon_metrics) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor(shape=(2, 1), values=np.array([1, 2])) ) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Route(request, None) j = json.loads(json_format.MessageToJson(resp)) assert j["data"] == { "names": ["t:0"], "tensor": {"shape": [1, 1], "values": [22.0]}, } assert j["meta"]["tags"] == EXPECTED_TAGS assert ("metrics" in j["meta"]) == client_gets_metrics data = seldon_metrics.data[os.getpid()] verify_seldon_metrics(data, 1, [0.0202], ROUTER_METRIC_METHOD_TAG) resp = app.Route(request, None) j = json.loads(json_format.MessageToJson(resp)) assert j["data"] == { "names": ["t:0"], "tensor": {"shape": [1, 1], "values": [22.0]}, } assert j["meta"]["tags"] == EXPECTED_TAGS assert ("metrics" in j["meta"]) == client_gets_metrics data = seldon_metrics.data[os.getpid()] verify_seldon_metrics(data, 2, [0.0202, 0.0202], ROUTER_METRIC_METHOD_TAG)
def test_proto_seldon_metrics_route(cls): user_object = cls() seldon_metrics = SeldonMetrics() app = SeldonModelGRPC(user_object, seldon_metrics) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor(shape=(2, 1), values=np.array([1, 2]))) request = prediction_pb2.SeldonMessage(data=datadef) app.Route(request, None) data = seldon_metrics.data[os.getpid()] assert data["GAUGE", "mygauge"]["value"] == 100 assert data["GAUGE", "customtag"]["value"] == 200 assert data["GAUGE", "customtag"]["tags"] == {"mytag": "mytagvalue"} assert data["COUNTER", "mycounter"]["value"] == 1 assert np.allclose( np.histogram([20.2 / 1000], BINS)[0], data["TIMER", "mytimer"]["value"][0]) assert np.allclose(data["TIMER", "mytimer"]["value"][1], 0.0202) app.Route(request, None) data = seldon_metrics.data[os.getpid()] assert data["GAUGE", "mygauge"]["value"] == 100 assert data["GAUGE", "customtag"]["value"] == 200 assert data["GAUGE", "customtag"]["tags"] == {"mytag": "mytagvalue"} assert data["COUNTER", "mycounter"]["value"] == 2 assert np.allclose( np.histogram([20.2 / 1000, 20.2 / 1000], BINS)[0], data["TIMER", "mytimer"]["value"][0], ) assert np.allclose(data["TIMER", "mytimer"]["value"][1], 0.0404)
def test_proto_seldon_metrics_route(cls, client_gets_metrics): user_object = cls() seldon_metrics = SeldonMetrics() app = SeldonModelGRPC(user_object, seldon_metrics) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor(shape=(2, 1), values=np.array([1, 2]))) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Route(request, None) assert ("metrics" in json.loads( json_format.MessageToJson(resp))["meta"]) == client_gets_metrics data = seldon_metrics.data[os.getpid()] verify_seldon_metrics(data, 1, [0.0202], ROUTER_METRIC_METHOD_TAG) resp = app.Route(request, None) assert ("metrics" in json.loads( json_format.MessageToJson(resp))["meta"]) == client_gets_metrics data = seldon_metrics.data[os.getpid()] verify_seldon_metrics(data, 2, [0.0202, 0.0202], ROUTER_METRIC_METHOD_TAG)
def test_router_proto_lowlevel_raw_ok(): user_object = UserObjectLowLevelRaw() app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor(shape=(2, 1), values=arr)) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Route(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) logging.info(j) assert j["data"]["tensor"]["shape"] == [1, 1] assert j["data"]["tensor"]["values"] == [1]
def test_router_proto_ok(): user_object = UserObject() app = SeldonModelGRPC(user_object) arr = np.array([1, 2]) datadef = prediction_pb2.DefaultData( tensor=prediction_pb2.Tensor(shape=(2, 1), values=arr)) request = prediction_pb2.SeldonMessage(data=datadef) resp = app.Route(request, None) jStr = json_format.MessageToJson(resp) j = json.loads(jStr) logging.info(j) assert j["meta"]["tags"] == {"mytag": 1} # add default type assert j["meta"]["metrics"][0]["key"] == user_object.metrics()[0]["key"] assert j["meta"]["metrics"][0]["value"] == user_object.metrics( )[0]["value"] assert j["data"]["tensor"]["shape"] == [1, 1] assert j["data"]["tensor"]["values"] == [22]