Skip to content

Commit

Permalink
algo: fix metric name fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
dayko2019 committed Oct 27, 2023
1 parent 0d434da commit 41f3894
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
8 changes: 2 additions & 6 deletions algorithm/kapacity/portrait/horizontal/predictive/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
7 changes: 2 additions & 5 deletions algorithm/kapacity/timeseries/forecasting/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 41f3894

Please sign in to comment.