Skip to content

Commit

Permalink
Merge branch 'feature/add-query-logs-endpoints' into test
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 20, 2025
2 parents 57df3b9 + ea27c62 commit 2ffdc47
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
18 changes: 14 additions & 4 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,6 +29,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ncbo_cron.git
branch: master
revision: 04381bb9bc4a98a954eb61460a0f3349486b3f21
branch: development
specs:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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 2ffdc47

Please sign in to comment.