Merge pull request #6849 from overleaf/msm-git-bridge-log-level

[git-bridge] review logging levels

GitOrigin-RevId: beb6ce89ccdee7c60c4439d7a5252d7858956a9a
This commit is contained in:
Miguel Serrano 2022-03-01 15:20:03 +01:00 committed by Copybot
parent 9702346edc
commit fe35372d27
29 changed files with 68 additions and 68 deletions

View file

@ -270,7 +270,7 @@ public class Bridge {
if (!rootDirectory.exists()) {
throw new Exception("bad filesystem state, root directory does not exist");
}
Log.info("[HealthCheck] passed");
Log.debug("[HealthCheck] passed");
return true;
} catch (Exception e) {
Log.error("[HealthCheck] FAILED!", e);
@ -332,7 +332,7 @@ public class Bridge {
throw new RepositoryNotFoundException(projectName);
}
GetDocResult doc = maybeDoc.get();
Log.info("[{}] Updating repository", projectName);
Log.debug("[{}] Updating repository", projectName);
return getUpdatedRepoCritical(oauth2, projectName, doc);
}
}
@ -539,13 +539,13 @@ public class Bridge {
if (maxFileNum.isPresent()) {
long maxFileNum_ = maxFileNum.get();
if (directoryContents.getFileTable().size() > maxFileNum_) {
Log.debug("[{}] Too many files: {}/{}", projectName, directoryContents.getFileTable().size(), maxFileNum_);
Log.warn("[{}] Too many files: {}/{}", projectName, directoryContents.getFileTable().size(), maxFileNum_);
throw new FileLimitExceededException(directoryContents.getFileTable().size(), maxFileNum_);
}
}
Log.info("[{}] Pushing files ({} new, {} old)", projectName, directoryContents.getFileTable().size(), oldDirectoryContents.getFileTable().size());
Log.debug("[{}] Pushing files ({} new, {} old)", projectName, directoryContents.getFileTable().size(), oldDirectoryContents.getFileTable().size());
String postbackKey = postbackManager.makeKeyForProject(projectName);
Log.info(
Log.debug(
"[{}] Created postback key: {}",
projectName,
postbackKey
@ -557,7 +557,7 @@ public class Bridge {
oldDirectoryContents
);
) {
Log.info(
Log.debug(
"[{}] Candidate snapshot created: {}",
projectName,
candidate
@ -565,20 +565,20 @@ public class Bridge {
PushResult result
= snapshotAPI.push(oauth2, candidate, postbackKey);
if (result.wasSuccessful()) {
Log.info(
Log.debug(
"[{}] Push to Overleaf successful",
projectName
);
Log.info("[{}] Waiting for postback...", projectName);
Log.debug("[{}] Waiting for postback...", projectName);
int versionID =
postbackManager.waitForVersionIdOrThrow(projectName);
Log.info(
Log.debug(
"[{}] Got version ID for push: {}",
projectName,
versionID
);
approveSnapshot(versionID, candidate);
Log.info(
Log.debug(
"[{}] Approved version ID: {}",
projectName,
versionID
@ -636,7 +636,7 @@ public class Bridge {
String postbackKey,
int versionID
) throws UnexpectedPostbackException {
Log.info(
Log.debug(
"[{}]" +
" Postback received by postback thread, version: {}",
projectName,
@ -762,7 +762,7 @@ public class Bridge {
)
);
}
Log.info(
Log.debug(
"[{}] Committing version ID: {}",
name,
snapshot.getVersionID()

View file

@ -117,14 +117,14 @@ public class GcJobImpl implements GcJob {
it.remove(), ++numGcs
) {
String proj = it.next();
Log.info("[{}] Running GC job on project", proj);
Log.debug("[{}] Running GC job on project", proj);
try (LockGuard __ = locks.lockGuard(proj)) {
try {
ProjectRepo repo = repoStore.getExistingRepo(proj);
repo.runGC();
repo.deleteIncomingPacks();
} catch (IOException e) {
Log.info("[{}] Failed to GC project", proj);
Log.warn("[{}] Failed to GC project", proj);
}
}
}

View file

@ -82,7 +82,7 @@ public class FSGitRepoStore implements RepoStore {
String repoRoot = getRepoStorePath();
String sourcePath = repoRoot + "/" + fromProject;
String destinationPath = repoRoot + "/" + project;
Log.info("[{}] Init repo by copying data from: {}, to: {}",
Log.debug("[{}] Init repo by copying data from: {}, to: {}",
project,
sourcePath,
destinationPath
@ -136,7 +136,7 @@ public class FSGitRepoStore implements RepoStore {
long[] sizePtr
) throws IOException {
Project.checkValidProjectName(projectName);
Log.info("[{}] bzip2 project", projectName);
Log.debug("[{}] bzip2 project", projectName);
return Tar.bz2.zip(getDotGitForProject(projectName), sizePtr);
}
@ -146,7 +146,7 @@ public class FSGitRepoStore implements RepoStore {
long[] sizePtr
) throws IOException {
Project.checkValidProjectName(projectName);
Log.info("[{}] gzip project", projectName);
Log.debug("[{}] gzip project", projectName);
return Tar.gzip.zip(getDotGitForProject(projectName), sizePtr);
}
@ -179,7 +179,7 @@ public class FSGitRepoStore implements RepoStore {
"evicted project already exist",
projectName
);
Log.info("[{}] un-bzip2 project", projectName);
Log.debug("[{}] un-bzip2 project", projectName);
Tar.bz2.unzip(dataStream, getDirForProject(projectName));
}
@ -199,7 +199,7 @@ public class FSGitRepoStore implements RepoStore {
"evicted project already exist",
projectName
);
Log.info("[{}] un-gzip project", projectName);
Log.debug("[{}] un-gzip project", projectName);
Tar.gzip.unzip(dataStream, getDirForProject(projectName));
}

View file

@ -116,14 +116,14 @@ public class GitProjectRepo implements ProjectRepo {
);
File dir = getProjectDir();
Preconditions.checkState(dir.isDirectory());
Log.info("[{}] Running git gc", projectName);
Log.debug("[{}] Running git gc", projectName);
Process proc = new ProcessBuilder(
"git", "gc"
).directory(dir).start();
int exitCode;
try {
exitCode = proc.waitFor();
Log.info("Exit: {}", exitCode);
Log.debug("Exit: {}", exitCode);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
@ -139,12 +139,12 @@ public class GitProjectRepo implements ProjectRepo {
));
throw new IOException("git gc error");
}
Log.info("[{}] git gc successful", projectName);
Log.debug("[{}] git gc successful", projectName);
}
@Override
public void deleteIncomingPacks() throws IOException {
Log.info(
Log.debug(
"[{}] Checking for garbage `incoming` files",
projectName
);
@ -165,7 +165,7 @@ public class GitProjectRepo implements ProjectRepo {
File file_ = file.toFile();
String name = file_.getName();
if (name.startsWith("incoming_") && name.endsWith(".pack")) {
Log.info("Deleting garbage `incoming` file: {}", file_);
Log.debug("Deleting garbage `incoming` file: {}", file_);
Preconditions.checkState(file_.delete());
}
return FileVisitResult.CONTINUE;
@ -242,21 +242,21 @@ public class GitProjectRepo implements ProjectRepo {
Repository repo = getJGitRepository();
resetHard();
String name = getProjectName();
Log.info("[{}] Writing commit", name);
Log.debug("[{}] Writing commit", name);
contents.write();
Git git = new Git(getJGitRepository());
Log.info("[{}] Getting missing files", name);
Log.debug("[{}] Getting missing files", name);
Set<String> missingFiles = git.status().call().getMissing();
for (String missing : missingFiles) {
Log.info("[{}] Git rm {}", name, missing);
Log.debug("[{}] Git rm {}", name, missing);
git.rm().setCached(true).addFilepattern(missing).call();
}
Log.info("[{}] Calling Git add", name);
Log.debug("[{}] Calling Git add", name);
git.add(
).setWorkingTreeIterator(
new NoGitignoreIterator(repo)
).addFilepattern(".").call();
Log.info("[{}] Calling Git commit", name);
Log.debug("[{}] Calling Git commit", name);
git.commit(
).setAuthor(
new PersonIdent(
@ -268,7 +268,7 @@ public class GitProjectRepo implements ProjectRepo {
).setMessage(
contents.getCommitMessage()
).call();
Log.info(
Log.debug(
"[{}] Deleting files in directory: {}",
name,
contents.getDirectory().getAbsolutePath()

View file

@ -50,8 +50,8 @@ public class UrlResourceCache implements ResourceCache {
contents = fetch(projectName, url, path, maxFileSize);
fetchedUrls.put(url, contents);
} else {
Log.info("Found (" + projectName + "): " + url);
Log.info("At (" + projectName + "): " + path);
Log.debug("Found (" + projectName + "): " + url);
Log.debug("At (" + projectName + "): " + path);
contents = fetchedUrls.get(url);
if (contents == null) {
RawFile rawFile = fileTable.get(path);
@ -79,7 +79,7 @@ public class UrlResourceCache implements ResourceCache {
Optional<Long> maxFileSize
) throws FailedConnectionException, SizeLimitExceededException {
byte[] contents;
Log.info("GET -> " + url);
Log.debug("GET -> " + url);
try {
contents = http.get(url, hs -> {
List<String> contentLengths = hs.getAll("Content-Length");

View file

@ -112,11 +112,11 @@ public class SwapJobImpl implements SwapJob {
private void doSwap_() {
ArrayList<String> exceptionProjectNames = new ArrayList<String>();
Log.info("Running swap number {}", swaps.get() + 1);
Log.debug("Running swap number {}", swaps.get() + 1);
long totalSize = repoStore.totalSize();
Log.info("Size is {}/{} (high)", totalSize, highWatermarkBytes);
Log.debug("Size is {}/{} (high)", totalSize, highWatermarkBytes);
if (totalSize < highWatermarkBytes) {
Log.info("No need to swap.");
Log.debug("No need to swap.");
swaps.incrementAndGet();
return;
}
@ -162,7 +162,7 @@ public class SwapJobImpl implements SwapJob {
"Finished swapping, but total size is still too high."
);
}
Log.info(
Log.debug(
"Size: {}/{} (low), " +
"{} (high), " +
"projects on disk: {}/{}, " +

View file

@ -30,7 +30,7 @@ public abstract class RawFile {
OutputStream out = new FileOutputStream(file);
out.write(getContents());
out.close();
Log.info("Wrote file: {}", file.getAbsolutePath());
Log.debug("Wrote file: {}", file.getAbsolutePath());
}
@Override

View file

@ -60,7 +60,7 @@ public class WLReceivePackFactory
HttpServletRequest httpServletRequest,
Repository repository
) {
Log.info(
Log.debug(
"[{}] Creating receive-pack",
repository.getWorkTree().getName()
);

View file

@ -82,7 +82,7 @@ public class WLRepositoryResolver
) throws RepositoryNotFoundException,
ServiceNotAuthorizedException,
ServiceMayNotContinueException {
Log.info("[{}] Request to open git repo", name);
Log.debug("[{}] Request to open git repo", name);
Optional<Credential> oauth2 = Optional.ofNullable(
(Credential) httpServletRequest.getAttribute(
Oauth2Filter.ATTRIBUTE_KEY));
@ -90,7 +90,7 @@ public class WLRepositoryResolver
try {
return bridge.getUpdatedRepo(oauth2, projName).getJGitRepository();
} catch (RepositoryNotFoundException e) {
Log.info("Repository not found: " + name);
Log.warn("Repository not found: " + name);
throw e;
/*
} catch (ServiceNotAuthorizedException e) {

View file

@ -34,7 +34,7 @@ public class WLUploadPackFactory
HttpServletRequest __,
Repository repository
) {
Log.info(
Log.debug(
"[{}] Creating upload-pack",
repository.getWorkTree().getName()
);

View file

@ -60,7 +60,7 @@ public class NingHttpClient implements NingHttpClientFacade {
}
byte[] ret = bytes.toByteArray();
bytes.close();
log.info(
log.debug(
statusCode
+ " "
+ response.getStatusText()

View file

@ -37,7 +37,7 @@ public class DiagnosticsHandler extends AbstractHandler {
) {
baseRequest.setHandled(true);
Log.info(method + " <- /diags");
Log.debug(method + " <- /diags");
String detail;
String summary;
@ -50,7 +50,7 @@ public class DiagnosticsHandler extends AbstractHandler {
response.setStatus(500);
return;
}
response.setContentType("text/plain");
response.setStatus(200);

View file

@ -38,7 +38,7 @@ public class FileHandler extends ResourceHandler {
HttpServletResponse response
) throws IOException, ServletException {
if (!"GET".equals(baseRequest.getMethod())) return;
LOG.info("GET <- {}", baseRequest.getRequestURI());
LOG.debug("GET <- {}", baseRequest.getRequestURI());
Matcher docKeyMatcher = DOC_KEY_PATTERN.matcher(target);
if (!docKeyMatcher.matches()) return;

View file

@ -35,7 +35,7 @@ public class GitLfsHandler extends AbstractHandler {
&& target != null
&& target.matches("^/[0-9a-z]+\\.git/info/lfs/objects/batch/?$")
) {
Log.info(method + " <- /<project>.git/info/lfs/objects/batch");
Log.debug(method + " <- /<project>.git/info/lfs/objects/batch");
response.setContentType("application/vnd.git-lfs+json");
response.setStatus(422);
response.getWriter().println("{\"message\": \"ERROR: Git LFS is not supported on Overleaf\"}");

View file

@ -34,7 +34,7 @@ public class HealthCheckHandler extends AbstractHandler {
&& target != null
&& target.matches("^/health_check/?$")
) {
Log.info(method + " <- /health_check");
Log.debug(method + " <- /health_check");
baseRequest.setHandled(true);
response.setContentType("text/plain");
if (bridge.healthCheck()) {

View file

@ -97,14 +97,14 @@ public class Oauth2Filter implements Filter {
));
return;
}
Log.info("[{}] Checking if auth needed", project);
Log.debug("[{}] Checking if auth needed", project);
GetDocRequest doc = new GetDocRequest(project);
doc.request();
try {
SnapshotApi.getResult(
snapshotApi.getDoc(Optional.empty(), project));
} catch (ForbiddenException e) {
Log.info("[{}] Auth needed", project);
Log.debug("[{}] Auth needed", project);
getAndInjectCredentials(
project,
servletRequest,
@ -115,7 +115,7 @@ public class Oauth2Filter implements Filter {
} catch (MissingRepositoryException e) {
handleMissingRepository(project, e, (HttpServletResponse) servletResponse);
}
Log.info("[{}] Auth not needed", project);
Log.debug("[{}] Auth not needed", project);
filterChain.doFilter(servletRequest, servletResponse);
}
@ -137,7 +137,7 @@ public class Oauth2Filter implements Filter {
if (clientIp == null) {
clientIp = request.getRemoteAddr();
}
Log.info("[{}] Authorization header present", clientIp);
Log.debug("[{}] Authorization header present", clientIp);
StringTokenizer st = new StringTokenizer(authHeader);
if (st.hasMoreTokens()) {
String basic = st.nextToken();

View file

@ -32,7 +32,7 @@ public class PostbackHandler extends AbstractHandler {
HttpServletRequest request,
HttpServletResponse response
) throws IOException, ServletException {
Log.info(
Log.debug(
"PostbackHandler: " + baseRequest.getMethod()
+ " <- "
+ baseRequest.getHttpURI()

View file

@ -43,7 +43,7 @@ public class PrometheusHandler extends AbstractHandler {
&& target != null
&& target.matches("^/metrics/?$")
) {
Log.info(method + " <- /metrics");
Log.debug(method + " <- /metrics");
this.printMetrics(request, response);
baseRequest.setHandled(true);
}

View file

@ -35,7 +35,7 @@ public class StatusHandler extends AbstractHandler {
&& target != null
&& target.matches("^/status/?$")
) {
Log.info(method + " <- /status");
Log.debug(method + " <- /status");
baseRequest.setHandled(true);
response.setContentType("text/plain");
response.setStatus(200);

View file

@ -56,7 +56,7 @@ public abstract class Request<T extends Result> {
private T getResult() throws MissingRepositoryException, FailedConnectionException, ForbiddenException {
try {
HttpResponse response = future.get();
Log.info(
Log.debug(
"{} {} ({}B) -> " + url,
response.getStatusCode(),
response.getStatusMessage(),
@ -140,7 +140,7 @@ public abstract class Request<T extends Result> {
throw new FailedConnectionException(cause);
}
} catch (IOException e) {
Log.error("Failed to parse JSON.", e);
Log.warn("Failed to parse JSON.", e);
throw new FailedConnectionException();
}
}
@ -159,7 +159,7 @@ public abstract class Request<T extends Result> {
}
private void performGetRequest() {
Log.info("GET -> " + url);
Log.debug("GET -> " + url);
try {
HttpRequest request = Instance.httpRequestFactory.buildGetRequest(
new GenericUrl(url)
@ -173,7 +173,7 @@ public abstract class Request<T extends Result> {
}
private void performPostRequest() {
Log.info("POST -> " + url);
Log.debug("POST -> " + url);
try {
HttpRequest request = Instance.httpRequestFactory.buildPostRequest(
new GenericUrl(url),

View file

@ -19,7 +19,7 @@ public class GetDocRequest extends SnapshotAPIRequest<GetDocResult> {
public GetDocRequest(Credential oauth2, String projectName) {
super(projectName, API_CALL, oauth2);
Log.info(
Log.debug(
"GetDocRequest({}, {})",
"oauth2: <oauth2>",
"projectName: " + projectName

View file

@ -80,7 +80,7 @@ public class GetDocResult extends Result {
@Override
public void fromJSON(JsonElement json) {
Log.info("GetDocResult: " + json);
Log.debug("GetDocResult: " + json);
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("status")) {
switch (jsonObject.get("status").getAsInt()) {

View file

@ -24,7 +24,7 @@ public class GetForVersionRequest
) {
super(projectName, API_CALL + "/" + versionID, oauth2);
this.versionID = versionID;
Log.info(
Log.debug(
"GetForVersionRequest({}, {}, {})",
"oauth2: <oauth2>",
"projectName: " + projectName,

View file

@ -28,7 +28,7 @@ public class GetForVersionResult extends Result {
@Override
public void fromJSON(JsonElement json) {
snapshotData = new SnapshotData(json);
Log.info("GetForVersionResult({})", snapshotData);
Log.debug("GetForVersionResult({})", snapshotData);
}
public SnapshotData getSnapshotData() {

View file

@ -17,7 +17,7 @@ public class GetSavedVersRequest
public GetSavedVersRequest(Credential oauth2, String projectName) {
super(projectName, API_CALL, oauth2);
Log.info(
Log.debug(
"GetSavedVersRequest({}, {})",
"oauth2: <oauth2>",
"projectName: " + projectName

View file

@ -50,7 +50,7 @@ public class GetSavedVersResult extends Result {
@Override
public void fromJSON(JsonElement json) {
Log.info("GetSavedVersResult({})", json);
Log.debug("GetSavedVersResult({})", json);
savedVers = new ArrayList<>();
for (JsonElement elem : json.getAsJsonArray()) {
savedVers.add(

View file

@ -26,7 +26,7 @@ public class PushRequest extends SnapshotAPIRequest<PushResult> {
super(candidateSnapshot.getProjectName(), API_CALL, oauth2);
this.candidateSnapshot = candidateSnapshot;
this.postbackKey = postbackKey;
Log.info(
Log.debug(
"PushRequest({}, {}, {})",
"oauth2: <oauth2>",
"candidateSnapshot: " + candidateSnapshot,

View file

@ -33,7 +33,7 @@ public class PushResult extends Result {
@Override
public void fromJSON(JsonElement json) {
Log.info("PushResult({})", json);
Log.debug("PushResult({})", json);
JsonObject responseObject = json.getAsJsonObject();
String code = Util.getCodeFromResponse(responseObject);

View file

@ -119,7 +119,7 @@ public class Util {
deleteInDirectory(file);
}
file.delete();
Log.info("Deleted file: {}", file.getAbsolutePath());
Log.debug("Deleted file: {}", file.getAbsolutePath());
}
}
}