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

Add a Rails::Engine-based dashboard with trace viewer #5244

Merged
merged 26 commits into from
Feb 25, 2025
Merged

Conversation

rmosolgo
Copy link
Owner

@rmosolgo rmosolgo commented Feb 19, 2025

I've been working on a detailed query tracer which produces artifacts for Perfetto (https://perfetto.dev). In this PR I'm going to:

  • create a new dashboard, GraphQL::Dashboard, which is a Rails engine
  • Add a "traces" view which lists saved traces and links to Perfetto to view them
  • Add a backend to PerfettoTrace so that traces can be saved for later (Redis and ActiveRecord)

Why a Rails Engine? I've seen it done nicely, eg https://github.com/bensheldon/good_job, https://github.com/mbajur/inner_performance. I have rolled my own in GraphQL::Pro::Dashboard for a long time but I'm not sure it's worth it. I think everyone uses Rails, and an Engine will bring a lot of convenience in development, robustness in production, lots of configuration options. If you're not using Rails, I think you could spin up a sidecar app just for running the dashboard if you need to.

I plan to replace GraphQL::Pro::Dashboard with this one (rolling its features into this one).

TODO:

  • Create backends for trace data
  • Add docs and links to docs
  • Add CSP configurations
  • Add dashboard tests
  • Use local static files instead of CDN
  • Pagination for trace listing
  • Auto-expiry, delete, delete all for stored traces
  • Reconsider the name of this feature: how much do I want perfetto to be "just" an implementation detail?

@@ -125,6 +125,9 @@ class << self
autoload :LoadApplicationObjectFailedError, "graphql/load_application_object_failed_error"
autoload :Testing, "graphql/testing"
autoload :Current, "graphql/current"
if defined?(::Rails::Engine)

Choose a reason for hiding this comment

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

module GraphQL missing tests for lines 15, 16, 17, 18, 63, 67, 68, 72, 128, 128, 128 (coverage: 0.88)

@rmosolgo rmosolgo added this to the 2.4.11 milestone Feb 24, 2025
# @return [Boolean] When `true`, save a detailed trace for this query.
# @see Tracing::DetailedTrace DetailedTrace saves traces when this method returns true
def detailed_trace?(query)
raise "#{self} must implement `def.detailed_trace?(query)` to use DetailedTrace. Implement this method in your schema definition."

Choose a reason for hiding this comment

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

instance method detailed_trace? missing tests for line 1376 (coverage: 0.0)

target = options[:query] || options[:multiplex]
mode ||= target && target.context[:trace_mode]
should_sample = if detailed_trace
if (query = options[:query])

Choose a reason for hiding this comment

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

instance method new_trace missing tests for lines 1469, 1470, 1471, 1475, 1469, 1470, 1471, 1471, 1474 (coverage: 0.75)

# @param redis [Redis] If provided, profiles will be stored in Redis for later review
# @param limit [Integer] A maximum number of profiles to store
def self.use(schema, trace_mode: :profile_sample, memory: false, redis: nil, limit: nil)
storage = if redis

Choose a reason for hiding this comment

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

class method use missing tests for lines 34, 35, 34, 35 (coverage: 0.75)

end

def traces(last:, before:)
before = case before

Choose a reason for hiding this comment

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

instance method traces missing tests for lines 15, 15 (coverage: 0.875)

target = options[:query] || options[:multiplex]
mode ||= target && target.context[:trace_mode]
should_sample = if detailed_trace
if (query = options[:query])

Choose a reason for hiding this comment

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

instance method new_trace missing tests for lines 1469, 1470, 1471, 1469, 1470, 1471, 1471 (coverage: 0.85)

@rmosolgo rmosolgo merged commit 46f8b69 into master Feb 25, 2025
14 checks passed
@rmosolgo rmosolgo deleted the dashboard-engine branch February 25, 2025 13:08
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.

1 participant