forked from ontoportal/ontologies_api
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add last 24 hours SPARQL queries logging
- Loading branch information
1 parent
8366d47
commit ea27c62
Showing
4 changed files
with
93 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |