Add autoscaling metrics aggregation function#56871
Conversation
Signed-off-by: abrar <abrar@anyscale.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable feature by allowing the autoscaling metrics aggregation function to be configured. Users can now choose between 'mean', 'max', and 'min' aggregation, providing more flexibility for different use cases. The implementation is solid, with the introduction of a new AggregationFunction enum, an aggregate_timeseries utility, and updates to the AutoscalingConfig. The changes are also well-covered by new and updated tests. I have a few minor suggestions to improve the docstring, memory efficiency, and exception handling.
Signed-off-by: abrar <abrar@anyscale.com>
| def aggregate_timeseries( | ||
| timeseries: List[TimeStampedValue], | ||
| aggregation_function: AggregationFunction, | ||
| last_window_s: float = 1.0, | ||
| ) -> Optional[float]: | ||
| """Aggregate the values in a timeseries using a specified function.""" | ||
| if aggregation_function == AggregationFunction.MEAN: | ||
| return time_weighted_average(timeseries, last_window_s=last_window_s) | ||
| elif aggregation_function == AggregationFunction.MAX: | ||
| return max(ts.value for ts in timeseries) if timeseries else None | ||
| elif aggregation_function == AggregationFunction.MIN: | ||
| return min(ts.value for ts in timeseries) if timeseries else None | ||
| else: | ||
| raise ValueError(f"Invalid aggregation function: {aggregation_function}") |
There was a problem hiding this comment.
| def aggregate_timeseries( | |
| timeseries: List[TimeStampedValue], | |
| aggregation_function: AggregationFunction, | |
| last_window_s: float = 1.0, | |
| ) -> Optional[float]: | |
| """Aggregate the values in a timeseries using a specified function.""" | |
| if aggregation_function == AggregationFunction.MEAN: | |
| return time_weighted_average(timeseries, last_window_s=last_window_s) | |
| elif aggregation_function == AggregationFunction.MAX: | |
| return max(ts.value for ts in timeseries) if timeseries else None | |
| elif aggregation_function == AggregationFunction.MIN: | |
| return min(ts.value for ts in timeseries) if timeseries else None | |
| else: | |
| raise ValueError(f"Invalid aggregation function: {aggregation_function}") | |
| def aggregate_timeseries( | |
| timeseries: List[TimeStampedValue], | |
| aggregation_function: AggregationFunction, | |
| last_window_s: float = 1.0, | |
| ) -> Optional[float]: | |
| """Aggregate the values in a timeseries using a specified function.""" | |
| if not timeseries: | |
| return None | |
| if aggregation_function == AggregationFunction.MEAN: | |
| return time_weighted_average(timeseries, last_window_s=last_window_s) | |
| elif aggregation_function == AggregationFunction.MAX: | |
| # maybe cleaner to refactor to windowed min/max function, the same way _get_datapoints is doing it | |
| window_start = datetime.now() - last_window_s | |
| return max(ts.value for ts in timeseries if ts.timestamp > window_start ) | |
| elif aggregation_function == AggregationFunction.MIN: | |
| window_start = datetime.now() - last_window_s | |
| return min(ts.value for ts in timeseries if ts.timestamp > window_start ) | |
| else: | |
| raise ValueError(f"Invalid aggregation function: {aggregation_function}") |
There was a problem hiding this comment.
i dont understand this suggestion can you elaborate what this does
window_start = datetime.now() - last_window_s
return max(ts.value for ts in timeseries if ts.timestamp > window_start )
landscapepainter
left a comment
There was a problem hiding this comment.
LGTM! By the way, do we need to add any tests that check how the autoscaling behavior changes based on used aggregation_function value? I assume the number of scaled replicas can change based on aggregation_function either being min, max, or mean.
| def aggregate_timeseries( | ||
| timeseries: List[TimeStampedValue], | ||
| aggregation_function: AggregationFunction, | ||
| last_window_s: float = 1.0, |
There was a problem hiding this comment.
Why do we set the default value of last_window_s to be 1.0? Was wondering the implication of it.
There was a problem hiding this comment.
in reality we are not depending on default value. The value basically decided how much to weight the last data point. 1 is safe default.
Signed-off-by: abrar <abrar@anyscale.com>
akyang-anyscale
left a comment
There was a problem hiding this comment.
Should we support percentiles too?
ok to leave it for the future? |
yeah that's fine |
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: Pavitra Bhalla <pavitra@rayai.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: Josh Kodi <joshkodi@gmail.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: xgui <xgui@anyscale.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
PR ray-project#56871 introduced the AggregationFunction enum for autoscaling metrics aggregation. However, the serve build command's YAML serialization path was not updated to handle Enum objects, causing RepresenterError when serializing AggregationFunction enum values in autoscaling config. This fix adds a helper function that recursively converts Enum objects to their string values before YAML dump, ensuring proper serialization of all enum types in the configuration. Fixes ray-project#58485 Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: Aydin Abiar <aydin@anyscale.com>
…on enum (#58509) PR #56871 introduced the AggregationFunction enum for autoscaling metrics aggregation. However, the serve build command's YAML serialization path was not updated to handle Enum objects, causing RepresenterError when serializing AggregationFunction enum values in autoscaling config. ex. `yaml.representer.RepresenterError: ('cannot represent an object', <AggregationFunction.MEAN: 'mean'>)` This fix adds 1. a helper function that recursively converts Enum objects to their string values before YAML dump, ensuring proper serialization of all enum types in the configuration. 2. a test that (a) Creates a temporary output YAML file (b) Reads the config from that file (c) Verifies that AggregationFunction.MEAN is correctly serialized as "mean" (string) Fixes #58485 --------- Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Nikhil G <nrghosh@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…on enum (ray-project#58509) PR ray-project#56871 introduced the AggregationFunction enum for autoscaling metrics aggregation. However, the serve build command's YAML serialization path was not updated to handle Enum objects, causing RepresenterError when serializing AggregationFunction enum values in autoscaling config. ex. `yaml.representer.RepresenterError: ('cannot represent an object', <AggregationFunction.MEAN: 'mean'>)` This fix adds 1. a helper function that recursively converts Enum objects to their string values before YAML dump, ensuring proper serialization of all enum types in the configuration. 2. a test that (a) Creates a temporary output YAML file (b) Reads the config from that file (c) Verifies that AggregationFunction.MEAN is correctly serialized as "mean" (string) Fixes ray-project#58485 --------- Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Nikhil G <nrghosh@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…on enum (ray-project#58509) PR ray-project#56871 introduced the AggregationFunction enum for autoscaling metrics aggregation. However, the serve build command's YAML serialization path was not updated to handle Enum objects, causing RepresenterError when serializing AggregationFunction enum values in autoscaling config. ex. `yaml.representer.RepresenterError: ('cannot represent an object', <AggregationFunction.MEAN: 'mean'>)` This fix adds 1. a helper function that recursively converts Enum objects to their string values before YAML dump, ensuring proper serialization of all enum types in the configuration. 2. a test that (a) Creates a temporary output YAML file (b) Reads the config from that file (c) Verifies that AggregationFunction.MEAN is correctly serialized as "mean" (string) Fixes ray-project#58485 --------- Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Nikhil G <nrghosh@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: YK <1811651+ykdojo@users.noreply.github.com>
…on enum (ray-project#58509) PR ray-project#56871 introduced the AggregationFunction enum for autoscaling metrics aggregation. However, the serve build command's YAML serialization path was not updated to handle Enum objects, causing RepresenterError when serializing AggregationFunction enum values in autoscaling config. ex. `yaml.representer.RepresenterError: ('cannot represent an object', <AggregationFunction.MEAN: 'mean'>)` This fix adds 1. a helper function that recursively converts Enum objects to their string values before YAML dump, ensuring proper serialization of all enum types in the configuration. 2. a test that (a) Creates a temporary output YAML file (b) Reads the config from that file (c) Verifies that AggregationFunction.MEAN is correctly serialized as "mean" (string) Fixes ray-project#58485 --------- Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Nikhil G <nrghosh@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Add support for min, max and time weighted average as aggregation function over timeseries data --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: Future-Outlier <eric901201@gmail.com>
…on enum (ray-project#58509) PR ray-project#56871 introduced the AggregationFunction enum for autoscaling metrics aggregation. However, the serve build command's YAML serialization path was not updated to handle Enum objects, causing RepresenterError when serializing AggregationFunction enum values in autoscaling config. ex. `yaml.representer.RepresenterError: ('cannot represent an object', <AggregationFunction.MEAN: 'mean'>)` This fix adds 1. a helper function that recursively converts Enum objects to their string values before YAML dump, ensuring proper serialization of all enum types in the configuration. 2. a test that (a) Creates a temporary output YAML file (b) Reads the config from that file (c) Verifies that AggregationFunction.MEAN is correctly serialized as "mean" (string) Fixes ray-project#58485 --------- Signed-off-by: Nikhil Ghosh <nikhil@anyscale.com> Signed-off-by: Nikhil G <nrghosh@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: peterxcli <peterxcli@gmail.com>
Add support for min, max and time weighted average as aggregation function over timeseries data