private VertxMetrics initialiseMetrics(VertxOptions options) { if (options.getMetricsOptions() != null && options.getMetricsOptions().isEnabled()) { VertxMetricsFactory factory = options.getMetricsOptions().getFactory(); if (factory == null) { factory = ServiceHelper.loadFactoryOrNull(VertxMetricsFactory.class); if (factory == null) { log.warn("Metrics has been set to enabled but no VertxMetricsFactory found on classpath"); } } if (factory != null) { VertxMetrics metrics = factory.metrics(options); Objects.requireNonNull(metrics, "The metric instance created from " + factory + " cannot be null"); return metrics; } } return null; }
@Test public void testCustomMetricsOptions() throws Exception { System.setProperty(RunCommand.METRICS_OPTIONS_PROP_PREFIX + "enabled", "true"); System.setProperty(RunCommand.METRICS_OPTIONS_PROP_PREFIX + "customProperty", "customPropertyValue"); MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(MetricsOptionsTest.createMetricsFromMetaInfLoader("io.vertx.core.CustomMetricsFactory")); try { launcher.dispatch(args); } finally { Thread.currentThread().setContextClassLoader(oldCL); } assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); CustomMetricsOptions custom = (CustomMetricsOptions) opts.getMetricsOptions(); assertEquals("customPropertyValue", custom.getCustomProperty()); }
json.put("maxWorkerExecuteTimeUnit", obj.getMaxWorkerExecuteTimeUnit().name()); if (obj.getMetricsOptions() != null) { json.put("metricsOptions", obj.getMetricsOptions().toJson());
@Test public void testCustomMetricsOptions() throws Exception { System.setProperty(Starter.METRICS_OPTIONS_PROP_PREFIX + "enabled", "true"); System.setProperty(Starter.METRICS_OPTIONS_PROP_PREFIX + "customProperty", "customPropertyValue"); MyStarter starter = new MyStarter(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(MetricsOptionsTest.createMetricsFromMetaInfLoader("io.vertx.core.CustomMetricsFactory")); try { starter.run(args); } finally { Thread.currentThread().setContextClassLoader(oldCL); } assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = starter.getVertxOptions(); CustomMetricsOptions custom = (CustomMetricsOptions) opts.getMetricsOptions(); assertEquals("customPropertyValue", custom.getCustomProperty()); cleanup(starter); }
@Test public void testConfigureFromSystemPropertiesInvalidPropertyName() throws Exception { System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "nosuchproperty", "123"); // Should be ignored MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); VertxOptions def = new VertxOptions(); if (opts.getMetricsOptions().isEnabled()) { def.getMetricsOptions().setEnabled(true); } assertEquals(def, opts); }
@Test public void testConfigureFromSystemPropertiesInvalidPropertyType() throws Exception { // One for each type that we support System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "eventLoopPoolSize", "sausages"); // Should be ignored MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); VertxOptions def = new VertxOptions(); if (opts.getMetricsOptions().isEnabled()) { def.getMetricsOptions().setEnabled(true); } assertEquals(def, opts); }
private void testCustomMetricsOptionsFromJson(boolean jsonFile) throws Exception { JsonObject json = new JsonObject() .put("metricsOptions", new JsonObject() .put("enabled", true) .put("customProperty", "customPropertyValue") .put("nestedOptions", new JsonObject().put("nestedProperty", "nestedValue"))); String optionsArg; if (jsonFile) { File file = testFolder.newFile(); Files.write(file.toPath(), json.toBuffer().getBytes()); optionsArg = file.getPath(); } else { optionsArg = json.toString(); } MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName(), "-options", optionsArg}; ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(MetricsOptionsTest.createMetricsFromMetaInfLoader("io.vertx.core.CustomMetricsFactory")); try { launcher.dispatch(args); } finally { Thread.currentThread().setContextClassLoader(oldCL); } assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); CustomMetricsOptions custom = (CustomMetricsOptions) opts.getMetricsOptions(); assertEquals("customPropertyValue", custom.getCustomProperty()); assertEquals("nestedValue", custom.getNestedOptions().getNestedProperty()); }
@Test public void testConfigureFromSystemPropertiesInvalidPropertyName() throws Exception { System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "nosuchproperty", "123"); // Should be ignored MyStarter starter = new MyStarter(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; starter.run(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = starter.getVertxOptions(); VertxOptions def = new VertxOptions(); if (opts.getMetricsOptions().isEnabled()) { def.getMetricsOptions().setEnabled(true); } assertEquals(def, opts); cleanup(starter); }
@Test public void testConfigureFromSystemPropertiesInvalidPropertyType() throws Exception { // One for each type that we support System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "eventLoopPoolSize", "sausages"); // Should be ignored MyStarter starter = new MyStarter(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; starter.run(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = starter.getVertxOptions(); VertxOptions def = new VertxOptions(); if (opts.getMetricsOptions().isEnabled()) { def.getMetricsOptions().setEnabled(true); } assertEquals(def, opts); cleanup(starter); }
private void testConfigureFromJson(boolean jsonFile) throws Exception { JsonObject json = new JsonObject() .put("eventLoopPoolSize", 123) .put("maxEventLoopExecuteTime", 123767667) .put("metricsOptions", new JsonObject().put("enabled", true)) .put("eventBusOptions", new JsonObject().put("clustered", true).put("clusterPublicHost", "mars")) .put("haGroup", "somegroup") .put("maxEventLoopExecuteTimeUnit", "SECONDS"); String optionsArg; if (jsonFile) { File file = testFolder.newFile(); Files.write(file.toPath(), json.toBuffer().getBytes()); optionsArg = file.getPath(); } else { optionsArg = json.toString(); } MyLauncher launcher = new MyLauncher(); String[] args = new String[]{"run", "java:" + TestVerticle.class.getCanonicalName(), "-options", optionsArg}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); assertEquals(123, opts.getEventLoopPoolSize(), 0); assertEquals(123767667L, opts.getMaxEventLoopExecuteTime()); assertEquals(true, opts.getMetricsOptions().isEnabled()); assertEquals(true, opts.isClustered()); assertEquals("mars", opts.getClusterPublicHost()); assertEquals("somegroup", opts.getHAGroup()); assertEquals(TimeUnit.SECONDS, opts.getMaxEventLoopExecuteTimeUnit()); }
/** * Copy constructor * * @param other The other {@code VertxOptions} to copy when creating this */ public VertxOptions(VertxOptions other) { this.eventLoopPoolSize = other.getEventLoopPoolSize(); this.workerPoolSize = other.getWorkerPoolSize(); this.blockedThreadCheckInterval = other.getBlockedThreadCheckInterval(); this.maxEventLoopExecuteTime = other.getMaxEventLoopExecuteTime(); this.maxWorkerExecuteTime = other.getMaxWorkerExecuteTime(); this.internalBlockingPoolSize = other.getInternalBlockingPoolSize(); this.clusterManager = other.getClusterManager(); this.haEnabled = other.isHAEnabled(); this.quorumSize = other.getQuorumSize(); this.haGroup = other.getHAGroup(); this.metricsOptions = other.getMetricsOptions() != null ? new MetricsOptions(other.getMetricsOptions()) : null; this.fileSystemOptions = other.getFileSystemOptions() != null ? new FileSystemOptions(other.getFileSystemOptions()) : null; this.warningExceptionTime = other.warningExceptionTime; this.eventBusOptions = new EventBusOptions(other.eventBusOptions); this.addressResolverOptions = other.addressResolverOptions != null ? new AddressResolverOptions() : null; this.maxEventLoopExecuteTimeUnit = other.maxEventLoopExecuteTimeUnit; this.maxWorkerExecuteTimeUnit = other.maxWorkerExecuteTimeUnit; this.warningExceptionTimeUnit = other.warningExceptionTimeUnit; this.blockedThreadCheckIntervalUnit = other.blockedThreadCheckIntervalUnit; }
private void testConfigureFromSystemProperties(boolean clustered) throws Exception { // One for each type that we support System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "eventLoopPoolSize", "123"); System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "maxEventLoopExecuteTime", "123767667"); System.setProperty(RunCommand.METRICS_OPTIONS_PROP_PREFIX + "enabled", "true"); System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "haGroup", "somegroup"); System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "maxEventLoopExecuteTimeUnit", "SECONDS"); MyLauncher launcher = new MyLauncher(); String[] args; if (clustered) { args = new String[]{"run", "java:" + TestVerticle.class.getCanonicalName(), "-cluster"}; } else { args = new String[]{"run", "java:" + TestVerticle.class.getCanonicalName()}; } launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); assertEquals(123, opts.getEventLoopPoolSize(), 0); assertEquals(123767667L, opts.getMaxEventLoopExecuteTime()); assertEquals(true, opts.getMetricsOptions().isEnabled()); assertEquals("somegroup", opts.getHAGroup()); assertEquals(TimeUnit.SECONDS, opts.getMaxEventLoopExecuteTimeUnit()); }
@Test public void testMetricsEnabledFromCommandLine() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-Dvertx.metrics.options.enabled=true"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); // Check that the metrics are enabled // We cannot use the response from the verticle as it uses the DymmyVertxMetrics (no metrics provider) assertThat(((RunCommand)cli.getExistingCommandInstance("run")).options.getMetricsOptions().isEnabled()).isTrue(); }
private void testConfigureFromSystemProperties(boolean clustered) throws Exception { // One for each type that we support System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "eventLoopPoolSize", "123"); System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "maxEventLoopExecuteTime", "123767667"); System.setProperty(Starter.METRICS_OPTIONS_PROP_PREFIX + "enabled", "true"); System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "haGroup", "somegroup"); System.setProperty(Starter.VERTX_OPTIONS_PROP_PREFIX + "maxEventLoopExecuteTimeUnit", "SECONDS"); MyStarter starter = new MyStarter(); String[] args; if (clustered) { args = new String[] {"run", "java:" + TestVerticle.class.getCanonicalName(), "-cluster"}; } else { args = new String[] {"run", "java:" + TestVerticle.class.getCanonicalName()}; } starter.run(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = starter.getVertxOptions(); assertEquals(123, opts.getEventLoopPoolSize(), 0); assertEquals(123767667L, opts.getMaxEventLoopExecuteTime()); assertEquals(true, opts.getMetricsOptions().isEnabled()); assertEquals("somegroup", opts.getHAGroup()); assertEquals(TimeUnit.SECONDS, opts.getMaxEventLoopExecuteTimeUnit()); cleanup(starter); }
assertEquals(1, options.getQuorumSize()); assertEquals(VertxOptions.DEFAULT_HA_GROUP, options.getHAGroup()); assertNotNull(options.getMetricsOptions()); assertEquals(5000000000l, options.getWarningExceptionTime()); assertEquals(TimeUnit.NANOSECONDS, options.getMaxEventLoopExecuteTimeUnit()); assertEquals(classPathResolvingEnabled, fileSystemOptions.isClassPathResolvingEnabled()); assertEquals(fileResolverCachingEnabled, fileSystemOptions.isFileCachingEnabled()); MetricsOptions metricsOptions = options.getMetricsOptions(); assertEquals(metricsEnabled, metricsOptions.isEnabled()); assertEquals(warningExceptionTime, options.getWarningExceptionTime());
public DefaultVertxMetrics(Vertx vertx, VertxOptions vertxOptions) { this.vertx = vertx; this.vertxOptions = vertxOptions; this.clientEndpointMetricManager = new DefaultClientEndpointMetricManager(vertx, (MetricsOptionsEx) vertxOptions.getMetricsOptions()); }
assertEquals(quorumSize, options.getQuorumSize()); assertEquals(haGroup, options.getHAGroup()); MetricsOptions metricsOptions = options.getMetricsOptions(); assertNotNull(metricsOptions); assertEquals(metricsEnabled, metricsOptions.isEnabled());
@Test public void testConfigureFromSystemPropertiesInvalidPropertyName() throws Exception { System.setProperty(RunCommand.VERTX_OPTIONS_PROP_PREFIX + "nosuchproperty", "123"); // Should be ignored MyLauncher launcher = new MyLauncher(); String[] args = {"run", "java:" + TestVerticle.class.getCanonicalName()}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); VertxOptions opts = launcher.getVertxOptions(); VertxOptions def = new VertxOptions(); if (opts.getMetricsOptions().isEnabled()) { def.getMetricsOptions().setEnabled(true); } assertEquals(def, opts); }
@Test public void testMetricsEnabledFromCommandLine() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-Dvertx.metrics.options.enabled=true"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); // Check that the metrics are enabled // We cannot use the response from the verticle as it uses the DymmyVertxMetrics (no metrics provider) assertThat(((RunCommand)cli.getExistingCommandInstance("run")).options.getMetricsOptions().isEnabled()).isTrue(); }
assertNotNull(options.getMetricsOptions());