locust-cloud 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
locust_cloud/__init__.py CHANGED
@@ -1,10 +1,11 @@
1
- from locust_cloud.auth import register_auth
2
- from locust_cloud.timescale.exporter import Timescale
3
-
4
1
  import os
5
2
 
3
+ os.environ["LOCUST_SKIP_MONKEY_PATCH"] = "1"
4
+
6
5
  from locust import events
7
6
  from locust.argument_parser import LocustArgumentParser
7
+ from locust_cloud.auth import register_auth
8
+ from locust_cloud.timescale.exporter import Timescale
8
9
 
9
10
  PG_USER = os.environ.get("PG_USER")
10
11
  PG_HOST = os.environ.get("PG_HOST")
@@ -15,11 +16,18 @@ PG_PORT = os.environ.get("PG_PORT", 5432)
15
16
 
16
17
  @events.init_command_line_parser.add_listener
17
18
  def add_arguments(parser: LocustArgumentParser):
19
+ if not PG_HOST:
20
+ parser.add_argument_group(
21
+ "locust-cloud",
22
+ "locust-cloud disabled, because PG_HOST was not set - this is normal for local runs",
23
+ )
24
+ return
25
+
26
+ os.environ["LOCUST_BUILD_PATH"] = os.path.join(os.path.dirname(__file__), "webui/dist")
18
27
  locust_cloud = parser.add_argument_group(
19
28
  "locust-cloud",
20
- "Arguments for use with Locust cloud!",
29
+ "Arguments for use with Locust cloud",
21
30
  )
22
-
23
31
  locust_cloud.add_argument(
24
32
  "--exporter",
25
33
  default=True,
@@ -38,7 +46,8 @@ def add_arguments(parser: LocustArgumentParser):
38
46
 
39
47
  @events.init.add_listener
40
48
  def on_locust_init(environment, **args):
41
- os.environ["LOCUST_BUILD_PATH"] = os.path.join(os.path.dirname(__file__), "webui/dist")
49
+ if not PG_HOST:
50
+ return
42
51
 
43
52
  if environment.parsed_options.exporter:
44
53
  Timescale(
locust_cloud/auth.py CHANGED
@@ -1,5 +1,5 @@
1
- import datetime
2
1
  import os
2
+ from datetime import UTC, datetime, timedelta
3
3
 
4
4
  import requests
5
5
  from flask import redirect, request, url_for
@@ -21,9 +21,9 @@ def set_credentials(credentials, response):
21
21
  user_sub_id = credentials["user_sub_id"]
22
22
  refresh_token = credentials["refresh_token"]
23
23
 
24
- response.set_cookie("cognito_token", id_token, expires=datetime.datetime.utcnow() + datetime.timedelta(days=1))
25
- response.set_cookie("user_token", refresh_token, expires=datetime.datetime.utcnow() + datetime.timedelta(days=365))
26
- response.set_cookie("user_sub_id", user_sub_id, expires=datetime.datetime.utcnow() + datetime.timedelta(days=365))
24
+ response.set_cookie("cognito_token", id_token, expires=datetime.now(tz=UTC) + timedelta(days=1))
25
+ response.set_cookie("user_token", refresh_token, expires=datetime.now(tz=UTC) + timedelta(days=365))
26
+ response.set_cookie("user_sub_id", user_sub_id, expires=datetime.now(tz=UTC) + timedelta(days=365))
27
27
 
28
28
  return response
29
29
 
locust_cloud/cloud.py CHANGED
@@ -15,6 +15,7 @@ from botocore.exceptions import ClientError
15
15
  LAMBDA = "https://deployer.locust.cloud/1"
16
16
  DEFAULT_CLUSTER_NAME = "locust"
17
17
  DEFAULT_REGION_NAME = "eu-north-1"
18
+ LOCUST_ENV_VARIABLE_IGNORE_LIST = ["LOCUST_BUILD_PATH", "LOCUST_SKIP_MONKEY_PATCH"]
18
19
 
19
20
 
20
21
  class LocustTomlConfigParser(configargparse.TomlConfigParser):
@@ -275,7 +276,7 @@ def deploy(
275
276
  locust_env_variables = [
276
277
  {"name": env_variable, "value": str(os.environ[env_variable])}
277
278
  for env_variable in os.environ
278
- if env_variable.startswith("LOCUST_")
279
+ if env_variable.startswith("LOCUST_") and env_variable not in LOCUST_ENV_VARIABLE_IGNORE_LIST
279
280
  ]
280
281
 
281
282
  response = requests.post(