Merge "Merge branch 'stable-2.13'"

This commit is contained in:
David Pursehouse 2017-02-07 01:00:26 +00:00 committed by Gerrit Code Review
commit 6723b6d0fa
5 changed files with 47 additions and 8 deletions

View File

@ -2280,7 +2280,17 @@ Metric recording statistical distribution (rate) of values.
Note that metrics cannot be recorded from plugin init steps that
are run during site initialization.
Plugin metrics are recorded under `plugins/${plugin-name}/${metric-name}`.
By default, plugin metrics are recorded under
`plugins/${plugin-name}/${metric-name}`. This can be changed by
setting `plugins.${plugin-name}.metricsPrefix` in the `gerrit.config`
file. For example:
----
[plugin "my-plugin"]
metricsPrefix = my-metrics
----
will cause the metrics to be recorded under `my-metrics/${metric-name}`.
See the replication metrics in the
link:https://gerrit.googlesource.com/plugins/replication/+/master/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationMetrics.java[

View File

@ -17,6 +17,8 @@ package com.google.gerrit.server.plugins;
import static com.google.gerrit.server.plugins.PluginLoader.asTemp;
import com.google.common.base.MoreObjects;
import com.google.gerrit.server.config.PluginConfig;
import com.google.gerrit.server.config.PluginConfigFactory;
import com.google.gerrit.server.config.SitePaths;
import com.google.inject.Inject;
@ -45,10 +47,13 @@ public class JarPluginProvider implements ServerPluginProvider {
static final Logger log = LoggerFactory.getLogger(JarPluginProvider.class);
private final Path tmpDir;
private final PluginConfigFactory configFactory;
@Inject
JarPluginProvider(SitePaths sitePaths) {
tmpDir = sitePaths.tmp_dir;
JarPluginProvider(SitePaths sitePaths,
PluginConfigFactory configFactory) {
this.tmpDir = sitePaths.tmp_dir;
this.configFactory = configFactory;
}
@Override
@ -143,9 +148,12 @@ public class JarPluginProvider implements ServerPluginProvider {
PluginLoader.parentFor(type));
JarScanner jarScanner = createJarScanner(tmp);
PluginConfig pluginConfig = configFactory.getFromGerritConfig(name);
ServerPlugin plugin = new ServerPlugin(name, description.canonicalUrl,
description.user, srcJar, snapshot, jarScanner,
description.dataDir, pluginLoader);
description.dataDir, pluginLoader,
pluginConfig.getString("metricsPrefix", null));
plugin.setCleanupHandle(new CleanupHandle(tmp, jarFile));
keep = true;
return plugin;

View File

@ -45,9 +45,9 @@ public class PluginMetricMaker extends MetricMaker implements LifecycleListener
private final String prefix;
private final Set<RegistrationHandle> cleanup;
public PluginMetricMaker(MetricMaker root, String pluginName) {
public PluginMetricMaker(MetricMaker root, String prefix) {
this.root = root;
this.prefix = String.format("plugins/%s/", pluginName);
this.prefix = prefix.endsWith("/") ? prefix : prefix + "/";
cleanup = Collections.synchronizedSet(new HashSet<RegistrationHandle>());
}

View File

@ -41,6 +41,7 @@ public class ServerPlugin extends Plugin {
private final Path dataDir;
private final String pluginCanonicalWebUrl;
private final ClassLoader classLoader;
private final String metricsPrefix;
protected Class<? extends Module> sysModule;
protected Class<? extends Module> sshModule;
protected Class<? extends Module> httpModule;
@ -58,7 +59,8 @@ public class ServerPlugin extends Plugin {
FileSnapshot snapshot,
PluginContentScanner scanner,
Path dataDir,
ClassLoader classLoader) throws InvalidPluginException {
ClassLoader classLoader,
String metricsPrefix) throws InvalidPluginException {
super(name, srcJar, pluginUser, snapshot,
scanner == null
? ApiType.PLUGIN
@ -68,11 +70,24 @@ public class ServerPlugin extends Plugin {
this.dataDir = dataDir;
this.classLoader = classLoader;
this.manifest = scanner == null ? null : getPluginManifest(scanner);
this.metricsPrefix = metricsPrefix;
if (manifest != null) {
loadGuiceModules(manifest, classLoader);
}
}
public ServerPlugin(String name,
String pluginCanonicalWebUrl,
PluginUser pluginUser,
Path srcJar,
FileSnapshot snapshot,
PluginContentScanner scanner,
Path dataDir,
ClassLoader classLoader) throws InvalidPluginException {
this(name, pluginCanonicalWebUrl, pluginUser, srcJar, snapshot, scanner,
dataDir, classLoader, null);
}
private void loadGuiceModules(Manifest manifest, ClassLoader classLoader) throws InvalidPluginException {
Attributes main = manifest.getMainAttributes();
String sysName = main.getValue("Gerrit-Module");
@ -119,6 +134,10 @@ public class ServerPlugin extends Plugin {
return pluginCanonicalWebUrl;
}
String getMetricsPrefix() {
return metricsPrefix;
}
private static Manifest getPluginManifest(PluginContentScanner scanner)
throws InvalidPluginException {
try {

View File

@ -14,6 +14,7 @@
package com.google.gerrit.server.plugins;
import com.google.common.base.MoreObjects;
import com.google.gerrit.extensions.annotations.PluginCanonicalWebUrl;
import com.google.gerrit.extensions.annotations.PluginData;
import com.google.gerrit.extensions.annotations.PluginName;
@ -57,7 +58,8 @@ class ServerPluginInfoModule extends AbstractModule {
public void configure() {
PluginMetricMaker metrics = new PluginMetricMaker(
serverMetrics,
plugin.getName());
MoreObjects.firstNonNull(plugin.getMetricsPrefix(),
String.format("plugins/%s/", plugin.getName())));
bind(MetricMaker.class).toInstance(metrics);
listener().toInstance(metrics);
}