Skip to content

Commit

Permalink
fix: flakey test for EndpointTraceItemAttributeNames (#6523)
Browse files Browse the repository at this point in the history
The bug:

I was querying for the attributes and they look something like this
```
a_tag_1
a_tag_2
...
a_tag_30
http.status
sentry.environment
...
```
The `a_tag` attributes I created and know where they're coming from. The
others like `http.status` idk where they come from, and it turns out
that they will be different on the local machine and in CI. I hard coded
them to what they are on my local machine but they were different in CI
sometimes which caused the tests to fail.

The way previous tests handled this was only validating the first 10
```
a_tag_1
...
a_tag_10
```
so they never encountered the changing attributes like `http.status`.
But I didnt like this too much since its ignoring a lot of the other
results (like 11 through 30).

I decided to solve the bug by validating only all the `a_tag` and
allowing any arbitrary extra attributes
```
a_tag_1
...
a_tag_30
```
(so now `http.status` can be there, or not it doesnt matter)
  • Loading branch information
kylemumma authored Nov 6, 2024
1 parent cbf05a3 commit 103a6d9
Showing 1 changed file with 11 additions and 54 deletions.
65 changes: 11 additions & 54 deletions tests/web/rpc/v1/test_endpoint_trace_item_attribute_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_basic(self) -> None:
seconds=int((BASE_TIME + timedelta(days=1)).timestamp())
),
),
limit=1000,
limit=TOTAL_GENERATED_ATTR_PER_TYPE,
type=AttributeKey.Type.TYPE_STRING,
value_substring_match="",
)
Expand All @@ -113,23 +113,6 @@ def test_basic(self) -> None:
name=f"a_tag_{str(i).zfill(3)}", type=AttributeKey.Type.TYPE_STRING
)
)
expected += [
TraceItemAttributeNamesResponse.Attribute(
name="http.status_code", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.category", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.name", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.segment_name", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.service", type=AttributeKey.Type.TYPE_STRING
),
]
assert res.attributes == expected

def test_simple_float(self) -> None:
Expand All @@ -146,7 +129,7 @@ def test_simple_float(self) -> None:
seconds=int((BASE_TIME + timedelta(days=1)).timestamp())
),
),
limit=1000,
limit=TOTAL_GENERATED_ATTR_PER_TYPE,
type=AttributeKey.Type.TYPE_FLOAT,
value_substring_match="",
)
Expand All @@ -159,11 +142,6 @@ def test_simple_float(self) -> None:
type=AttributeKey.Type.TYPE_FLOAT,
)
)
expected.append(
TraceItemAttributeNamesResponse.Attribute(
name="sentry.duration_ms", type=AttributeKey.Type.TYPE_FLOAT
)
)
assert res.attributes == expected

def test_with_filter(self) -> None:
Expand All @@ -180,7 +158,7 @@ def test_with_filter(self) -> None:
seconds=int((BASE_TIME + timedelta(days=1)).timestamp())
),
),
limit=1000,
limit=TOTAL_GENERATED_ATTR_PER_TYPE,
type=AttributeKey.Type.TYPE_STRING,
value_substring_match="28",
)
Expand All @@ -203,28 +181,11 @@ def test_with_page_token(self) -> None:
type=AttributeKey.Type.TYPE_STRING,
)
)
expected_attributes += [
TraceItemAttributeNamesResponse.Attribute(
name="http.status_code", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.category", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.name", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.segment_name", type=AttributeKey.Type.TYPE_STRING
),
TraceItemAttributeNamesResponse.Attribute(
name="sentry.service", type=AttributeKey.Type.TYPE_STRING
),
]
# we just get the first 10
limit = 10
# grab 10 at a time until we get them all
done = 0
page_token = None
while True:
# and grab `limit` at a time until we get them all
at_a_time = 10
while done < TOTAL_GENERATED_ATTR_PER_TYPE:
req = TraceItemAttributeNamesRequest(
meta=RequestMeta(
project_ids=[1, 2, 3],
Expand All @@ -238,20 +199,16 @@ def test_with_page_token(self) -> None:
seconds=int((BASE_TIME + timedelta(days=1)).timestamp())
),
),
limit=limit,
limit=at_a_time,
type=AttributeKey.Type.TYPE_STRING,
value_substring_match="",
page_token=page_token,
)
res = EndpointTraceItemAttributeNames().execute(req)
page_token = res.page_token
reslen = len(res.attributes)
if reslen == 0:
# we are done, we got everything
break
else:
assert res.attributes == expected_attributes[:reslen]
expected_attributes = expected_attributes[reslen:]
assert res.attributes == expected_attributes[:at_a_time]
expected_attributes = expected_attributes[at_a_time:]
done += at_a_time
assert expected_attributes == []

def test_page_token_offset_filter(self) -> None:
Expand Down

0 comments on commit 103a6d9

Please sign in to comment.