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

feat(tracing) Add a UI and backend for trace data #2309

Merged
merged 25 commits into from
Jan 12, 2022

Conversation

evanh
Copy link
Member

@evanh evanh commented Dec 17, 2021

Add a (very rudimentary) UI that allows a query to be run and displays the trace
for that query. It will also display any error that may have arrived from
running the query.

Add a (very rudimentary) UI that allows a query to be run and displays the trace
for that query. It will also display any error that may have arrived from
running the query.
@evanh evanh requested a review from a team as a code owner December 17, 2021 22:10
Copy link
Member

@lynnagara lynnagara left a comment

Choose a reason for hiding this comment

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

Just a couple of questions

snuba/clickhouse/native.py Outdated Show resolved Hide resolved
snuba/clickhouse/native.py Outdated Show resolved Hide resolved
snuba/admin/clickhouse/common.py Outdated Show resolved Hide resolved
Copy link
Contributor

@onewland onewland left a comment

Choose a reason for hiding this comment

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

Looks good to me, outside of a couple comments.

Were you able to test this locally e.g. with the curl command in the comment?

snuba/admin/views.py Outdated Show resolved Hide resolved
tests/admin/test_api.py Outdated Show resolved Hide resolved
snuba/admin/static/tracing/index.tsx Outdated Show resolved Hide resolved
snuba/admin/static/api_client.tsx Outdated Show resolved Hide resolved
snuba/admin/views.py Outdated Show resolved Hide resolved
Copy link
Member

@lynnagara lynnagara left a comment

Choose a reason for hiding this comment

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

This PR is quite large and involves a lot of refactoring that touches other functionality including core ClickHouse driver functionality. It's also hard to figure out what's changed and what's just moved around. Please consider splitting it up.

Currently you must run make build-admin manually before pushing the bundle.js file as we do not build it in CI for prod and rely on the checked in version of this file. Currently you have pushed the dev version of the bundle.

snuba/admin/clickhouse/common.py Outdated Show resolved Hide resolved
snuba/admin/clickhouse/tracing.py Outdated Show resolved Hide resolved
snuba/admin/static/components/query_display/types.tsx Outdated Show resolved Hide resolved
snuba/admin/static/tracing/index.tsx Outdated Show resolved Hide resolved
snuba/admin/static/tracing/index.tsx Outdated Show resolved Hide resolved
snuba/admin/static/tracing/index.tsx Outdated Show resolved Hide resolved
snuba/admin/views.py Outdated Show resolved Hide resolved
snuba/admin/views.py Outdated Show resolved Hide resolved
@evanh evanh force-pushed the feat/capture-trace-admin-portal branch from c83062c to f88f7e5 Compare January 4, 2022 22:08
Copy link
Member

@nikhars nikhars left a comment

Choose a reason for hiding this comment

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

Left some minor comments

snuba/admin/clickhouse/common.py Outdated Show resolved Hide resolved
snuba/admin/clickhouse/common.py Show resolved Hide resolved
Comment on lines 43 to 44
if storage_key in CONNECTIONS:
return CONNECTIONS[storage_key]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will work.

The issue is that there are two separate use cases, you cannot use the same logic to retrieve a connection for the tracing tool (that needs to talk to a query node through envoy) and for the system tables tool (which needs to access individual nodes and uses the storage key just to fetch the right cluster to validate the host name/port).

Specifically:
Here the system table tool will create a connection to the required host the first time and cache it. Subsequently it will always return the same connection to the same host for the same storage, no matter which host/port the user wants. Which is wrong. If you want to cache connections for the system tables tool, the key must contain at least the host name as well.

I think you want two methods, one to return a query connection to a cluster given a storage key. And another one to take host/port and validates they are part of a storage and then return a connection to those.
The system tables tool would use the first. The tracing tool would use the second (or both if you want to get a trace from a query ran on a storage node)

Copy link
Member Author

Choose a reason for hiding this comment

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

I split the connection functions into two, one for system queries that cache by hostname, and one for tracing queries that cache by cluster.

@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2022

Codecov Report

Merging #2309 (60ff1ba) into master (0b53064) will increase coverage by 0.17%.
The diff coverage is 91.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2309      +/-   ##
==========================================
+ Coverage   92.76%   92.93%   +0.17%     
==========================================
  Files         561      563       +2     
  Lines       25790    25888      +98     
==========================================
+ Hits        23924    24059     +135     
+ Misses       1866     1829      -37     
Impacted Files Coverage Δ
tests/clickhouse/test_query_format.py 100.00% <ø> (+6.97%) ⬆️
snuba/admin/views.py 58.97% <83.33%> (+16.43%) ⬆️
snuba/admin/clickhouse/common.py 87.50% <87.50%> (ø)
snuba/admin/clickhouse/tracing.py 93.75% <93.75%> (ø)
tests/admin/test_api.py 98.55% <97.43%> (-1.45%) ⬇️
snuba/admin/clickhouse/system_queries.py 83.11% <100.00%> (+17.11%) ⬆️
snuba/clickhouse/native.py 82.60% <100.00%> (+0.50%) ⬆️
tests/admin/test_system_queries.py 100.00% <100.00%> (ø)
tests/test_clickhouse.py 100.00% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b53064...60ff1ba. Read the comment docs.

@evanh evanh requested a review from fpacifici January 10, 2022 13:54
@nikhars
Copy link
Member

nikhars commented Jan 10, 2022

LGTM

Copy link
Contributor

@fpacifici fpacifici left a comment

Choose a reason for hiding this comment

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

Fyi: the readonly user is not present on the query nodes. So you will need to send a request to create it. @nikhars could help you with this.

def run_query_and_get_trace(storage_name: str, query: str) -> ClickhouseResult:
validate_trace_query(query)
connection = get_ro_cluster_connection(storage_name)
query_result = connection.execute(query=query, capture_trace=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will run the query on one single thread. Which is good to start with.
Though later we will want to add a switch to use 1 thread vs 2 or 4 to test how the query parallelizes.

@evanh evanh merged commit 6f92898 into master Jan 12, 2022
@evanh evanh deleted the feat/capture-trace-admin-portal branch January 12, 2022 18:50
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.

7 participants