Skip to content
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

allow searching of deleted request logs #1212

Merged
merged 4 commits into from Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -271,11 +271,22 @@ private void checkS3() {
checkNotFound(configuration.isPresent(), "S3 configuration was absent");
}

private SingularityRequestWithState getRequest(final String requestId) {
private Optional<String> getRequestGroup(final String requestId) {
final Optional<SingularityRequestWithState> maybeRequest = requestManager.getRequest(requestId);
checkNotFound(maybeRequest.isPresent(), "RequestId %s does not exist", requestId);
authorizationHelper.checkForAuthorization(maybeRequest.get().getRequest(), user, SingularityAuthorizationScope.READ);
return maybeRequest.get();
if (maybeRequest.isPresent()) {
authorizationHelper.checkForAuthorization(maybeRequest.get().getRequest(), user, SingularityAuthorizationScope.READ);
return maybeRequest.get().getRequest().getGroup();
} else {
Optional<SingularityRequestHistory> maybeRequestHistory = requestHistoryHelper.getLastHistory(requestId);
if (maybeRequestHistory.isPresent()) {
authorizationHelper.checkForAuthorization(maybeRequestHistory.get().getRequest(), user, SingularityAuthorizationScope.READ);
return maybeRequestHistory.get().getRequest().getGroup();
} else {
// Deleted requests with no history data are searchable, but only by admins since we have no auth information about them
authorizationHelper.checkAdminAuthorization(user);
return Optional.absent();
}
}
}

@GET
Expand All @@ -290,7 +301,7 @@ public List<SingularityS3Log> getS3LogsForTask(
SingularityTaskId taskIdObject = getTaskIdObject(taskId);

try {
return getS3Logs(configuration.get(), getRequest(taskIdObject.getRequestId()).getRequest().getGroup(), getS3PrefixesForTask(configuration.get(), taskIdObject, start, end));
return getS3Logs(configuration.get(), getRequestGroup(taskIdObject.getRequestId()), getS3PrefixesForTask(configuration.get(), taskIdObject, start, end));
} catch (TimeoutException te) {
throw timeout("Timed out waiting for response from S3 for %s", taskId);
} catch (Throwable t) {
Expand All @@ -308,7 +319,7 @@ public List<SingularityS3Log> getS3LogsForRequest(
checkS3();

try {
return getS3Logs(configuration.get(), getRequest(requestId).getRequest().getGroup(), getS3PrefixesForRequest(configuration.get(), requestId, start, end));
return getS3Logs(configuration.get(), getRequestGroup(requestId), getS3PrefixesForRequest(configuration.get(), requestId, start, end));
} catch (TimeoutException te) {
throw timeout("Timed out waiting for response from S3 for %s", requestId);
} catch (Throwable t) {
Expand All @@ -327,7 +338,7 @@ public List<SingularityS3Log> getS3LogsForDeploy(
checkS3();

try {
return getS3Logs(configuration.get(), getRequest(requestId).getRequest().getGroup(), getS3PrefixesForDeploy(configuration.get(), requestId, deployId, start, end));
return getS3Logs(configuration.get(), getRequestGroup(requestId), getS3PrefixesForDeploy(configuration.get(), requestId, deployId, start, end));
} catch (TimeoutException te) {
throw timeout("Timed out waiting for response from S3 for %s-%s", requestId, deployId);
} catch (Throwable t) {
Expand Down
4 changes: 4 additions & 0 deletions scripts/logfetch/grep.py
@@ -1,6 +1,10 @@
import sys
import subprocess
<<<<<<< HEAD
from logfetch_base import log, get_timestamp
=======
from logfetch_base import log, get_timestamp_string
>>>>>>> master
from termcolor import colored

DEFAULT_GREP_COMMAND = 'grep --color=always \'{0}\''
Expand Down
7 changes: 7 additions & 0 deletions scripts/logfetch/logfetch_base.py
Expand Up @@ -92,6 +92,13 @@ def get_timestamp_string(filename):
else:
return ""

def get_timestamp(filename):
timestamps = re.findall(r"-\d{13}-", filename)
if timestamps:
return datetime.utcfromtimestamp(int(str(timestamps[-1]).replace("-", "")[0:-3]))
else:
return ""

def update_progress_bar(progress, goal, progress_type, silent):
bar_length = 30
percent = float(progress) / goal
Expand Down