Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 RPC of TraceItemAttributeValues #6563

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft

V1 RPC of TraceItemAttributeValues #6563

wants to merge 2 commits into from

Conversation

xurui-c
Copy link
Member

@xurui-c xurui-c commented Nov 12, 2024

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

@xurui-c xurui-c force-pushed the rachel/v1RPC branch 7 times, most recently from 45d0159 to b972ec8 Compare November 12, 2024 18:59
Copy link

codecov bot commented Nov 12, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
1 1 0 0
View the top 1 failed tests by shortest run time
::tests.web.rpc.v1alpha.test_trace_item_attribute_values
Stack Traces | 0s run time
No failure message available

To view more test analytics, go to the Test Analytics Dashboard
Got feedback? Let us know on Github

@@ -108,6 +108,8 @@ def request_class(cls) -> Type[AttributeValuesRequestProto]:

def _execute(self, in_msg: AttributeValuesRequestProto) -> AttributeValuesResponse:
snuba_request = _build_snuba_request(in_msg)
print("snuba_request")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill remove these

Comment on lines +12 to +54
def truncate_request_meta_to_day(meta: RequestMeta) -> None:
# some tables store timestamp as toStartOfDay(x) in UTC, so if you request 4PM - 8PM on a specific day, nada
# this changes a request from 4PM - 8PM to a request from midnight today to 8PM tomorrow UTC.
# it also changes 11PM - 1AM to midnight today to 1AM overmorrow
start_timestamp = datetime.utcfromtimestamp(meta.start_timestamp.seconds)
end_timestamp = datetime.utcfromtimestamp(meta.end_timestamp.seconds)
start_timestamp = start_timestamp.replace(
hour=0, minute=0, second=0, microsecond=0
) - timedelta(days=1)
end_timestamp = end_timestamp.replace(
hour=0, minute=0, second=0, microsecond=0
) + timedelta(days=1)

meta.start_timestamp.seconds = int(start_timestamp.timestamp())
meta.end_timestamp.seconds = int(end_timestamp.timestamp())


def treeify_or_and_conditions(query: Query) -> None:
"""
look for expressions like or(a, b, c) and turn them into or(a, or(b, c))
and(a, b, c) and turn them into and(a, and(b, c))

even though clickhouse sql supports arbitrary amount of arguments there are other parts of the
codebase which assume `or` and `and` have two arguments

Adding this post-process step is easier than changing the rest of the query pipeline

Note: does not apply to the conditions of a from_clause subquery (the nested one)
this is bc transform_expressions is not implemented for composite queries
"""

def transform(exp: Expression) -> Expression:
if not isinstance(exp, FunctionCall):
return exp

if exp.function_name == "and":
return combine_and_conditions(exp.parameters)
elif exp.function_name == "or":
return combine_or_conditions(exp.parameters)
else:
return exp

query.transform_expressions(transform)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these are in rpc/common.py already

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I think this entire file is in snuba/web/rpc/common.py

# https://clickhouse.com/docs/en/engines/table-engines/mergetree-family/mergetree#functions-support
f.multiSearchAny(
column("attr_value"),
literals_array(None, [literal(request.value_substring_match)]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if the value_substring_match field is not set?

Comment on lines +112 to +113
print("snuba_request")
print(snuba_request)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove these too

Comment on lines +119 to +121
return TraceItemAttributeValuesResponse(
values=[r["attr_value"] for r in res.result.get("data", [])]
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing pagination support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants