Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

algo: fix metric name fetching #79

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions algorithm/kapacity/portrait/horizontal/predictive/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,9 @@ 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')
metric_name = metric['name']
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 +212,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
10 changes: 3 additions & 7 deletions algorithm/kapacity/timeseries/forecasting/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,16 @@ def fetch_history_metrics(args, target):

for i in range(len(target['metrics'])):
metric = target['metrics'][i]
if metric['type'] != 'Object' and metric['type'] != 'External':
raise RuntimeError('UnsupportedMetricType')
workload_namespace = target['workloadNamespace']
workload_name = target['workloadName']

df_metric = query.fetch_metrics(addr=args.metrics_server_addr,
namespace=workload_namespace,
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:
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