class MetricService(MetricServiceServicer): def __init__(self, db_uri): self.db_uri = db_uri self.store = SqlAlchemyStore(db_uri) @catch_exception def registerMetricMeta(self, request, context): metric_meta_proto = request.metric_meta metric_meta = proto_to_metric_meta(metric_meta_proto) res_metric_meta = self.store.register_metric_meta( metric_meta.name, metric_meta.dataset_id, metric_meta.model_name, metric_meta.model_version, metric_meta.job_id, metric_meta.start_time, metric_meta.end_time, metric_meta.metric_type, metric_meta.uri, metric_meta.tags, metric_meta.metric_description, metric_meta.properties) return _warp_metric_meta_response(res_metric_meta) def registerMetricSummary(self, request, context): metric_summary_proto = request.metric_summary metric_summary = proto_to_metric_summary(metric_summary_proto) res_metric_summary = self.store.register_metric_summary( metric_id=metric_summary.metric_id, metric_key=metric_summary.metric_key, metric_value=metric_summary.metric_value) return _warp_metric_summary_response(res_metric_summary) def updateMetricMeta(self, request, context): metric_meta_proto = request.metric_meta if metric_meta_proto.metric_type == MetricTypeProto.DATASET: metric_type = MetricType.DATASET else: metric_type = MetricType.MODEL res_metric_meta = self.store.update_metric_meta( metric_meta_proto.uuid, metric_meta_proto.name.value if metric_meta_proto.HasField('name') else None, metric_meta_proto.dataset_id.value if metric_meta_proto.HasField('dataset_id') else None, metric_meta_proto.model_name.value if metric_meta_proto.HasField('model_name') else None, metric_meta_proto.model_version.value if metric_meta_proto.HasField('model_version') else None, metric_meta_proto.job_id.value if metric_meta_proto.HasField('job_id') else None, metric_meta_proto.start_time.value if metric_meta_proto.HasField('start_time') else None, metric_meta_proto.end_time.value if metric_meta_proto.HasField('end_time') else None, metric_type, metric_meta_proto.uri.value if metric_meta_proto.HasField('uri') else None, metric_meta_proto.tags.value if metric_meta_proto.HasField('tags') else None, metric_meta_proto.metric_description.value if metric_meta_proto.HasField('metric_description') else None, metric_meta_proto.properties if {} == metric_meta_proto.properties else None) return _warp_metric_meta_response(res_metric_meta) def updateMetricSummary(self, request, context): metric_summary_proto = request.metric_summary res_metric_summary = self.store.update_metric_summary( uuid=metric_summary_proto.uuid, metric_id=metric_summary_proto.metric_id.value if metric_summary_proto.HasField('metric_id') else None, metric_key=metric_summary_proto.metric_key.value if metric_summary_proto.HasField('metric_key') else None, metric_value=metric_summary_proto.metric_value.value if metric_summary_proto.HasField('metric_value') else None) return _warp_metric_summary_response(res_metric_summary) def getMetricMeta(self, request, context): metric_name = request.metric_name res_metric_meta = self.store.get_metric_meta(metric_name) return _warp_metric_meta_response(res_metric_meta) def getDatasetMetricMeta(self, request, context): dataset_id = request.dataset_id metric_meta = self.store.get_dataset_metric_meta(dataset_id=dataset_id) return _warp_list_metric_meta_response(metric_meta) def getModelMetricMeta(self, request, context): model_name = request.model_name model_version = request.model_version metric_meta = self.store.get_model_metric_meta( model_name=model_name, model_version=model_version) return _warp_list_metric_meta_response(metric_meta) def getMetricSummary(self, request, context): metric_id = request.metric_id metric_summary = self.store.get_metric_summary(metric_id=metric_id) return _warp_list_metric_summary_response(metric_summary) def deleteMetricMeta(self, request, context): uuid = request.uuid try: self.store.delete_metric_meta(uuid) return Response(return_code=str(ReturnCode.SUCCESS), return_msg='', data='') except Exception as e: return Response(return_code=str(ReturnCode.INTERNAL_ERROR), return_msg=str(e), data='') def deleteMetricSummary(self, request, context): uuid = request.uuid try: self.store.delete_metric_summary(uuid) return Response(return_code=str(ReturnCode.SUCCESS), return_msg='', data='') except Exception as e: return Response(return_code=str(ReturnCode.INTERNAL_ERROR), return_msg=str(e), data='')
class MetricService(MetricServiceServicer): def __init__(self, db_uri): self.db_uri = db_uri self.store = SqlAlchemyStore(self.db_uri) @catch_exception def registerMetricMeta(self, request, context): metric_meta_proto = request.metric_meta metric_meta = proto_to_metric_meta(metric_meta_proto) res_metric_meta = self.store.register_metric_meta( metric_meta.metric_name, metric_meta.metric_type, metric_meta.project_name, metric_meta.metric_desc, metric_meta.dataset_name, metric_meta.model_name, metric_meta.job_name, metric_meta.start_time, metric_meta.end_time, metric_meta.uri, metric_meta.tags, metric_meta.properties) return _warp_metric_meta_response(res_metric_meta) @catch_exception def updateMetricMeta(self, request, context): metric_meta_proto = request.metric_meta metric_meta = proto_to_metric_meta(metric_meta_proto) res_metric_meta = self.store.update_metric_meta( metric_meta.metric_name, metric_meta.metric_desc, metric_meta.project_name, metric_meta.dataset_name, metric_meta.model_name, metric_meta.job_name, metric_meta.start_time, metric_meta.end_time, metric_meta.uri, metric_meta.tags, metric_meta.properties) return _warp_metric_meta_response(res_metric_meta) @catch_exception def deleteMetricMeta(self, request, context): metric_name = request.metric_name try: self.store.delete_metric_meta(metric_name) return Response(return_code=str(ReturnCode.SUCCESS), return_msg='', data='') except Exception as e: return Response(return_code=str(ReturnCode.INTERNAL_ERROR), return_msg=str(e), data='') @catch_exception def getMetricMeta(self, request, context): metric_name = request.metric_name res_metric_meta = self.store.get_metric_meta(metric_name) return _warp_metric_meta_response(res_metric_meta) @catch_exception def listDatasetMetricMetas(self, request, context): dataset_name = request.dataset_name project_name = request.project_name.value if request.HasField( 'project_name') else None metric_metas = self.store.list_dataset_metric_metas( dataset_name=dataset_name, project_name=project_name) return _warp_list_metric_metas_response(metric_metas) @catch_exception def listModelMetricMetas(self, request, context): model_name = request.model_name project_name = request.project_name.value if request.HasField( 'project_name') else None metric_metas = self.store.list_model_metric_metas( model_name=model_name, project_name=project_name) return _warp_list_metric_metas_response(metric_metas) @catch_exception def registerMetricSummary(self, request, context): metric_summary_proto = request.metric_summary metric_summary = proto_to_metric_summary(metric_summary_proto) res_metric_summary = self.store.register_metric_summary( metric_summary.metric_name, metric_summary.metric_key, metric_summary.metric_value, metric_summary.metric_timestamp, metric_summary.model_version, metric_summary.job_execution_id) return _warp_metric_summary_response(res_metric_summary) @catch_exception def updateMetricSummary(self, request, context): metric_summary_proto = request.metric_summary metric_summary = proto_to_metric_summary(metric_summary_proto) res_metric_summary = self.store.update_metric_summary( metric_summary.uuid, metric_summary.metric_name, metric_summary.metric_key, metric_summary.metric_value, metric_summary.metric_timestamp, metric_summary.model_version, metric_summary.job_execution_id) return _warp_metric_summary_response(res_metric_summary) @catch_exception def deleteMetricSummary(self, request, context): uuid = request.uuid try: self.store.delete_metric_summary(uuid) return Response(return_code=str(ReturnCode.SUCCESS), return_msg='', data='') except Exception as e: return Response(return_code=str(ReturnCode.INTERNAL_ERROR), return_msg=str(e), data='') @catch_exception def getMetricSummary(self, request, context): uuid = request.uuid metric_summary = self.store.get_metric_summary(uuid) return _warp_metric_summary_response(metric_summary) @catch_exception def listMetricSummaries(self, request, context): metric_name = request.metric_name.value if request.HasField( 'metric_name') else None metric_key = request.metric_key.value if request.HasField( 'metric_key') else None model_version = request.model_version.value if request.HasField( 'model_version') else None start_time = request.start_time.value if request.HasField( 'start_time') else None end_time = request.end_time.value if request.HasField( 'end_time') else None metric_summaries = self.store.list_metric_summaries( metric_name, metric_key, model_version, start_time, end_time) return _warp_list_metric_summaries_response(metric_summaries)