diff --git a/Gemfile b/Gemfile index 190c5ee1..97031021 100644 --- a/Gemfile +++ b/Gemfile @@ -50,7 +50,7 @@ gem 'redcarpet' gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.git', branch: 'development' gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'development' gem 'ncbo_ontology_recommender', git: 'https://github.com/ontoportal-lirmm/ncbo_ontology_recommender.git', branch: 'development' -gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' +gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'feature/add-triple-store-logging' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development' diff --git a/Gemfile.lock b/Gemfile.lock index eee0a755..e8036e55 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: f8ac7b00e8d8b46d1eea04de014175525c1cdd83 - branch: development + revision: 6594c7dd689d96d4085ea66deffb9528b418b74c + branch: feature/add-triple-store-logging specs: goo (0.0.2) addressable (~> 2.8) @@ -29,6 +29,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git + branch: master revision: 04381bb9bc4a98a954eb61460a0f3349486b3f21 branch: development specs: @@ -58,6 +59,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git revision: e65d887616aaf4ae6f099437223d86515ffdca79 + revision: 0aa6219c44143b94135e01c78eb94ad99a5e8b32 branch: development specs: ontologies_linked_data (0.0.1) @@ -77,7 +79,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/sparql-client.git - revision: 59251e59346c9a69a67c88552ba55a1244eec602 + revision: d1b90df22ce8f9fa1b87d9483f7e833a19eaa86e branch: development specs: sparql-client (3.2.2) @@ -134,6 +136,8 @@ GEM coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.5.0) + concurrent-ruby (1.3.5) + connection_pool (2.5.0) crack (0.4.5) rexml cube-ruby (0.0.3) @@ -170,6 +174,7 @@ GEM google-apis-analytics_v3 (0.16.0) google-apis-core (>= 0.15.0, < 2.a) google-apis-core (0.15.0) + google-apis-core (0.16.0) addressable (~> 2.5, >= 2.5.1) googleauth (~> 1.9) httpclient (>= 2.8.1, < 3.a) @@ -189,6 +194,7 @@ GEM googleapis-common-protos-types (~> 1.7) grpc (~> 1.41) googleapis-common-protos-types (1.17.0) + googleapis-common-protos-types (1.18.0) google-protobuf (>= 3.18, < 5.a) googleauth (1.11.2) faraday (>= 1.0, < 3.a) @@ -209,7 +215,7 @@ GEM http-cookie (1.0.8) domain_name (~> 0.5) httpclient (2.8.3) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) json (2.9.1) json-ld (3.0.2) @@ -244,6 +250,8 @@ GEM mlanett-redis-lock (0.2.7) redis multi_json (1.15.0) + net-http-persistent (4.0.5) + mutex_m (0.3.0) net-http-persistent (4.0.5) connection_pool (~> 2.2) net-imap (0.4.18) @@ -272,6 +280,7 @@ GEM parallel (1.26.3) parseconfig (1.1.2) parser (3.3.6.0) + parser (3.3.7.0) ast (~> 2.4.1) racc pony (1.13.1) @@ -319,6 +328,7 @@ GEM redis (5.3.0) redis-client (>= 0.22.0) redis-client (0.23.1) + redis-client (0.23.2) connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) diff --git a/controllers/logging_controller.rb b/controllers/logging_controller.rb new file mode 100644 index 00000000..81049f2b --- /dev/null +++ b/controllers/logging_controller.rb @@ -0,0 +1,22 @@ +require 'multi_json' + +module Admin + + class LoggingController < ApplicationController + + namespace "/admin" do + before { + if LinkedData.settings.enable_security && (!env["REMOTE_USER"] || !env["REMOTE_USER"].admin?) + error 403, "Access denied" + end + } + + get '/latest_query_logs' do + logs = Goo.logger.get_logs + logs = logs.map { |log| MultiJson.load(log) } + reply logs + end + + end + end +end diff --git a/test/controllers/test_logging_controller.rb b/test/controllers/test_logging_controller.rb new file mode 100644 index 00000000..e309afb8 --- /dev/null +++ b/test/controllers/test_logging_controller.rb @@ -0,0 +1,25 @@ +require_relative '../test_case' +require "multi_json" + +class TestLoggingController < TestCase + + def setup + Goo.use_cache = true + Goo.redis_client.flushdb + Goo.add_query_logger(enabled: true, file: "./queries.log") + end + def teardown + Goo.add_query_logger(enabled: false, file: nil) + File.delete("./queries.log") if File.exist?("./queries.log") + Goo.redis_client.flushdb + Goo.use_cache = false + end + + def test_logging_endpoint + LinkedData::Models::Ontology.where.include(:acronym).all + get '/admin/latest_query_logs' + assert last_response.ok? + logs = MultiJson.load(last_response.body) + assert logs + end +end