6
6
import threading
7
7
from collections import defaultdict
8
8
from string import Template
9
- from typing import Dict , List , Optional , Any
9
+ from typing import Optional , Any
10
10
import os
11
11
import math
12
12
import time
@@ -164,12 +164,12 @@ def instance_limit(self):
164
164
return self ._max_instances
165
165
166
166
@property
167
- def max_instances (self ):
167
+ def max_instances (self ) -> int :
168
168
# Adjust the max_instances based on the number that is already requested
169
169
# this keeps the scaler from running way ahead with its demands when resource caps are reached
170
170
return min (self ._max_instances , self .target_instances + 2 )
171
171
172
- def update (self , delta , instances , backlog , duty_cycle ):
172
+ def update (self , delta : float , instances : int , backlog : int , duty_cycle : float ):
173
173
self .last_update = time .time ()
174
174
self .running_instances = instances
175
175
self .queue_length = backlog
@@ -235,7 +235,7 @@ def __init__(self, config=None, datastore=None, redis=None, redis_persist=None):
235
235
236
236
self .scaler_timeout_queue = NamedQueue (SCALER_TIMEOUT_QUEUE , host = self .redis_persist )
237
237
self .error_count_lock = threading .Lock ()
238
- self .error_count : Dict [str , List [float ]] = {}
238
+ self .error_count : dict [str , list [float ]] = {}
239
239
self .status_table = ExpiringHash (SERVICE_STATE_HASH , host = self .redis , ttl = 30 * 60 )
240
240
self .service_change_watcher = EventWatcher (self .redis , deserializer = ServiceChange .deserialize )
241
241
self .service_change_watcher .register ('changes.services.*' , self ._handle_service_change_event )
@@ -274,7 +274,7 @@ def __init__(self, config=None, datastore=None, redis=None, redis_persist=None):
274
274
self .controller .global_mounts .append ((CLASSIFICATION_HOST_PATH , '/etc/assemblyline/classification.yml' ))
275
275
276
276
# Information about services
277
- self .profiles : Dict [str , ServiceProfile ] = {}
277
+ self .profiles : dict [str , ServiceProfile ] = {}
278
278
self .profiles_lock = threading .RLock ()
279
279
280
280
# Prepare a single threaded scheduler
@@ -364,7 +364,7 @@ def _sync_service(self, service: Service):
364
364
name = service .name
365
365
stage = self .get_service_stage (service .name )
366
366
default_settings = self .config .core .scaler .service_defaults
367
- image_variables = defaultdict (str )
367
+ image_variables : defaultdict [ str , str ] = defaultdict (str )
368
368
image_variables .update (self .config .services .image_variables )
369
369
370
370
def prepare_container (docker_config : DockerConfig ) -> DockerConfig :
@@ -473,7 +473,7 @@ def update_scaling(self):
473
473
# Figure out what services are expected to be running and how many
474
474
with elasticapm .capture_span ('read_profiles' ):
475
475
with self .profiles_lock :
476
- all_profiles : Dict [str , ServiceProfile ] = copy .deepcopy (self .profiles )
476
+ all_profiles : dict [str , ServiceProfile ] = copy .deepcopy (self .profiles )
477
477
raw_targets = self .controller .get_targets ()
478
478
targets = {_p .name : raw_targets .get (_p .name , 0 ) for _p in all_profiles .values ()}
479
479
@@ -516,7 +516,7 @@ def update_scaling(self):
516
516
free_memory = self .controller .free_memory ()
517
517
518
518
#
519
- def trim (prof : List [ServiceProfile ]):
519
+ def trim (prof : list [ServiceProfile ]):
520
520
prof = [_p for _p in prof if _p .desired_instances > targets [_p .name ]]
521
521
drop = [_p for _p in prof if _p .cpu > free_cpu or _p .ram > free_memory ]
522
522
if drop :
@@ -525,7 +525,7 @@ def trim(prof: List[ServiceProfile]):
525
525
prof = [_p for _p in prof if _p .cpu <= free_cpu and _p .ram <= free_memory ]
526
526
return prof
527
527
528
- remaining_profiles : List [ServiceProfile ] = trim (list (all_profiles .values ()))
528
+ remaining_profiles : list [ServiceProfile ] = trim (list (all_profiles .values ()))
529
529
# The target values up until now should be in sync with the container orchestrator
530
530
# create a copy, so we can track which ones change in the following loop
531
531
old_targets = dict (targets )
@@ -553,7 +553,7 @@ def trim(prof: List[ServiceProfile]):
553
553
pool .call (self .controller .set_target , name , value )
554
554
555
555
@elasticapm .capture_span (span_type = APM_SPAN_TYPE )
556
- def handle_service_error (self , service_name ):
556
+ def handle_service_error (self , service_name : str ):
557
557
"""Handle an error occurring in the *analysis* service.
558
558
559
559
Errors for core systems should simply be logged, and a best effort to continue made.
0 commit comments