Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 658298a

Browse files
authored
Merge pull request #158 from Yelp/m6id-c6id
Update for using m6id and c6id instance type families
2 parents 9119dc4 + a4c722e commit 658298a

File tree

106 files changed

+2285
-721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+2285
-721
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ repos:
4444
- id: pyupgrade
4545
args: [--py3-plus]
4646
language_version: python3.6
47-
- repo: http://github.com/psf/black
48-
rev: 19.10b0
47+
- repo: https://github.com/psf/black
48+
rev: 22.3.0
4949
hooks:
5050
- id: black
5151
language_version: python3.7

acceptance/run_instance.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
vpc_response = ec2.create_vpc(CidrBlock=cidr_block)
3434
subnet_response = ec2.create_subnet(
35-
CidrBlock=cidr_block, VpcId=vpc_response["Vpc"]["VpcId"], AvailabilityZone="us-west-2a",
35+
CidrBlock=cidr_block,
36+
VpcId=vpc_response["Vpc"]["VpcId"],
37+
AvailabilityZone="us-west-2a",
3638
)
3739
subnet_id = subnet_response["Subnet"]["SubnetId"]
3840
with open("{root}/autoscaler_config.tmpl".format(root=root)) as config_template:
@@ -57,7 +59,17 @@
5759
"EbsOptimized": False,
5860
# note that this is not useful until we solve
5961
# https://github.com/spulec/moto/issues/1644
60-
"TagSpecifications": [{"ResourceType": "instance", "Tags": [{"Key": "foo", "Value": "bar",}],}],
62+
"TagSpecifications": [
63+
{
64+
"ResourceType": "instance",
65+
"Tags": [
66+
{
67+
"Key": "foo",
68+
"Value": "bar",
69+
}
70+
],
71+
}
72+
],
6173
},
6274
],
6375
"IamFleetRole": "foo",
@@ -73,15 +85,22 @@
7385
Body=json.dumps(
7486
{
7587
"cluster_autoscaling_resources": {
76-
"aws_spot_fleet_request.local-dev": {"id": sfr_response["SpotFleetRequestId"], "pool": "default",}
88+
"aws_spot_fleet_request.local-dev": {
89+
"id": sfr_response["SpotFleetRequestId"],
90+
"pool": "default",
91+
}
7792
}
7893
}
7994
).encode(),
8095
)
8196

