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 cffc996
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ 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'
gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/add-queries-logging-'


group :development do
Expand Down
22 changes: 11 additions & 11 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: 04381bb9bc4a98a954eb61460a0f3349486b3f21
revision: e1a64a77ba07e5d6662caa599a959758530bda23
branch: development
specs:
ncbo_cron (0.0.1)
Expand Down Expand Up @@ -57,8 +57,8 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: e65d887616aaf4ae6f099437223d86515ffdca79
branch: development
revision: 32c1aed4221e1b5f50a7931137092ee4ba62ca94
branch: feature/add-queries-logging-
specs:
ontologies_linked_data (0.0.1)
activesupport
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 @@ -132,7 +132,7 @@ GEM
capistrano (~> 3.1)
sshkit (~> 1.3)
coderay (1.1.3)
concurrent-ruby (1.3.4)
concurrent-ruby (1.3.5)
connection_pool (2.5.0)
crack (0.4.5)
rexml
Expand Down Expand Up @@ -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.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 +209,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 @@ -271,7 +271,7 @@ GEM
ostruct (0.6.1)
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 @@ -318,7 +318,7 @@ GEM
redcarpet (3.6.0)
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 cffc996

Please sign in to comment.