From 0c8095493a469071b64723de821ae68706ffdb2a Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Thu, 8 Feb 2018 22:29:58 -0800 Subject: [PATCH] Skylight instrumentation This allows individual installations to optionally collect performance data using [Skylight for Open Source](https://www.skylight.io/oss). --- Gemfile | 3 ++ Gemfile.lock | 3 ++ INSTALL.md | 7 ++++ app/views/layouts/application.html.haml | 9 +++-- dotenv.example | 4 ++ .../application_controller_spec.rb | 40 ++++++++++++++++++- 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index e624a1f7..9be883a3 100644 --- a/Gemfile +++ b/Gemfile @@ -209,6 +209,9 @@ gem 'sprockets-rails' # for multiple speakers select on proposal/event forms gem 'selectize-rails' +# For collecting performance data +gem 'skylight' + # Nokogiri < 1.8.1 is subject to: # CVE-2017-0663, CVE-2017-7375, CVE-2017-7376, CVE-2017-9047, CVE-2017-9048, # CVE-2017-9049, CVE-2017-9050 diff --git a/Gemfile.lock b/Gemfile.lock index 38a4fce0..9e07eb20 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -505,6 +505,8 @@ GEM simplecov-html (~> 0.10.0) simplecov-html (0.10.0) sixarm_ruby_unaccent (1.1.1) + skylight (1.5.1) + activesupport (>= 3.0.0) slop (3.6.0) sort_alphabetical (1.0.2) unicode_utils (>= 1.2.2) @@ -668,6 +670,7 @@ DEPENDENCIES sass-rails (>= 4.0.2) selectize-rails shoulda-matchers + skylight spring-commands-rspec sprockets-rails sqlite3 diff --git a/INSTALL.md b/INSTALL.md index ea47fd93..06249929 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -106,6 +106,8 @@ There are a couple of environment variables you can set to configure OSEM. Check | STRIPE_PUBLISHABLE_KEY | *string* | Publishable Key for Stripe Gateway | STRIPE_SECRET_KEY | *string* | Secret Key for Stripe Gateway | OSEM_REDIS_URL | *string* | Redis server URL e.g. redis://localhost:6379/1 +| SKYLIGHT_AUTHENTICATION | *string* | (Optional) Authentication token for Skylight +| SKYLIGHT_PUBLIC_DASHBOARD_URL | *string* | (Optional) URL to your public Skylight dashboard ### Online Ticket Payments We use [Stripe](https://stripe.com) for accepting your ticket payments securely over the web. @@ -130,3 +132,8 @@ Open a separate terminal and go into the directory where the rails app is presen ``` bundle exec rake jobs:work ``` + +## Performance +If you are experiencing performance issues (or just curious), you may be able to [apply a free Skylight account](https://www.skylight.io/oss). +Once you have your account setup, simply set `SKYLIGHT_AUTHENTICATION` and `SKYLIGHT_PUBLIC_DASHBOARD_URL` in your `.env` file. +If you are reporting a performance issue or submiting a performance patch, it would be helpful (but not required) to link to the relevant Skylight data. diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index aa155bcb..128f491a 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -37,11 +37,14 @@ %p.muted.text-center %small This tool is - =link_to "free software,", "http://www.gnu.org/philosophy/free-sw.html" + #{link_to "free software", "http://www.gnu.org/philosophy/free-sw.html"}, released under the - =link_to "MIT license.", "http://opensource.org/licenses/MIT" + #{link_to "MIT license", "http://opensource.org/licenses/MIT"}. You can run, copy, distribute, study, change and improve it. The source code and the developers are on - =link_to "github.", "https://github.com/openSUSE/osem" + #{link_to "GitHub", "https://github.com/openSUSE/osem"}. + - if ENV["SKYLIGHT_PUBLIC_DASHBOARD_URL"].present? + Performance data is available on + #{link_to "Skylight", ENV["SKYLIGHT_PUBLIC_DASHBOARD_URL"]}. = yield :script_body = piwik_tracking_tag diff --git a/dotenv.example b/dotenv.example index e0e3f519..6d8dd025 100644 --- a/dotenv.example +++ b/dotenv.example @@ -46,6 +46,10 @@ OSEM_SUSE_SECRET='' STRIPE_PUBLISHABLE_KEY='' STRIPE_SECRET_KEY='' +# (OPTIONAL) Skylight keys. See https://www.skylight.io/oss. +# SKYLIGHT_AUTHENTICATION='' +# SKYLIGHT_PUBLIC_DASHBOARD_URL='https://oss.skylight.io/app/applications/xxxxxxxxxxxx' + # Disable linting of factories in the test suite. # Speeds up turn around times of tests OSEM_FACTORY_LINT="false" diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 214e522a..4d1c2eab 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -30,7 +30,45 @@ describe ApplicationController, type: :controller do expect(controller.after_sign_in_path_for(user)).to eq conferences_path end end - + end + + end + +end + +describe ApplicationController, type: :request do + let(:conference) { create(:conference) } + + describe 'Skylight link' do + + around do |example| + original_value = ENV['SKYLIGHT_PUBLIC_DASHBOARD_URL'] + example.run + ENV['SKYLIGHT_PUBLIC_DASHBOARD_URL'] = original_value + end + + context 'when SKYLIGHT_PUBLIC_DASHBOARD_URL is set' do + before do + ENV['SKYLIGHT_PUBLIC_DASHBOARD_URL'] = 'https://oss.skylight.io/app/applications/my-osem' + end + + it 'should include a link to view performance data' do + get '/' + expect(response.body).to match(/Performance data/i) + expect(response.body).to include('https://oss.skylight.io/app/applications/my-osem') + end + end + + context 'when SKYLIGHT_PUBLIC_DASHBOARD_URL is not set' do + before do + ENV['SKYLIGHT_PUBLIC_DASHBOARD_URL'] = nil + end + + it 'should not include a link to view performance data' do + get '/' + expect(response.body).to_not match(/performance data/i) + expect(response.body).to_not match(/skylight/i) + end end end