Skip to content

Commit

Permalink
add last 24 hours SPARQL queries logging
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 20, 2025
1 parent 8366d47 commit ea27c62
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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: 'master'
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'

Expand Down
88 changes: 45 additions & 43 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -29,7 +29,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ncbo_cron.git
revision: 37a9573c11978869a867050f8ec75e048c8b9b2b
revision: d50c624868dec11cb0afcc88ba422d021c77926c
branch: master
specs:
ncbo_cron (0.0.1)
Expand Down Expand Up @@ -57,7 +57,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 312ef426eeaa461e88fa23124ea5fd531f4276ba
revision: 0aa6219c44143b94135e01c78eb94ad99a5e8b32
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand All @@ -77,7 +77,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/sparql-client.git
revision: 59251e59346c9a69a67c88552ba55a1244eec602
revision: d1b90df22ce8f9fa1b87d9483f7e833a19eaa86e
branch: development
specs:
sparql-client (3.2.2)
Expand Down Expand Up @@ -117,9 +117,9 @@ GEM
base64 (0.2.0)
bcrypt (3.1.20)
bcrypt_pbkdf (1.1.1)
bigdecimal (3.1.8)
bigdecimal (3.1.9)
builder (3.3.0)
capistrano (3.19.1)
capistrano (3.19.2)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
Expand All @@ -132,13 +132,13 @@ GEM
capistrano (~> 3.1)
sshkit (~> 1.3)
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crack (0.4.5)
rexml
cube-ruby (0.0.3)
dante (0.2.0)
date (3.4.0)
date (3.4.1)
declarative (0.0.20)
docile (1.4.1)
domain_name (0.6.20240107)
Expand All @@ -164,12 +164,12 @@ GEM
google-analytics-data (0.6.1)
google-analytics-data-v1beta (>= 0.11, < 2.a)
google-cloud-core (~> 1.6)
google-analytics-data-v1beta (0.13.1)
google-analytics-data-v1beta (0.14.0)
gapic-common (>= 0.21.1, < 2.a)
google-cloud-errors (~> 1.0)
google-apis-analytics_v3 (0.16.0)
google-apis-core (>= 0.15.0, < 2.a)
google-apis-core (0.15.1)
google-apis-core (0.16.0)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.3, < 3.a)
Expand All @@ -188,7 +188,7 @@ GEM
google-protobuf (>= 3.18, < 5.a)
googleapis-common-protos-types (~> 1.7)
grpc (~> 1.41)
googleapis-common-protos-types (1.16.0)
googleapis-common-protos-types (1.18.0)
google-protobuf (>= 3.18, < 5.a)
googleauth (1.11.2)
faraday (>= 1.0, < 3.a)
Expand All @@ -203,27 +203,27 @@ GEM
haml (5.2.2)
temple (>= 0.8.0)
tilt
hashdiff (1.1.1)
hashdiff (1.1.2)
htmlentities (4.3.4)
http-accept (1.7.0)
http-cookie (1.0.7)
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.7.6)
json (2.9.1)
json-ld (3.0.2)
multi_json (~> 1.12)
rdf (>= 2.2.8, < 4.0)
json-schema (2.8.1)
addressable (>= 2.4)
jwt (2.9.3)
jwt (2.10.1)
base64
kgio (2.11.4)
language_server-protocol (3.17.0.3)
libxml-ruby (5.0.3)
link_header (0.0.8)
logger (1.6.1)
logger (1.6.5)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.8.1)
Expand All @@ -235,19 +235,19 @@ GEM
mime-types (3.6.0)
logger
mime-types-data (~> 3.2015)
mime-types-data (3.2024.1001)
mime-types-data (3.2025.0107)
mini_mime (1.1.5)
minitest (5.25.1)
minitest (5.25.4)
minitest-hooks (1.5.2)
minitest (> 5.3)
minitest-stub_any_instance (1.0.3)
mlanett-redis-lock (0.2.7)
redis
multi_json (1.15.0)
mutex_m (0.2.0)
net-http-persistent (4.0.4)
mutex_m (0.3.0)
net-http-persistent (4.0.5)
connection_pool (~> 2.2)
net-imap (0.4.17)
net-imap (0.4.18)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -262,22 +262,22 @@ GEM
net-protocol
net-ssh (7.3.0)
netrc (0.11.0)
newrelic_rpm (9.15.0)
oj (3.16.7)
newrelic_rpm (9.16.1)
oj (3.16.9)
bigdecimal (>= 3.0)
ostruct (>= 0.2)
omni_logger (0.1.4)
logger
os (1.1.4)
ostruct (0.6.0)
ostruct (0.6.1)
parallel (1.26.3)
parseconfig (1.1.2)
parser (3.3.5.1)
parser (3.3.7.0)
ast (~> 2.4.1)
racc
pony (1.13.1)
mail (>= 2.0)
pry (0.14.2)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.1.1)
Expand All @@ -295,7 +295,7 @@ GEM
rack (>= 1.2.0)
rack-protection (1.5.5)
rack
rack-test (2.1.0)
rack-test (2.2.0)
rack (>= 1.3)
rack-timeout (0.7.0)
rainbow (3.1.1)
Expand All @@ -319,14 +319,14 @@ GEM
redcarpet (3.6.0)
redis (5.3.0)
redis-client (>= 0.22.0)
redis-client (0.22.2)
redis-client (0.23.2)
connection_pool
redis-rack-cache (2.2.1)
rack-cache (>= 1.10, < 2)
redis-store (>= 1.6, < 2)
redis-store (1.11.0)
redis (>= 4, < 6)
regexp_parser (2.9.2)
regexp_parser (2.10.0)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
Expand All @@ -339,26 +339,26 @@ GEM
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retriable (3.1.2)
rexml (3.3.9)
rexml (3.4.0)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rubocop (1.68.0)
rubocop (1.70.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.34.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
ruby-xxHash (0.4.0.2)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
rubyzip (2.4.1)
rufus-scheduler (2.0.24)
tzinfo (>= 0.3.22)
signet (0.19.0)
Expand Down Expand Up @@ -397,13 +397,15 @@ GEM
systemu (2.6.5)
temple (0.10.3)
thread_safe (0.3.6)
tilt (2.4.0)
timeout (0.4.1)
tilt (2.6.0)
timeout (0.4.3)
trailblazer-option (0.1.2)
tzinfo (1.2.11)
thread_safe (~> 0.1)
uber (0.1.0)
unicode-display_width (2.6.0)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unicorn (6.1.0)
kgio (~> 2.6)
raindrops (~> 0.7)
Expand All @@ -416,7 +418,7 @@ GEM
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.9.0)
webrick (1.9.1)

PLATFORMS
x86_64-linux
Expand Down
22 changes: 22 additions & 0 deletions controllers/logging_controller.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions test/controllers/test_logging_controller.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ea27c62

Please sign in to comment.