-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add a Rails::Engine-based dashboard with trace viewer #5244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
76dad36
Add Rails engine-based dashboard with Perfetto trace listing
rmosolgo 5037617
Add memory and redis backends
rmosolgo 6ef72dc
Add icons and dark mode
rmosolgo a72de98
update tests, statics
rmosolgo 96470ee
Add tests for memory and redis storage
rmosolgo 93ff323
improve Redis CI setup
rmosolgo 68129a9
Add PerfettoSampler tests
rmosolgo d020c1d
Add test coverage
rmosolgo 1cf44ac
Fix a couple of tests
rmosolgo e15a9d4
Try running system tests with a ci gemfile
rmosolgo 652b38a
Try different gemfile setup
rmosolgo d556cd0
try bin/rails
rmosolgo 2245b02
Try relative gemfile path
rmosolgo ad24c1c
Merge branch 'master' into dashboard-engine
rmosolgo 56113c9
Merge branch 'master' into dashboard-engine
rmosolgo 06db592
Clear any leftover flow stack
rmosolgo 1bd193e
Merge branch 'master' into dashboard-engine
rmosolgo 1d11253
Add CSP rules
rmosolgo 735eed9
Start adding tests
rmosolgo 86b526e
Add tests for Dashboard controllers
rmosolgo bf7cf65
Update Redis backend
rmosolgo ae7eceb
Add limit: option
rmosolgo 9de189a
Update error message test
rmosolgo 3b5566a
fix dashboard tests
rmosolgo ace88db
Rename to DetailedTrace, write docs
rmosolgo c5415bf
Add test for multiplex
rmosolgo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| # frozen_string_literal: true | ||
| require 'rails/engine' | ||
|
|
||
| module Graphql | ||
| # `GraphQL::Dashboard` is a `Rails::Engine`-based dashboard for viewing metadata about your GraphQL schema. | ||
| # | ||
| # Pass the class name of your schema when mounting it. | ||
| # @see GraphQL::Tracing::DetailedTrace DetailedTrace for viewing production traces in the Dashboard | ||
| # | ||
| # @example Mounting the Dashboard in your app | ||
| # mount GraphQL::Dashboard, at: "graphql_dashboard", schema: "MySchema" | ||
| # | ||
| # @example Authenticating the Dashboard with HTTP Basic Auth | ||
| # # config/initializers/graphql_dashboard.rb | ||
| # GraphQL::Dashboard.middleware.use(Rack::Auth::Basic) do |username, password| | ||
| # # Compare the provided username/password to an application setting: | ||
| # ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.graphql_dashboard_username, username) && | ||
| # ActiveSupport::SecurityUtils.secure_compare(Rails.application.credentials.graphql_dashboard_username, password) | ||
| # end | ||
| # | ||
| # @example Custom Rails authentication | ||
| # # config/initializers/graphql_dashboard.rb | ||
| # ActiveSupport.on_load(:graphql_dashboard_application_controller) do | ||
| # # context here is GraphQL::Dashboard::ApplicationController | ||
| # | ||
| # before_action do | ||
| # raise ActionController::RoutingError.new('Not Found') unless current_user&.admin? | ||
| # end | ||
| # | ||
| # def current_user | ||
| # # load current user | ||
| # end | ||
| # end | ||
| # | ||
| class Dashboard < Rails::Engine | ||
| engine_name "graphql_dashboard" | ||
| isolate_namespace(Graphql::Dashboard) | ||
| routes.draw do | ||
| root "landings#show" | ||
| resources :statics, only: :show, constraints: { id: /[0-9A-Za-z\-.]+/ } | ||
| delete "/traces/delete_all", to: "traces#delete_all", as: :traces_delete_all | ||
| resources :traces, only: [:index, :show, :destroy] | ||
| end | ||
|
|
||
| class ApplicationController < ActionController::Base | ||
| protect_from_forgery with: :exception | ||
| prepend_view_path(File.join(__FILE__, "../dashboard/views")) | ||
|
|
||
| content_security_policy do |policy| | ||
| policy.default_src(:self) if policy.default_src(*policy.default_src).blank? | ||
| policy.connect_src(:self) if policy.connect_src(*policy.connect_src).blank? | ||
| policy.base_uri(:none) if policy.base_uri(*policy.base_uri).blank? | ||
| policy.font_src(:self) if policy.font_src(*policy.font_src).blank? | ||
| policy.img_src(:self, :data) if policy.img_src(*policy.img_src).blank? | ||
| policy.object_src(:none) if policy.object_src(*policy.object_src).blank? | ||
| policy.script_src(:self) if policy.script_src(*policy.script_src).blank? | ||
| policy.style_src(:self) if policy.style_src(*policy.style_src).blank? | ||
| policy.form_action(:self) if policy.form_action(*policy.form_action).blank? | ||
| policy.frame_ancestors(:none) if policy.frame_ancestors(*policy.frame_ancestors).blank? | ||
| end | ||
|
|
||
| def schema_class | ||
| @schema_class ||= begin | ||
| schema_param = request.query_parameters["schema"] || params[:schema] | ||
| case schema_param | ||
| when Class | ||
| schema_param | ||
| when String | ||
| schema_param.constantize | ||
| else | ||
| raise "Missing `params[:schema]`, please provide a class or string to `mount GraphQL::Dashboard, schema: ...`" | ||
| end | ||
| end | ||
| end | ||
| helper_method :schema_class | ||
| end | ||
|
|
||
| class LandingsController < ApplicationController | ||
| def show | ||
| end | ||
| end | ||
|
|
||
| class TracesController < ApplicationController | ||
| def index | ||
| @detailed_trace_installed = !!schema_class.detailed_trace | ||
| if @detailed_trace_installed | ||
| @last = params[:last]&.to_i || 50 | ||
| @before = params[:before]&.to_i | ||
| @traces = schema_class.detailed_trace.traces(last: @last, before: @before) | ||
| end | ||
| end | ||
|
|
||
| def show | ||
| trace = schema_class.detailed_trace.find_trace(params[:id].to_i) | ||
| send_data(trace.trace_data) | ||
| end | ||
|
|
||
| def destroy | ||
| schema_class.detailed_trace.delete_trace(params[:id]) | ||
| head :no_content | ||
| end | ||
|
|
||
| def delete_all | ||
| schema_class.detailed_trace.delete_all_traces | ||
| head :no_content | ||
| end | ||
| end | ||
|
|
||
| class StaticsController < ApplicationController | ||
| skip_after_action :verify_same_origin_request | ||
| # Use an explicit list of files to avoid any chance of reading other files from disk | ||
| STATICS = {} | ||
|
|
||
| [ | ||
| "icon.png", | ||
| "header-icon.png", | ||
| "dashboard.css", | ||
| "dashboard.js", | ||
| "bootstrap-5.3.3.min.css", | ||
| "bootstrap-5.3.3.min.js", | ||
| ].each do |static_file| | ||
| STATICS[static_file] = File.expand_path("../dashboard/statics/#{static_file}", __FILE__) | ||
| end | ||
|
|
||
| def show | ||
| expires_in 1.year, public: true | ||
| if (filepath = STATICS[params[:id]]) | ||
| render file: filepath | ||
| else | ||
| head :not_found | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # Rails expects the engine to be called `Graphql::Dashboard`, | ||
| # but `GraphQL::Dashboard` is consistent with this gem's naming. | ||
| # So define both constants to refer to the same class. | ||
| GraphQL::Dashboard = Graphql::Dashboard | ||
|
|
||
| ActiveSupport.run_load_hooks(:graphql_dashboard_application_controller, GraphQL::Dashboard::ApplicationController) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #header-icon { | ||
| max-height: 2em; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)