send_json/stress_test utilities: prettier tag-sending

This commit is contained in:
Klaas van Schelven
2025-11-15 14:51:27 +01:00
parent 1829465342
commit 8da9ec593e
3 changed files with 48 additions and 12 deletions

View File

@@ -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):

View File

@@ -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):

View File

@@ -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()