From 41f3894ba04484f08352504a167b9344ed48e49d Mon Sep 17 00:00:00 2001 From: dayko Date: Fri, 27 Oct 2023 14:46:57 +0800 Subject: [PATCH] algo: fix metric name fetching --- algorithm/kapacity/portrait/horizontal/predictive/main.py | 8 ++------ algorithm/kapacity/timeseries/forecasting/train.py | 7 ++----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/algorithm/kapacity/portrait/horizontal/predictive/main.py b/algorithm/kapacity/portrait/horizontal/predictive/main.py index 268984d..e7f7140 100644 --- a/algorithm/kapacity/portrait/horizontal/predictive/main.py +++ b/algorithm/kapacity/portrait/horizontal/predictive/main.py @@ -196,11 +196,7 @@ def fetch_metrics_history(args, env, hp_cr): scale_target, start, end) metric_ctx.replicas_history = replica_history.rename(columns={'value': 'replicas'}) else: - if metric_type == 'Object': - metric_name = metric['object']['metric']['name'] - elif metric_type == 'External': - metric_name = metric['external']['metric']['name'] - else: + if metric_type != 'Object' and metric_type != 'External': raise RuntimeError('MetricTypeError') traffic_history = query.fetch_metrics(env.metrics_server_addr, env.namespace, metric, scale_target, start, end) metric_ctx.traffics_history_dict[metric_name] = traffic_history @@ -215,7 +211,7 @@ def compute_resource_target(namespace, resource, scale_target): if target['type'] == 'Value': raise RuntimeError('UnsupportedResourceTargetType') elif target['type'] == 'AverageValue': - return target['averageValue'] + return float(utils.parse_quantity(target['averageValue'])) elif target['type'] == 'Utilization': return (target['averageUtilization'] / 100) * fetch_workload_pod_request(namespace, resource_name, scale_target) diff --git a/algorithm/kapacity/timeseries/forecasting/train.py b/algorithm/kapacity/timeseries/forecasting/train.py index 322ee9e..27db4e8 100644 --- a/algorithm/kapacity/timeseries/forecasting/train.py +++ b/algorithm/kapacity/timeseries/forecasting/train.py @@ -98,12 +98,9 @@ def fetch_history_metrics(args, target): metric=metric, start=start, end=end) - if metric['type'] == 'Object': - df_metric['metric'] = metric['object']['metric']['name'] - elif metric['type'] == 'External': - df_metric['metric'] = metric['external']['metric']['name'] - else: + if metric['type'] != 'Object' and metric['type'] != 'External': raise RuntimeError('UnsupportedMetricType') + df_metric['metric'] = metric['name'] df_metric['workload'] = '%s/%s' % (workload_namespace, workload_name) df = pd.concat([df, df_metric]) return df