def save_metric_meta(job_id, component_name, task_id, role, party_id): request_data = request.json tracker = Tracking(job_id=job_id, component_name=component_name, task_id=task_id, role=role, party_id=party_id) metric_meta = deserialize_b64(request_data['metric_meta']) tracker.save_metric_meta(metric_namespace=request_data['metric_namespace'], metric_name=request_data['metric_name'], metric_meta=metric_meta, job_level=request_data['job_level']) return get_json_result()
def read_data_from_db(self, metric_namespace: str, metric_name: str, data_type, job_level=False): with DB.connection_context(): metrics = [] try: query_sql = 'select f_key, f_value from t_tracking_metric_{} where ' \ 'f_job_id = "{}" and f_component_name = "{}" and f_role = "{}" and f_party_id = "{}"' \ 'and f_task_id = "{}" and f_metric_namespace = "{}" and f_metric_name= "{}" and f_type="{}" order by f_id'.format( self.get_table_index(), self.job_id, self.component_name if not job_level else 'dag', self.role, self.party_id, self.task_id, metric_namespace, metric_name, data_type) cursor = DB.execute_sql(query_sql) for row in cursor.fetchall(): yield deserialize_b64(row[0]), deserialize_b64(row[1]) except Exception as e: stat_logger.exception(e) return metrics