Merge branch 'stable-2.13'
* stable-2.13: Allow plugins to set a custom metrics prefix Change-Id: Ia46ff8f66a1b8f18d2c7af08d62d5637f57a49e5
This commit is contained in:
commit
c9a0da87df
@ -2280,7 +2280,17 @@ Metric recording statistical distribution (rate) of values.
|
|||||||
Note that metrics cannot be recorded from plugin init steps that
|
Note that metrics cannot be recorded from plugin init steps that
|
||||||
are run during site initialization.
|
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
|
See the replication metrics in the
|
||||||
link:https://gerrit.googlesource.com/plugins/replication/+/master/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationMetrics.java[
|
link:https://gerrit.googlesource.com/plugins/replication/+/master/src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationMetrics.java[
|
||||||
|
@ -17,6 +17,8 @@ package com.google.gerrit.server.plugins;
|
|||||||
import static com.google.gerrit.server.plugins.PluginLoader.asTemp;
|
import static com.google.gerrit.server.plugins.PluginLoader.asTemp;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
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.gerrit.server.config.SitePaths;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
@ -45,10 +47,13 @@ public class JarPluginProvider implements ServerPluginProvider {
|
|||||||
static final Logger log = LoggerFactory.getLogger(JarPluginProvider.class);
|
static final Logger log = LoggerFactory.getLogger(JarPluginProvider.class);
|
||||||
|
|
||||||
private final Path tmpDir;
|
private final Path tmpDir;
|
||||||
|
private final PluginConfigFactory configFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
JarPluginProvider(SitePaths sitePaths) {
|
JarPluginProvider(SitePaths sitePaths,
|
||||||
tmpDir = sitePaths.tmp_dir;
|
PluginConfigFactory configFactory) {
|
||||||
|
this.tmpDir = sitePaths.tmp_dir;
|
||||||
|
this.configFactory = configFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -143,9 +148,12 @@ public class JarPluginProvider implements ServerPluginProvider {
|
|||||||
PluginLoader.parentFor(type));
|
PluginLoader.parentFor(type));
|
||||||
|
|
||||||
JarScanner jarScanner = createJarScanner(tmp);
|
JarScanner jarScanner = createJarScanner(tmp);
|
||||||
|
PluginConfig pluginConfig = configFactory.getFromGerritConfig(name);
|
||||||
|
|
||||||
ServerPlugin plugin = new ServerPlugin(name, description.canonicalUrl,
|
ServerPlugin plugin = new ServerPlugin(name, description.canonicalUrl,
|
||||||
description.user, srcJar, snapshot, jarScanner,
|
description.user, srcJar, snapshot, jarScanner,
|
||||||
description.dataDir, pluginLoader);
|
description.dataDir, pluginLoader,
|
||||||
|
pluginConfig.getString("metricsPrefix", null));
|
||||||
plugin.setCleanupHandle(new CleanupHandle(tmp, jarFile));
|
plugin.setCleanupHandle(new CleanupHandle(tmp, jarFile));
|
||||||
keep = true;
|
keep = true;
|
||||||
return plugin;
|
return plugin;
|
||||||
|
@ -45,9 +45,9 @@ public class PluginMetricMaker extends MetricMaker implements LifecycleListener
|
|||||||
private final String prefix;
|
private final String prefix;
|
||||||
private final Set<RegistrationHandle> cleanup;
|
private final Set<RegistrationHandle> cleanup;
|
||||||
|
|
||||||
public PluginMetricMaker(MetricMaker root, String pluginName) {
|
public PluginMetricMaker(MetricMaker root, String prefix) {
|
||||||
this.root = root;
|
this.root = root;
|
||||||
this.prefix = String.format("plugins/%s/", pluginName);
|
this.prefix = prefix.endsWith("/") ? prefix : prefix + "/";
|
||||||
cleanup = Collections.synchronizedSet(new HashSet<RegistrationHandle>());
|
cleanup = Collections.synchronizedSet(new HashSet<RegistrationHandle>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ public class ServerPlugin extends Plugin {
|
|||||||
private final Path dataDir;
|
private final Path dataDir;
|
||||||
private final String pluginCanonicalWebUrl;
|
private final String pluginCanonicalWebUrl;
|
||||||
private final ClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
private final String metricsPrefix;
|
||||||
protected Class<? extends Module> sysModule;
|
protected Class<? extends Module> sysModule;
|
||||||
protected Class<? extends Module> sshModule;
|
protected Class<? extends Module> sshModule;
|
||||||
protected Class<? extends Module> httpModule;
|
protected Class<? extends Module> httpModule;
|
||||||
@ -58,7 +59,8 @@ public class ServerPlugin extends Plugin {
|
|||||||
FileSnapshot snapshot,
|
FileSnapshot snapshot,
|
||||||
PluginContentScanner scanner,
|
PluginContentScanner scanner,
|
||||||
Path dataDir,
|
Path dataDir,
|
||||||
ClassLoader classLoader) throws InvalidPluginException {
|
ClassLoader classLoader,
|
||||||
|
String metricsPrefix) throws InvalidPluginException {
|
||||||
super(name, srcJar, pluginUser, snapshot,
|
super(name, srcJar, pluginUser, snapshot,
|
||||||
scanner == null
|
scanner == null
|
||||||
? ApiType.PLUGIN
|
? ApiType.PLUGIN
|
||||||
@ -68,11 +70,24 @@ public class ServerPlugin extends Plugin {
|
|||||||
this.dataDir = dataDir;
|
this.dataDir = dataDir;
|
||||||
this.classLoader = classLoader;
|
this.classLoader = classLoader;
|
||||||
this.manifest = scanner == null ? null : getPluginManifest(scanner);
|
this.manifest = scanner == null ? null : getPluginManifest(scanner);
|
||||||
|
this.metricsPrefix = metricsPrefix;
|
||||||
if (manifest != null) {
|
if (manifest != null) {
|
||||||
loadGuiceModules(manifest, classLoader);
|
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 {
|
private void loadGuiceModules(Manifest manifest, ClassLoader classLoader) throws InvalidPluginException {
|
||||||
Attributes main = manifest.getMainAttributes();
|
Attributes main = manifest.getMainAttributes();
|
||||||
String sysName = main.getValue("Gerrit-Module");
|
String sysName = main.getValue("Gerrit-Module");
|
||||||
@ -119,6 +134,10 @@ public class ServerPlugin extends Plugin {
|
|||||||
return pluginCanonicalWebUrl;
|
return pluginCanonicalWebUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getMetricsPrefix() {
|
||||||
|
return metricsPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
private static Manifest getPluginManifest(PluginContentScanner scanner)
|
private static Manifest getPluginManifest(PluginContentScanner scanner)
|
||||||
throws InvalidPluginException {
|
throws InvalidPluginException {
|
||||||
try {
|
try {
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.plugins;
|
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.PluginCanonicalWebUrl;
|
||||||
import com.google.gerrit.extensions.annotations.PluginData;
|
import com.google.gerrit.extensions.annotations.PluginData;
|
||||||
import com.google.gerrit.extensions.annotations.PluginName;
|
import com.google.gerrit.extensions.annotations.PluginName;
|
||||||
@ -57,7 +58,8 @@ class ServerPluginInfoModule extends AbstractModule {
|
|||||||
public void configure() {
|
public void configure() {
|
||||||
PluginMetricMaker metrics = new PluginMetricMaker(
|
PluginMetricMaker metrics = new PluginMetricMaker(
|
||||||
serverMetrics,
|
serverMetrics,
|
||||||
plugin.getName());
|
MoreObjects.firstNonNull(plugin.getMetricsPrefix(),
|
||||||
|
String.format("plugins/%s/", plugin.getName())));
|
||||||
bind(MetricMaker.class).toInstance(metrics);
|
bind(MetricMaker.class).toInstance(metrics);
|
||||||
listener().toInstance(metrics);
|
listener().toInstance(metrics);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user