Skip to content

Commit

Permalink
Algo: enable ReadyPodsOnly feature filtering for resource metrics query
Browse files Browse the repository at this point in the history
  • Loading branch information
dayko2019 committed Oct 17, 2023
1 parent db496da commit 62890a9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 31 deletions.
29 changes: 18 additions & 11 deletions algorithm/kapacity/portrait/horizontal/predictive/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.


import argparse
import datetime
import json
import os
import datetime
import pandas as pd
import sys

import grpc
from kubernetes import client, config, utils
import pandas as pd
from google.protobuf import timestamp_pb2, duration_pb2
from kubernetes import client, config, utils

import metrics.metric_pb2 as metric_pb
import metrics.provider_pb2 as provider_pb
import metrics.provider_pb2_grpc as provider_pb_grpc
import replicas_estimator as estimator

import kapacity.portrait.horizontal.predictive.replicas_estimator as estimator
import kapacity.timeseries.forecasting.forecaster as forecaster
import kapacity.portrait.horizontal.predictive.metrics.metric_pb2 as metric_pb
import kapacity.portrait.horizontal.predictive.metrics.provider_pb2 as provider_pb
import kapacity.portrait.horizontal.predictive.metrics.provider_pb2_grpc as provider_pb_grpc
sys.path.append(os.path.split(os.path.abspath(__file__))[0].rsplit('/', 3)[0])
from timeseries.forecasting import forecaster


class EnvInfo:
Expand Down Expand Up @@ -312,7 +316,8 @@ def fetch_resource_metric_history(args, namespace, metric, scale_target, start,
workload_resource = metric_pb.WorkloadResourceQuery(group_kind=group_kind,
namespace=namespace,
name=name,
resource_name=resource_name)
resource_name=resource_name,
ready_pods_only=True)
query = metric_pb.Query(type=metric_pb.WORKLOAD_RESOURCE,
workload_resource=workload_resource)
return query_metrics(args=args, query=query, start=start, end=end)
Expand All @@ -327,7 +332,8 @@ def fetch_container_resource_metric_history(args, namespace, metric, scale_targe
namespace=namespace,
name=name,
resource_name=resource_name,
container_name=container_name)
container_name=container_name,
ready_pods_only=True)
query = metric_pb.Query(type=metric_pb.WORKLOAD_CONTAINER_RESOURCE,
workload_container_resource=workload_container_resource)
return query_metrics(args=args, query=query, start=start, end=end)
Expand Down Expand Up @@ -440,7 +446,8 @@ def write_pred_replicas_to_config_map(args, env, hp_cr, pred_replicas):
last_timestamp = pred_replicas.iloc[len(pred_replicas) - 1, 0]
content = pred_replicas.set_index('timestamp', drop=True).to_dict()['pred_replicas']
expire_time = parse_timestamp_to_rfc3339(
datetime.datetime.utcfromtimestamp(last_timestamp) + datetime.timedelta(minutes=time_period_to_minutes(args.scaling_freq)))
datetime.datetime.utcfromtimestamp(last_timestamp) + datetime.timedelta(
minutes=time_period_to_minutes(args.scaling_freq)))
cmap_namespace = env.namespace
cmap_name = env.hp_name + '-result'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ message WorkloadResourceQuery {
string namespace = 2;
string name = 3;
string resource_name = 4;
bool ready_pods_only = 5;
}

message WorkloadContainerResourceQuery {
Expand All @@ -92,6 +93,7 @@ message WorkloadContainerResourceQuery {
string name = 3;
string resource_name = 4;
string container_name = 5;
bool ready_pods_only = 6;
}

message ObjectQuery {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,34 @@ class ContainerResourceQuery(_message.Message):
def __init__(self, namespace: _Optional[str] = ..., name: _Optional[str] = ..., selector: _Optional[str] = ..., resource_name: _Optional[str] = ..., container_name: _Optional[str] = ...) -> None: ...

class WorkloadResourceQuery(_message.Message):
__slots__ = ["group_kind", "namespace", "name", "resource_name"]
__slots__ = ["group_kind", "namespace", "name", "resource_name", "ready_pods_only"]
GROUP_KIND_FIELD_NUMBER: _ClassVar[int]
NAMESPACE_FIELD_NUMBER: _ClassVar[int]
NAME_FIELD_NUMBER: _ClassVar[int]
RESOURCE_NAME_FIELD_NUMBER: _ClassVar[int]
READY_PODS_ONLY_FIELD_NUMBER: _ClassVar[int]
group_kind: GroupKind
namespace: str
name: str
resource_name: str
def __init__(self, group_kind: _Optional[_Union[GroupKind, _Mapping]] = ..., namespace: _Optional[str] = ..., name: _Optional[str] = ..., resource_name: _Optional[str] = ...) -> None: ...
ready_pods_only: bool
def __init__(self, group_kind: _Optional[_Union[GroupKind, _Mapping]] = ..., namespace: _Optional[str] = ..., name: _Optional[str] = ..., resource_name: _Optional[str] = ..., ready_pods_only: bool = ...) -> None: ...

class WorkloadContainerResourceQuery(_message.Message):
__slots__ = ["group_kind", "namespace", "name", "resource_name", "container_name"]
__slots__ = ["group_kind", "namespace", "name", "resource_name", "container_name", "ready_pods_only"]
GROUP_KIND_FIELD_NUMBER: _ClassVar[int]
NAMESPACE_FIELD_NUMBER: _ClassVar[int]
NAME_FIELD_NUMBER: _ClassVar[int]
RESOURCE_NAME_FIELD_NUMBER: _ClassVar[int]
CONTAINER_NAME_FIELD_NUMBER: _ClassVar[int]
READY_PODS_ONLY_FIELD_NUMBER: _ClassVar[int]
group_kind: GroupKind
namespace: str
name: str
resource_name: str
container_name: str
def __init__(self, group_kind: _Optional[_Union[GroupKind, _Mapping]] = ..., namespace: _Optional[str] = ..., name: _Optional[str] = ..., resource_name: _Optional[str] = ..., container_name: _Optional[str] = ...) -> None: ...
ready_pods_only: bool
def __init__(self, group_kind: _Optional[_Union[GroupKind, _Mapping]] = ..., namespace: _Optional[str] = ..., name: _Optional[str] = ..., resource_name: _Optional[str] = ..., container_name: _Optional[str] = ..., ready_pods_only: bool = ...) -> None: ...

class ObjectQuery(_message.Message):
__slots__ = ["group_kind", "namespace", "name", "selector", "metric"]
Expand Down

0 comments on commit 62890a9

Please sign in to comment.