From 8da9ec593e9cdc43c41a796370648e3371a9612b Mon Sep 17 00:00:00 2001 From: Klaas van Schelven Date: Sat, 15 Nov 2025 14:51:27 +0100 Subject: [PATCH] send_json/stress_test utilities: prettier tag-sending --- bsmain/management/commands/send_json.py | 4 +++ bsmain/management/commands/stress_test.py | 13 +------ bsmain/management/utils.py | 43 +++++++++++++++++++++++ 3 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 bsmain/management/utils.py diff --git a/bsmain/management/commands/send_json.py b/bsmain/management/commands/send_json.py index ad0e705..6d30b92 100644 --- a/bsmain/management/commands/send_json.py +++ b/bsmain/management/commands/send_json.py @@ -15,6 +15,8 @@ from compat.dsn import get_store_url, get_envelope_url, get_header_value from bugsink.streams import compress_with_zlib, WBITS_PARAM_FOR_GZIP, WBITS_PARAM_FOR_DEFLATE from bugsink.utils import nc_rnd +from ..utils import random_for_RANDOM + class Command(BaseCommand): help = "Send raw events to a sentry-compatible server; events can be sources from the filesystem or your DB." @@ -125,6 +127,8 @@ class Command(BaseCommand): for tag in options["tag"]: tag = tag[0] # it's a list of lists... how to prevent this is not immediately clear k, v = tag.split(":", 1) + + v = random_for_RANDOM(k, v) data["tags"][k] = v if options["valid_only"] and not self.is_valid(data, identifier): diff --git a/bsmain/management/commands/stress_test.py b/bsmain/management/commands/stress_test.py index db792a5..d1cad7b 100644 --- a/bsmain/management/commands/stress_test.py +++ b/bsmain/management/commands/stress_test.py @@ -15,18 +15,7 @@ from bugsink.streams import compress_with_zlib, WBITS_PARAM_FOR_GZIP, WBITS_PARA from bugsink.utils import nc_rnd from issues.utils import get_values - -def random_postfix(): - # avoids numbers, because when usedd in the type I imagine numbers may at some point be ignored in the grouping. - random_number = nc_rnd.random() - - if random_number < 0.1: - # 10% of the time we simply sample from 1M to create a "fat tail". - unevenly_distributed_number = int(nc_rnd.random() * 1_000_000) - else: - unevenly_distributed_number = int(1 / random_number) - - return "".join([chr(ord("A") + int(c)) for c in str(unevenly_distributed_number)]) +from ..utils import random_postfix class Command(BaseCommand): diff --git a/bsmain/management/utils.py b/bsmain/management/utils.py new file mode 100644 index 0000000..eb7c1d7 --- /dev/null +++ b/bsmain/management/utils.py @@ -0,0 +1,43 @@ +from bugsink.utils import nc_rnd + + +PRETTY_RANDOM_TAGS = { + "os": ["Windows", "Linux", "MacOS", "Android", "iOS"], + "os.version": ["10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"], + "cpu": ["x86", "x64", "ARM", "ARM64", "MIPS"], + "browser": ["Chrome", "Firefox", "Safari", "Edge", "Opera"], + "device": ["Desktop", "Laptop", "Tablet", "Smartphone"], + "environment": ["production", "staging", "development", "testing"], + "release": ["1.0.0", "1.1.0", "1.2.0", "2.0.0", "2.1.0"], + "feature_flag": ["new-ui", "beta-feature", "dark-mode", "performance-improvements"], +} + + +def random_postfix(): + # avoids numbers, because when used in the type I imagine numbers may at some point be ignored in the grouping. + random_number = nc_rnd.random() + + if random_number < 0.1: + # 10% of the time we simply sample from 1M to create a "fat tail". + unevenly_distributed_number = int(nc_rnd.random() * 1_000_000) + else: + unevenly_distributed_number = int(1 / random_number) + + return "".join([chr(ord("A") + int(c)) for c in str(unevenly_distributed_number)]) + + +def random_for_RANDOM(k, v): + if v != "RANDOM": + return v + + if k in PRETTY_RANDOM_TAGS: + options = PRETTY_RANDOM_TAGS[k] + random_number = nc_rnd.random() + unevenly_distributed_number = int(1 / random_number) + + if unevenly_distributed_number > len(options) - 1: + return options[0] + + return options[unevenly_distributed_number] + + return "value-" + random_postfix()