8297
s3.create_bucket(Bucket="clusterman-signals")
8398
with open(
84-
"{root}/{env}/clusterman_signals_acceptance.tar.gz".format(root=root, env=os.environ["DISTRIB_CODENAME"],), "rb",
99+
"{root}/{env}/clusterman_signals_acceptance.tar.gz".format(
100+
root=root,
101+
env=os.environ["DISTRIB_CODENAME"],
102+
),
103+
"rb",
85104
) as f:
86105
s3.put_object(
87106
Bucket="clusterman-signals",
@@ -92,7 +111,10 @@
92111
try:
93112
dynamodb.create_table(
94113
TableName="clusterman_cluster_state",
95-
KeySchema=[{"AttributeName": "state", "KeyType": "HASH"}, {"AttributeName": "entity", "KeyType": "SORT"},],
114+
KeySchema=[
115+
{"AttributeName": "state", "KeyType": "HASH"},
116+
{"AttributeName": "entity", "KeyType": "SORT"},
117+
],
96118
AttributeDefinitions=[
97119
{"AttributeName": "state", "AttributeType": "S"},
98120
{"AttributeName": "entity", "AttributeType": "S"},

clusterman/args.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def subparser(command, help, entrypoint): # pragma: no cover
26-
""" Function decorator to simplify adding arguments to subcommands
26+
"""Function decorator to simplify adding arguments to subcommands
2727
2828
:param command: name of the subcommand to add
2929
:param help: help string for the subcommand
@@ -68,7 +68,7 @@ def add_branch_or_tag_arg(parser): # pragma: no cover
6868

6969

7070
def add_start_end_args(parser, start_help, end_help): # pragma: no cover
71-
""" Add --start-time and --end-time args to a parser
71+
"""Add --start-time and --end-time args to a parser
7272
7373
:param start_help: help string for --start-time
7474
:param end_help: help string for --end-time
@@ -88,21 +88,25 @@ def add_start_end_args(parser, start_help, end_help): # pragma: no cover
8888

8989

9090
def add_region_arg(parser, required=False): # pragma: no cover
91-
""" Add an --aws-region argument to a parser """
91+
"""Add an --aws-region argument to a parser"""
9292
parser.add_argument(
93-
"--aws-region", required=required, help="AWS region to operate in",
93+
"--aws-region",
94+
required=required,
95+
help="AWS region to operate in",
9496
)
9597

9698

9799
def add_cluster_arg(parser, required=False): # pragma: no cover
98-
""" Add --cluster argument to a parser """
100+
"""Add --cluster argument to a parser"""
99101
parser.add_argument(
100-
"--cluster", default=os.environ.get("CMAN_CLUSTER", None), help="Name of Mesos cluster to operate on",
102+
"--cluster",
103+
default=os.environ.get("CMAN_CLUSTER", None),
104+
help="Name of Mesos cluster to operate on",
101105
)
102106

103107

104108
def add_pool_arg(parser): # pragma: no cover
105-
""" Add --pool argument to a parser """
109+
"""Add --pool argument to a parser"""
106110
parser.add_argument(
107111
"--pool",
108112
"--role",
@@ -114,7 +118,7 @@ def add_pool_arg(parser): # pragma: no cover
114118

115119

116120
def add_scheduler_arg(parser): # pragma: no cover
117-
""" Add --scheduler argument to a parser """
121+
"""Add --scheduler argument to a parser"""
118122
parser.add_argument(
119123
"--scheduler",
120124
default=os.environ.get("CMAN_SCHEDULER", "mesos"),
@@ -124,28 +128,36 @@ def add_scheduler_arg(parser): # pragma: no cover
124128

125129

126130
def add_env_config_path_arg(parser): # pragma: no cover
127-
""" Add a --env-config-path argument to a parser """
131+
"""Add a --env-config-path argument to a parser"""
128132
parser.add_argument(
129-
"--env-config-path", default="/nail/srv/configs/clusterman.yaml", help="Path to clusterman configuration file",
133+
"--env-config-path",
134+
default="/nail/srv/configs/clusterman.yaml",
135+
help="Path to clusterman configuration file",
130136
)
131137

132138

133139
def add_cluster_config_directory_arg(parser): # pragma: no cover
134140
parser.add_argument(
135-
"--cluster-config-directory", metavar="directory", help="specify role configuration directory for simulation",
141+
"--cluster-config-directory",
142+
metavar="directory",
143+
help="specify role configuration directory for simulation",
136144
)
137145

138146

139147
def add_disable_sensu_arg(parser): # pragma: no cover
140-
""" Add a --disable-sensu argument to a parser """
148+
"""Add a --disable-sensu argument to a parser"""
141149
parser.add_argument(
142-
"--disable-sensu", action="store_true", help="Disable sensu checkins",
150+
"--disable-sensu",
151+
action="store_true",
152+
help="Disable sensu checkins",
143153
)
144154

145155

146156
def add_json_arg(parser): # pragma: no cover
147157
parser.add_argument(
148-
"--json", action="store_true", help="Return information in JSON format",
158+
"--json",
159+
action="store_true",
160+
help="Return information in JSON format",
149161
)
150162

151163

@@ -189,7 +201,9 @@ def get_parser(description=""): # pragma: no cover
189201
root_parser = argparse.ArgumentParser(prog="clusterman", description=description, formatter_class=help_formatter)
190202
add_env_config_path_arg(root_parser)
191203
root_parser.add_argument(
192-
"--log-level", default="warning", choices=["debug", "info", "warning", "error", "critical"],
204+
"--log-level",
205+
default="warning",
206+
choices=["debug", "info", "warning", "error", "critical"],
193207
)
194208
root_parser.add_argument("-v", "--version", action="version", version="clusterman " + __version__)
195209

clusterman/autoscaler/autoscaler.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(
6060
metrics_client: Optional[ClustermanMetricsBotoClient] = None,
6161
monitoring_enabled: bool = True,
6262
) -> None:
63-
""" Class containing the core logic for autoscaling a cluster
63+
"""Class containing the core logic for autoscaling a cluster
6464
6565
:param cluster: the name of the cluster to autoscale
6666
:param pool: the name of the pool to autoscale
@@ -87,7 +87,8 @@ def __init__(
8787
self.resource_request_gauges: Dict[str, Any] = {}
8888
for resource in SignalResourceRequest._fields:
8989
self.resource_request_gauges[resource] = monitoring_client.create_gauge(
90-
RESOURCE_GAUGE_BASE_NAME.format(resource=resource), gauge_dimensions,
90+
RESOURCE_GAUGE_BASE_NAME.format(resource=resource),
91+
gauge_dimensions,
9192
)
9293

9394
self.autoscaling_config = get_autoscaling_config(
@@ -128,7 +129,7 @@ def run_frequency(self) -> int:
128129
return self.signal.period_minutes * 60
129130

130131
def run(self, dry_run: bool = False, timestamp: Optional[arrow.Arrow] = None) -> None:
131-
""" Do a single check to scale the fleet up or down if necessary.
132+
"""Do a single check to scale the fleet up or down if necessary.
132133
133134
:param dry_run: boolean; if True, don't modify the pool size, just print what would happen
134135
:param timestamp: an arrow object indicating the current time
@@ -161,7 +162,8 @@ def run(self, dry_run: bool = False, timestamp: Optional[arrow.Arrow] = None) ->
161162
logger.warning(
162163
"Nodes lost since last autoscaler run is {}"
163164
" which is greater than the threshold ({}),".format(
164-
str(num_removed_nodes_before_last_reload), str(self.autoscaling_config.instance_loss_threshold),
165+
str(num_removed_nodes_before_last_reload),
166+
str(self.autoscaling_config.instance_loss_threshold),
165167
)
166168
)
167169
logger.warning("Autoscaler will not kill any nodes on this run.")
@@ -226,7 +228,9 @@ def _get_signal_for_app(self, app: str) -> Signal:
226228
pool_namespace,
227229
self.metrics_client,
228230
signal_namespace=staticconf.read_string(
229-
"autoscale_signal.namespace", default=app, namespace=pool_namespace,
231+
"autoscale_signal.namespace",
232+
default=app,
233+
namespace=pool_namespace,
230234
),
231235
)
232236
except NoSignalConfiguredException:
@@ -250,7 +254,7 @@ def _get_signal_for_app(self, app: str) -> Signal:
250254
return self.default_signal
251255

252256
def _compute_target_capacity(self, resource_request: SignalResourceRequest) -> float:
253-
""" Compare signal to the resources allocated and compute appropriate capacity change.
257+
"""Compare signal to the resources allocated and compute appropriate capacity change.
254258
255259
:param resource_request: a resource_request object from the signal evaluation
256260
:returns: the new target capacity we should scale to
@@ -320,7 +324,8 @@ def _compute_target_capacity(self, resource_request: SignalResourceRequest) -> f
320324

321325
# If we get here, everything is non-zero and we can use the "normal" logic to determine scaling
322326
(most_constrained_resource, usage_pct,) = self._get_most_constrained_resource_for_request(
323-
resource_request, cluster_total_resources,
327+
resource_request,
328+
cluster_total_resources,
324329
)
325330
logger.info(
326331
f"Fulfilling resource request will cause {most_constrained_resource} to be the most constrained resource "
@@ -371,7 +376,9 @@ def _compute_target_capacity(self, resource_request: SignalResourceRequest) -> f
371376
return new_target_capacity
372377

373378
def _get_most_constrained_resource_for_request(
374-
self, resource_request: SignalResourceRequest, cluster_total_resources: ClustermanResources,
379+
self,
380+
resource_request: SignalResourceRequest,
381+
cluster_total_resources: ClustermanResources,
375382
) -> Tuple[str, float]:
376383
"""Determine what would be the most constrained resource if were to fulfill a resource_request without scaling
377384
the cluster.
@@ -403,7 +410,7 @@ def _get_most_constrained_resource_for_request(
403410
return max(requested_resource_usage_pcts.items(), key=lambda x: x[1])
404411

405412
def _get_historical_weighted_resource_value(self) -> ClustermanResources:
406-
""" Compute the weighted value of each type of resource in the cluster
413+
"""Compute the weighted value of each type of resource in the cluster
407414
408415
returns: a ClustermanResources object with the weighted resource value, or 0 if it couldn't be determined
409416
"""
@@ -419,7 +426,9 @@ def _get_historical_weighted_resource_value(self) -> ClustermanResources:
419426
weighted_resource_dict: MutableMapping[str, float] = {}
420427
for resource in ClustermanResources._fields:
421428
resource_history = self._get_smoothed_non_zero_metadata(
422-
f"{resource}_total", time_start=time_start, time_end=time_end,
429+
f"{resource}_total",
430+
time_start=time_start,
431+
time_end=time_end,
423432
)
424433
if not resource_history:
425434
weighted_resource_dict[resource] = 0
@@ -429,9 +438,13 @@ def _get_historical_weighted_resource_value(self) -> ClustermanResources:
429438
return ClustermanResources(**weighted_resource_dict)
430439

431440
def _get_smoothed_non_zero_metadata(
432-
self, metric_name: str, time_start: arrow.Arrow, time_end: arrow.Arrow, smoothing: int = 5,
441+
self,
442+
metric_name: str,
443+
time_start: arrow.Arrow,
444+
time_end: arrow.Arrow,
445+
smoothing: int = 5,
433446
) -> Optional[Tuple[int, int, float]]:
434-
""" Compute some smoothed-out historical metrics metadata
447+
"""Compute some smoothed-out historical metrics metadata
435448
436449
:param metric_name: the metadata metric to query
437450
:param time_start: the beginning of the historical time window to query

clusterman/autoscaler/config.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AutoscalingConfig(NamedTuple):
3131

3232

3333
def get_autoscaling_config(config_namespace: str) -> AutoscalingConfig:
34-
""" Load autoscaling configuration values from the provided config_namespace, falling back to the
34+
"""Load autoscaling configuration values from the provided config_namespace, falling back to the
3535
values stored in the default namespace if none are specified.
3636
3737
:param config_namespace: namespace to read from before falling back to the default namespace
@@ -46,7 +46,8 @@ def get_autoscaling_config(config_namespace: str) -> AutoscalingConfig:
4646
excluded_resources=reader.read_list("autoscaling.excluded_resources", default=default_excluded_resources),
4747
setpoint=reader.read_float("autoscaling.setpoint", default=default_setpoint),
4848
target_capacity_margin=reader.read_float(
49-
"autoscaling.target_capacity_margin", default=default_target_capacity_margin,
49+
"autoscaling.target_capacity_margin",
50+
default=default_target_capacity_margin,
5051
),
5152
prevent_scale_down_after_capacity_loss=reader.read_bool(
5253
"autoscaling.prevent_scale_down_after_capacity_loss", default=False

0 commit comments

Comments
 (0)