Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  Set version to 2.16.16-SNAPSHOT
  Set version to 2.16.15
  Revert "Revert "Fix handling of interactive/batch users in the QoS filter""
  Separate request context filter from cleanup
  Assert RequestCleanup ran only once
  Test Git/HTTP Servlet when SSH is enabled
  Fix linter errors under eslint 6.x
  Add example command for how to display note of an external ID
  Add example command for how to find SHA1 of an external ID
  Link global eslint packages to local project
  Revert "Fix handling of interactive/batch users in the QoS filter"
  Log also thread name in the sshd_log
  Log also thread name in the httpd_log

Change-Id: I4618f563b27581d109d03d98e0f4e32a18c2a1bb
This commit is contained in:
David Pursehouse
2019-12-14 12:45:22 +09:00
17 changed files with 285 additions and 28 deletions

View File

@@ -0,0 +1,65 @@
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.httpd;
import com.google.gerrit.server.RequestCleanup;
import com.google.inject.Inject;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import com.google.inject.servlet.ServletModule;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/** Executes any pending {@link RequestCleanup} at the end of a request. */
@Singleton
public class RequestCleanupFilter implements Filter {
public static Module module() {
return new ServletModule() {
@Override
protected void configureServlets() {
filter("/*").through(RequestCleanupFilter.class);
}
};
}
private final Provider<RequestCleanup> cleanup;
@Inject
RequestCleanupFilter(Provider<RequestCleanup> r) {
cleanup = r;
}
@Override
public void init(FilterConfig filterConfig) {}
@Override
public void destroy() {}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
try {
chain.doFilter(request, response);
} finally {
cleanup.get().run();
}
}
}

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.httpd;
import com.google.gerrit.server.RequestCleanup;
import com.google.gerrit.server.util.RequestContext;
import com.google.gerrit.server.util.ThreadLocalRequestContext;
import com.google.inject.Inject;
@@ -30,7 +29,7 @@ import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/** Executes any pending {@link RequestCleanup} at the end of a request. */
/** Set the request context for the downstream filters and invocation. */
@Singleton
public class RequestContextFilter implements Filter {
public static Module module() {
@@ -42,14 +41,11 @@ public class RequestContextFilter implements Filter {
};
}
private final Provider<RequestCleanup> cleanup;
private final Provider<HttpRequestContext> requestContext;
private final ThreadLocalRequestContext local;
@Inject
RequestContextFilter(
Provider<RequestCleanup> r, Provider<HttpRequestContext> c, ThreadLocalRequestContext l) {
cleanup = r;
RequestContextFilter(Provider<HttpRequestContext> c, ThreadLocalRequestContext l) {
requestContext = c;
local = l;
}
@@ -65,11 +61,7 @@ public class RequestContextFilter implements Filter {
throws IOException, ServletException {
RequestContext old = local.setContext(requestContext.get());
try {
try {
chain.doFilter(request, response);
} finally {
cleanup.get().run();
}
chain.doFilter(request, response);
} finally {
local.setContext(old);
}

View File

@@ -27,6 +27,7 @@ import com.google.gerrit.httpd.GetUserFilter;
import com.google.gerrit.httpd.GitOverHttpModule;
import com.google.gerrit.httpd.H2CacheBasedWebSession;
import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider;
import com.google.gerrit.httpd.RequestCleanupFilter;
import com.google.gerrit.httpd.RequestContextFilter;
import com.google.gerrit.httpd.RequestMetricsFilter;
import com.google.gerrit.httpd.RequireSslFilter;
@@ -373,6 +374,7 @@ public class WebAppInitializer extends GuiceServletContextListener implements Fi
modules.add(RequestMetricsFilter.module());
modules.add(sysInjector.getInstance(GerritAuthModule.class));
modules.add(sysInjector.getInstance(GitOverHttpModule.class));
modules.add(RequestCleanupFilter.module());
modules.add(AllRequestFilter.module());
modules.add(sysInjector.getInstance(WebModule.class));
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));

View File

@@ -31,6 +31,7 @@ import com.google.gerrit.httpd.GetUserFilter;
import com.google.gerrit.httpd.GitOverHttpModule;
import com.google.gerrit.httpd.H2CacheBasedWebSession;
import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider;
import com.google.gerrit.httpd.RequestCleanupFilter;
import com.google.gerrit.httpd.RequestContextFilter;
import com.google.gerrit.httpd.RequestMetricsFilter;
import com.google.gerrit.httpd.RequireSslFilter;
@@ -552,6 +553,7 @@ public class Daemon extends SiteProgram {
if (sshd) {
modules.add(new ProjectQoSFilter.Module());
}
modules.add(RequestCleanupFilter.module());
modules.add(AllRequestFilter.module());
modules.add(sysInjector.getInstance(WebModule.class));
modules.add(sysInjector.getInstance(RequireSslFilter.Module.class));

View File

@@ -73,7 +73,7 @@ class HttpLog extends AbstractLifeCycle implements RequestLog {
TimeUtil.nowMs(), // when
Level.INFO, // level
"", // message text
"HTTPD", // thread name
Thread.currentThread().getName(), // thread name
null, // exception information
null, // current NDC string
null, // caller location

View File

@@ -40,6 +40,11 @@ public final class HttpLogLayout extends Layout {
opt(buf, event, HttpLog.P_HOST);
buf.append(' ');
buf.append('[');
buf.append(event.getThreadName());
buf.append(']');
buf.append(' ');
buf.append('-'); // identd on client system (never requested)

View File

@@ -31,9 +31,7 @@ public class RequestCleanup implements Runnable {
/** Register a task to be completed after the request ends. */
public void add(Runnable task) {
synchronized (cleanup) {
if (ran) {
throw new IllegalStateException("Request has already been cleaned up");
}
assertNotRan();
cleanup.add(task);
}
}
@@ -41,6 +39,7 @@ public class RequestCleanup implements Runnable {
@Override
public void run() {
synchronized (cleanup) {
assertNotRan();
ran = true;
for (Iterator<Runnable> i = cleanup.iterator(); i.hasNext(); ) {
try {
@@ -52,4 +51,10 @@ public class RequestCleanup implements Runnable {
}
}
}
private void assertNotRan() {
if (ran) {
throw new IllegalStateException("Request has already been cleaned up");
}
}
}

View File

@@ -250,7 +250,7 @@ class SshLog implements LifecycleListener, GerritConfigListener {
TimeUtil.nowMs(), // when
Level.INFO, // level
msg, // message text
"SSHD", // thread name
Thread.currentThread().getName(), // thread name
null, // exception information
null, // current NDC string
null, // caller location

View File

@@ -54,6 +54,12 @@ public final class SshLogLayout extends Layout {
buf.append(']');
req(P_SESSION, buf, event);
buf.append(' ');
buf.append('[');
buf.append(event.getThreadName());
buf.append(']');
req(P_USER_NAME, buf, event);
req(P_ACCOUNT_ID, buf, event);