Skip to content

Commit

Permalink
Merge pull request #1781 from datadryad/3472-healthcheck-page
Browse files Browse the repository at this point in the history
added health check endpoint
  • Loading branch information
ryscher authored Jul 23, 2024
2 parents 7c092ca + 87ecfe3 commit af811ef
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 45 deletions.
42 changes: 42 additions & 0 deletions app/controllers/health_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class HealthController < ApplicationController

def check
health_status = { status: 'OK' }

# Check database connectivity
begin
StashEngine::Identifier.last
health_status[:database] = 'connected'
rescue StandardError => e
health_status[:database] = 'not connected'
health_status[:database_error] = e.message if params[:advanced]
end

# Check Solr connectivity
begin
solr = RSolr.connect(url: Blacklight.connection_config[:url])
solr.get('select', params: { fl: 'dc_identifier_s', rows: 1 })
health_status[:solr] = 'connected'
rescue StandardError => e
health_status[:solr] = 'not connected'
health_status[:solr_error] = e.message if params[:advanced]
end

# Check AWS S3 connectivity
begin
if Stash::Aws::S3.new.exists?(s3_key: 's3_status_check.txt')
health_status[:aws_s3] = 'connected'
else
health_status[:aws_s3] = 'not connected'
health_status[:aws_s3_error] = 'file does not exist' if params[:advanced]
end
rescue StandardError => e
health_status[:aws_s3] = 'not connected'
health_status[:aws_s3_error] = e.message if params[:advanced]
end

status_code = health_status.values.include?('not connected') ? :service_unavailable : :ok
health_status[:status] = status_code
render json: health_status, status: status_code
end
end
92 changes: 47 additions & 45 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
match '/search', to: 'datasets#search', via: %i[get]
get '/reports', to: 'api#reports_index'
get '/reports(/:report_name)', to: 'api#reports'

# Support for the Editorial Manager API
match '/em_submission_metadata(/:id)', constraints: { id: /\S+/ }, to: 'datasets#em_submission_metadata', via: %i[post put]

Expand All @@ -113,16 +113,16 @@
end
resources :processor_results, only: [:show, :index, :create, :update]
end

resources :urls, shallow: true, path: '/urls', only: [:create]
end

# this one doesn't follow the pattern since it gloms filename on the end, so manual route
# supporting both POST and PUT for updating the file to ensure as many clients as possible can use this end point
match '/datasets/:id/files/:filename', to: 'files#update', as: 'dataset_file', constraints: { id: %r{[^\s/]+?}, filename: %r{[^\s/]+?} }, format: false, via: %i[post put]

resources :users, path: '/users', only: %i[index show]

get '/queue_length', to: 'submission_queue#length'
end

Expand All @@ -136,7 +136,7 @@

########################## StashEngine support ######################################

scope module: 'stash_engine', path: '/stash' do
scope module: 'stash_engine', path: '/stash' do

get 'landing/show'

Expand All @@ -159,21 +159,21 @@
end
match 'identifier_internal_data/:identifier_id', to: 'internal_data#create', as: 'internal_data_create', via: %i[get post put]
resources :internal_data, shallow: true, as: 'stash_engine_internal_data'

resources :tenants, only: %i[index show]
resources :data_files, :software_files, :supp_files do
member do
patch 'destroy_manifest' # destroy file from manifest method
end
end

resources :edit_histories, only: [:index]

# these are weird and different and want to get rid of these with file redesign
match 'data_file/validate_urls/:resource_id', to: 'data_files#validate_urls', as: 'data_file_validate_urls', via: %i[get post put]
match 'software_file/validate_urls/:resource_id', to: 'software_files#validate_urls', as: 'software_file_validate_urls', via: %i[get post put]
match 'supp_file/validate_urls/:resource_id', to: 'supp_files#validate_urls', as: 'supp_file_validate_urls', via: %i[get post put]

get 'data_file/presign_upload/:resource_id', to: 'data_files#presign_upload', as: 'data_file_presign_url'
get 'software_file/presign_upload/:resource_id', to: 'software_files#presign_upload', as: 'software_file_presign_url'
get 'supp_file/presign_upload/:resource_id', to: 'supp_files#presign_upload', as: 'supp_file_presign_url'
Expand All @@ -191,15 +191,15 @@
get 'generic_file/check_frictionless/:resource_id',
to: 'generic_files#check_frictionless',
as: 'generic_file_check_frictionless'

