From 356a06a3d411fbd0625641ac6810bf5802f601f7 Mon Sep 17 00:00:00 2001 From: Joshua Fox Date: Sun, 30 Apr 2023 17:32:25 +0300 Subject: [PATCH] more instnaces --- app.yaml | 4 ++-- cron.yaml | 2 +- main.py | 11 ++++------- plugin.py | 2 +- util/gcp_utils.py | 6 ++---- util/utils.py | 6 ++++++ 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app.yaml b/app.yaml index c22522fcf..1855051a1 100644 --- a/app.yaml +++ b/app.yaml @@ -1,8 +1,8 @@ runtime: python39 service: iris3 automatic_scaling: - max_instances: 3 - max_concurrent_requests: 3 + max_instances: 6 + max_concurrent_requests: 5 instance_class: F2 inbound_services: - warmup diff --git a/cron.yaml b/cron.yaml index 0c3b79512..b610cf7a7 100644 --- a/cron.yaml +++ b/cron.yaml @@ -2,5 +2,5 @@ cron: - description: "Invoke /schedule which sends out messages triggering do_label per project/plugin." url: /schedule - schedule: every day 13:27 + schedule: every day 10:00 target: iris3 diff --git a/main.py b/main.py index 63935ee77..653d16e8b 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ app.wsgi_app = google.appengine.api.wrap_wsgi_app(app.wsgi_app) -from util.utils import init_logging +from util.utils import init_logging, sort_dict # Must init logging before any library code writes logs (which would then just override our config) init_logging() @@ -66,10 +66,7 @@ gcp_utils.set_env() -logging.info( - "env GAE_USE_SOCKETS_HTTPLIB is %s", os.environ.get("GAE_USE_SOCKETS_HTTPLIB") -) -logging.info("env PYTHONMALLOC is %s", os.environ.get("PYTHONMALLOC")) +logging.info("env is %s", sort_dict( (os.environ.copy()))) PluginHolder.init() @@ -254,10 +251,10 @@ def __label_one_0(data, plugin_cls: Type[Plugin]): plugin = PluginHolder.get_plugin_instance(plugin_cls) gcp_object = plugin.get_gcp_object(data) if gcp_object is not None: - project_id = data["resource"]["labels"]["project_id"] + project_id = data["labels"]["project_id"] if is_project_enabled(project_id): logging.info( - "Will label_one() in %s, existing object %s...", + "Will label_one() in %s, existing object %s ", project_id, str(gcp_object)[:100], ) diff --git a/plugin.py b/plugin.py index 4e012c044..35e7828ef 100644 --- a/plugin.py +++ b/plugin.py @@ -237,7 +237,7 @@ def load_plugin_class(name) -> Type: ] = None # Initialize with NO instance to avoid importing loaded.append(plugin_class.__name__) - logging.info("Loaded plugins: %s", loaded) + assert cls.plugins, "No plugins defined" @classmethod diff --git a/util/gcp_utils.py b/util/gcp_utils.py index 0bf277816..2f37eb4d4 100644 --- a/util/gcp_utils.py +++ b/util/gcp_utils.py @@ -12,7 +12,7 @@ from util import localdev_config, utils from util.detect_gae import detect_gae -from util.utils import timed_lru_cache, log_time, dict_to_camelcase +from util.utils import timed_lru_cache, log_time, dict_to_camelcase, sort_dict __invocation_count = Counter() @@ -26,9 +26,7 @@ def increment_invocation_count(path: str): def count_invocations_by_path(): d = dict(__invocation_count) - keys = sorted(list(d.keys())) - sorted_dict = {i: d[i] for i in keys} - return sorted_dict + return sort_dict(d) def current_project_id(): diff --git a/util/utils.py b/util/utils.py index 243202f12..d44cd7226 100644 --- a/util/utils.py +++ b/util/utils.py @@ -256,3 +256,9 @@ def run_command(command_s): def mkdirs(dir_): pathlib.Path(dir_).mkdir(parents=True, exist_ok=True) + + +def sort_dict(d): + keys = sorted(list(d.keys())) + sorted_dict = {i: d[i] for i in keys} + return sorted_dict \ No newline at end of file