-
Notifications
You must be signed in to change notification settings - Fork 531
Add optional logging of requests for non-existent/non-public PIDs #11601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ecebf5a
7c19d20
aae8439
bcd15a4
4aa12ca
155c06b
8eb4f62
bbd67c9
f4f55ff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| This version of Dataverse includes a new feature flag - ``dataverse.feature.enable-pid-failure-log``. When set, Dataverse will log requests for dataset and file pages via persistentId that fail in monthly log files of the form PIDFailures_<yyyy-MM>.log. These potentially indicate when someone has shared a draft PID without publishing or cases where a '.' or other character has been added to the PID, which may be of interest to site administrators. | ||
|
|
||
| The new log files can be used in concert with the pidreport.py script at https://github.com/gdcc/dataverse-recipes/tree/main/python/pid_reports to generate and email monthly PID failure reports. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| /* | ||
| * To change this license header, choose License Headers in Project Properties. | ||
| * To change this template file, choose Tools | Templates | ||
| * and open the template in the editor. | ||
| */ | ||
| package edu.harvard.iq.dataverse.pidproviders; | ||
|
|
||
| import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress; | ||
| import edu.harvard.iq.dataverse.batch.util.LoggingUtil; | ||
| import java.io.UnsupportedEncodingException; | ||
| import java.net.URLEncoder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.sql.Timestamp; | ||
| import java.text.SimpleDateFormat; | ||
| import java.util.Date; | ||
| import jakarta.enterprise.context.RequestScoped; | ||
| import jakarta.inject.Named; | ||
|
|
||
| /** | ||
| * | ||
| * @author qqmyers | ||
| */ | ||
|
|
||
| @Named | ||
| @RequestScoped | ||
| public class FailedPIDResolutionLoggingServiceBean { | ||
|
|
||
| public static final String LOG_HEADER = "#Fields: pid\trequestURI\tHTTP method\tclient_ip\teventTime\n"; | ||
|
|
||
|
|
||
| public void logEntry(FailedPIDResolutionEntry entry) { | ||
| LoggingUtil.saveLogFileAppendWithHeader(entry.toString(), "../logs", getLogFileName(), LOG_HEADER); | ||
| } | ||
|
|
||
| public String getLogFileName() { | ||
| return "PIDFailures_" + new SimpleDateFormat("yyyy-MM").format(new Timestamp(new Date().getTime())) + ".log"; | ||
| } | ||
|
|
||
| public static class FailedPIDResolutionEntry { | ||
|
|
||
| private String eventTime; | ||
| private String clientIp; | ||
| private String requestUrl; | ||
| private String identifier; | ||
| private String method; | ||
|
|
||
| public FailedPIDResolutionEntry() { | ||
|
|
||
| } | ||
|
|
||
| public FailedPIDResolutionEntry(String persistentId, String requestURI, String method, IpAddress sourceAddress) { | ||
| try { | ||
| setIdentifier(URLEncoder.encode(persistentId, StandardCharsets.UTF_8.toString())); | ||
| } catch (UnsupportedEncodingException e) { | ||
| // Should never happen | ||
| e.printStackTrace(); | ||
| } | ||
| setRequestUrl(requestURI); | ||
| setMethod(method); | ||
| setClientIp(sourceAddress.toString()); | ||
| setEventTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Timestamp(new Date().getTime()))); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return getIdentifier() + "\t" + | ||
| getRequestUrl() + "\t" + | ||
| getMethod() + "\t" + | ||
| getClientIp() + "\t" + | ||
| getEventTime() + "\n"; | ||
| } | ||
|
|
||
| /** | ||
| * @return the eventTime | ||
| */ | ||
| public String getEventTime() { | ||
| if (eventTime == null) { | ||
| return "-"; | ||
| } | ||
| return eventTime; | ||
| } | ||
|
|
||
| /** | ||
| * @param eventTime | ||
| * the eventTime to set | ||
| */ | ||
| public final void setEventTime(String eventTime) { | ||
| this.eventTime = eventTime; | ||
| } | ||
|
|
||
| /** | ||
| * @return the clientIp | ||
| */ | ||
| public String getClientIp() { | ||
| if (clientIp == null) { | ||
| return "-"; | ||
| } | ||
| return clientIp; | ||
| } | ||
|
|
||
| /** | ||
| * @param clientIp | ||
| * the clientIp to set | ||
| */ | ||
| public final void setClientIp(String clientIp) { | ||
| this.clientIp = clientIp; | ||
| } | ||
|
|
||
| /** | ||
| * @return the HTTP Method | ||
| */ | ||
| public String getMethod() { | ||
| return method; | ||
| } | ||
|
|
||
| /** | ||
| * @param method | ||
| * - the HTTP Method used | ||
| */ | ||
| public final void setMethod(String method) { | ||
| this.method = method; | ||
| } | ||
|
|
||
| /** | ||
| * @return the requestUrl | ||
| */ | ||
| public String getRequestUrl() { | ||
| if (requestUrl == null) { | ||
| return "-"; | ||
| } | ||
| return requestUrl; | ||
| } | ||
|
|
||
| /** | ||
| * @param requestUrl | ||
| * the requestUrl to set | ||
| */ | ||
| public final void setRequestUrl(String requestUrl) { | ||
| this.requestUrl = requestUrl; | ||
| } | ||
|
|
||
| /** | ||
| * @return the identifier | ||
| */ | ||
| public String getIdentifier() { | ||
| if (identifier == null) { | ||
| return "-"; | ||
| } | ||
| return identifier; | ||
| } | ||
|
|
||
| /** | ||
| * @param identifier | ||
| * the identifier to set | ||
| */ | ||
| public final void setIdentifier(String identifier) { | ||
| this.identifier = identifier; | ||
| } | ||
|
|
||
| } | ||
| } |
pdurbin marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,6 +218,18 @@ public enum FeatureFlags { | |
| * @since Dataverse 6.5 | ||
| */ | ||
| ADD_LOCAL_CONTEXTS_PERMISSION_CHECK("add-local-contexts-permission-check"), | ||
|
|
||
| /** | ||
| * This flag turns on creation of a monthly log file that tracks when requests for | ||
| * datasets/files with PIDs fail due to the PIDs not existing. This helps in catching | ||
| * cases where the DOI of a draft dataset has been cited, etc. | ||
| * | ||
| * @apiNote Raise flag by setting | ||
| * "dataverse.feature.enable-pid-failure-log" | ||
| * @since Dataverse 6.8 | ||
| */ | ||
| ENABLE_PID_FAILURE_LOG("enable-pid-failure-log"), | ||
|
|
||
| ; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just adding this at the end... https://jenkins.dataverse.org/job/IQSS-Dataverse-Develop-PR/job/PR-11601/3/testReport/junit/edu.harvard.iq.dataverse.api/DataverseFeaturedItemsIT/testCreateFeaturedItemWithBadDvOdbjectIds/ is failing with a 500 error. Can you please merge the latest from develop and see if tests pass? |
||
| final String flag; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.