get 'dashboard', to: 'dashboard#show', as: 'dashboard'
get 'dashboard/user_datasets', to: 'dashboard#user_datasets'
get 'ajax_wait', to: 'dashboard#ajax_wait', as: 'ajax_wait'
get 'metadata_basics', to: 'dashboard#metadata_basics', as: 'metadata_basics'
get 'preparing_to_submit', to: 'dashboard#preparing_to_submit', as: 'preparing_to_submit'
get 'upload_basics', to: 'dashboard#upload_basics', as: 'upload_basics'
get 'react_basics', to: 'dashboard#react_basics', as: 'react_basics'

# download related
match 'downloads/zip_assembly_info/:resource_id', to: 'downloads#zip_assembly_info', as: 'zip_assembly_info', via: %i[get post]
match 'downloads/download_resource/:resource_id', to: 'downloads#download_resource', as: 'download_resource', via: %i[get post]
Expand All @@ -209,31 +209,31 @@
get 'downloads/preview_csv/:file_id', to: 'downloads#preview_csv', as: 'preview_csv'
get 'share/:id', to: 'downloads#share', as: 'share'
get 'downloads/assembly_status/:id', to: 'downloads#assembly_status', as: 'download_assembly_status'

get 'edit/:doi/:edit_code', to: 'metadata_entry_pages#edit_by_doi', as: 'edit', constraints: { doi: /\S+/ }
match 'metadata_entry_pages/find_or_create', to: 'metadata_entry_pages#find_or_create', via: %i[get post put]
match 'metadata_entry_pages/new_version', to: 'metadata_entry_pages#new_version', via: %i[post get]
post 'metadata_entry_pages/new_version_from_previous', to: 'metadata_entry_pages#new_version_from_previous'
match 'metadata_entry_pages/reject_agreement', to: 'metadata_entry_pages#reject_agreement', via: [:delete]
match 'metadata_entry_pages/accept_agreement', to: 'metadata_entry_pages#accept_agreement', via: [:post]

# root 'sessions#index'
root 'pages#home', as: 'pages_root'

match 'auth/orcid/callback', to: 'sessions#orcid_callback', via: %i[get post]
match 'auth/google_oauth2/callback', to: 'sessions#google_callback', via: %i[get post]
match 'auth/developer/callback', to: 'sessions#developer_callback', via: %i[get post]
match 'auth/:provider/callback', to: 'sessions#callback', via: %i[get post]
match 'session/test_login', to: 'sessions#test_login', via: [:get, :post], as: 'test_login'

match 'terms/view', to: 'dashboard#view_terms', via: %i[get post]

get 'auth/failure', to: redirect('/')
match 'sessions/destroy', to: 'sessions#destroy', via: %i[get post]
get 'sessions/choose_login', to: 'sessions#choose_login', as: 'choose_login'
get 'sessions/choose_sso', to: 'sessions#choose_sso', as: 'choose_sso'
match 'sessions/no_partner', to: 'sessions#no_partner', as: 'no_partner', via: [:get, :post]
post 'sessions/sso', to: 'sessions#sso', as: 'sso'
post 'sessions/sso', to: 'sessions#sso', as: 'sso'
get 'feedback', to: 'sessions#feedback', as: 'feedback'
post 'feedback_signup', to: 'sessions#feedback_signup', as: 'feedback_signup'

Expand Down Expand Up @@ -274,14 +274,14 @@
get 'landing/metrics/:identifier_id', to: 'landing#metrics', as: 'show_metrics'
get 'test', to: 'pages#test'
get 'ip_error', to: 'pages#ip_error'

# user management
get 'account', to: 'user_account#index', as: 'my_account'
post 'account/edit', to: 'user_account#edit', as: 'edit_account'
# admin user management
get 'user_admin', to: 'user_admin#index' # main page for administering users
# page for viewing a single user
get 'user_admin/user_profile/:id', to: 'user_admin#user_profile', as: 'user_admin_profile'
get 'user_admin/user_profile/:id', to: 'user_admin#user_profile', as: 'user_admin_profile'
post 'user_admin/set_role/:id', to: 'user_admin#set_role', as: 'user_admin_set_role'
# admin editing user
get 'user_admin/merge', to: 'user_admin#merge_popup', as: 'user_merge_popup'
Expand Down Expand Up @@ -330,30 +330,30 @@

# admin report for dataset funders
get 'ds_admin_funders', to: 'admin_dataset_funders#index', as: 'ds_admin_funders'

# routing for submission queue controller
get 'submission_queue', to: 'submission_queue#index'
get 'submission_queue/refresh_table', to: 'submission_queue#refresh_table'
get 'submission_queue/graceful_start', to: 'submission_queue#graceful_start', as: 'graceful_start'

# routing for zenodo_queue
get 'zenodo_queue', to: 'zenodo_queue#index', as: 'zenodo_queue'
get 'zenodo_queue/item_details/:id', to: 'zenodo_queue#item_details', as: 'zenodo_queue_item_details'
get 'zenodo_queue/identifier_details/:id', to: 'zenodo_queue#identifier_details', as: 'zenodo_queue_identifier_details'
post 'zenodo_queue/resubmit_job', to: 'zenodo_queue#resubmit_job', as: 'zenodo_queue_resubmit_job'
post 'zenodo_queue/set_errored', to: 'zenodo_queue#set_errored', as: 'zenodo_queue_set_errored'

# Administrative Status Dashboard that displays statuses of external dependencies
get 'status_dashboard', to: 'status_dashboard#show'

# Publication updater page - Allows admins to accept/reject metadata changes from external sources like Crrossref
get 'publication_updater', to: 'publication_updater#index'
put 'publication_updater/:id', to: 'publication_updater#update'
delete 'publication_updater/:id', to: 'publication_updater#destroy'

# Curation stats
get 'curation_stats', to: 'curation_stats#index'

# Journals
get 'journals', to: 'journals#index'

Expand All @@ -376,80 +376,80 @@

# this is kind of hacky, but it directs our search results to open links to the landing pages
resources :solr_documents, only: [:show], path: '/stash/dataset', controller: 'catalog'

########################## StashDatacite support ######################################

scope module: 'stash_datacite', path: '/stash_datacite' do
scope module: 'stash_datacite', path: '/stash_datacite' do
get 'titles/new', to: 'titles#new'
post 'titles/create', to: 'titles#create'
patch 'titles/update', to: 'titles#update'

get 'descriptions/new', to: 'descriptions#new'
patch 'descriptions/update', to: 'descriptions#update'

get 'temporal_coverages/new', to: 'temporal_coverages#new'
patch 'temporal_coverages/update', to: 'temporal_coverages#update'

get 'authors/new', to: 'authors#new'
post 'authors/create', to: 'authors#create'
patch 'authors/update', to: 'authors#update'
delete 'authors/:id/delete', to: 'authors#delete', as: 'authors_delete'
patch 'authors/reorder', to: 'authors#reorder', as: 'authors_reorder'

get 'contributors/new', to: 'contributors#new'
get 'contributors/autocomplete', to: 'contributors#autocomplete'
post 'contributors/create', to: 'contributors#create'
patch 'contributors/update', to: 'contributors#update'
patch 'contributors/reorder', to: 'contributors#reorder', as: 'contributors_reorder'
delete 'contributors/:id/delete', to: 'contributors#delete', as: 'contributors_delete'

get 'publications/new', to: 'publications#new'
get 'publications/autocomplete', to: 'publications#autocomplete'
get 'publications/issn/:id', to: 'publications#issn'
post 'publications/create', to: 'publications#create'
patch 'publications/update', to: 'publications#update'
delete 'publications/:id/delete', to: 'publications#delete', as: 'publications_delete'
post 'publications/autofill/:id', to: 'publications#autofill_data', as: 'publications_autofill_data'

get 'resource_types/new', to: 'resource_types#new'
post 'resource_types/create', to: 'resource_types#create'
patch 'resource_types/update', to: 'resource_types#update'

get 'subjects/new', to: 'subjects#new'
get 'subjects/autocomplete', to: 'subjects#autocomplete'
post 'subjects/create', to: 'subjects#create'
delete 'subjects/:id/delete', to: 'subjects#delete', as: 'subjects_delete'
get 'subjects/landing', to: 'subjects#landing', as: 'subjects_landing'

# fos subjects are a special subject that is treated differently for the OECD Field of Science
patch 'fos_subjects/update', to: 'fos_subjects#update'

get 'related_identifiers/new', to: 'related_identifiers#new'
post 'related_identifiers/create', to: 'related_identifiers#create'
patch 'related_identifiers/update', to: 'related_identifiers#update'
delete 'related_identifiers/:id/delete', to: 'related_identifiers#delete', as: 'related_identifiers_delete'
get 'related_identifiers/report', to: 'related_identifiers#report', as: 'related_identifiers_report'
get 'related_identifiers/show', to: 'related_identifiers#show', as: 'related_identifiers_show'

get 'geolocation_places/new', to: 'geolocation_places#new'
post 'geolocation_places/create', to: 'geolocation_places#create'
delete 'geolocation_places/:id/delete', to: 'geolocation_places#delete', as: 'geolocation_places_delete'

get 'geolocation_points/new', to: 'geolocation_points#new'
post 'geolocation_points/create', to: 'geolocation_points#create'
delete 'geolocation_points/:id/delete', to: 'geolocation_points#delete', as: 'geolocation_points_delete'

get 'geolocation_boxes/new', to: 'geolocation_boxes#new'
post 'geolocation_boxes/create', to: 'geolocation_boxes#create'
delete 'geolocation_boxes/:id/delete', to: 'geolocation_boxes#delete', as: 'geolocation_boxes_delete'

get 'affiliations/autocomplete', to: 'affiliations#autocomplete'
get 'affiliations/new', to: 'affiliations#new'
post 'affiliations/create', to: 'affiliations#create'
delete 'affiliations/:id/delete', to: 'affiliations#delete', as: 'affiliations_delete'

get 'licenses/details', to: 'licenses#details', as: 'license_details'

# Actions through Leaflet Ajax posts
# points
get 'geolocation_points/index', to: 'geolocation_points#index'
Expand All @@ -463,14 +463,14 @@
# location names/places
get 'geolocation_places/places_coordinates', to: 'geolocation_places#places_coordinates'
post 'geolocation_places/map_coordinates', to: 'geolocation_places#map_coordinates'

# get composite views or items that begin at the resource level
get 'metadata_entry_pages/find_or_create', to: 'metadata_entry_pages#find_or_create', as: :datacite_metadata_entry_pages
get 'metadata_entry_pages/cedar_check', to: 'metadata_entry_pages#cedar_check', as: :metadata_entry_cedar_check
get 'resources/review', to: 'resources#review'
match 'resources/submission' => 'resources#submission', as: :resources_submission, via: :post
get 'resources/show', to: 'resources#show'

patch 'peer_review/toggle', to: 'peer_review#toggle', as: :peer_review
patch 'peer_review/release', to: 'peer_review#release', as: :peer_review_release
end
Expand All @@ -486,9 +486,9 @@

get '/cedar-config', to: 'cedar#json_config'
post '/cedar-save', to: 'cedar#save'

########################## Dryad v1 support ######################################

# Routing to redirect old Dryad URLs to their correct locations in this system
get '/pages/faq', to: redirect('stash/requirements')
get '/pages/jdap', to: redirect('docs/JointDataArchivingPolicy.pdf')
Expand All @@ -514,7 +514,7 @@
get '/submit', to: redirect { |params, request| "/stash/resources/new?#{request.params.to_query}" }
get '/interested', to: redirect('/stash/contact#get-involved')
get '/stash/interested', to: redirect('/stash/contact#get-involved')

# Routing to redirect old Dryad landing pages to the correct location
# Regex based on https://www.crossref.org/blog/dois-and-matching-regular-expressions/ but a little more restrictive specific to old dryad
# Dataset: https://datadryad.org/resource/doi:10.5061/dryad.kq201
Expand All @@ -529,4 +529,6 @@
get '/resource/:doi_prefix/:doi_suffix*file',
constraints: { doi_prefix: /doi:10.\d{4,9}/i, doi_suffix: /[A-Z0-9]+\.[A-Z0-9]+/i },
to: redirect{ |p, req| "stash/dataset/#{p[:doi_prefix]}/#{p[:doi_suffix]}" }

get :health_check, to: 'health#check'
end

0 comments on commit af811ef

Please sign in to comment.