io.vertx.micrometer.MicrometerMetricsOptions Java Examples

The following examples show how to use io.vertx.micrometer.MicrometerMetricsOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldStartEmbeddedServer(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .addLabels(Label.LOCAL, Label.HTTP_PATH, Label.REMOTE)
      .setEnabled(true)));

  Async async = context.async();
  // First "blank" connection to trigger some metrics
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", r1 -> {
    // Delay to make "sure" metrics are populated
    vertx.setTimer(500, l ->
      // Second connection, this time actually reading the metrics content
      PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", body -> {
          context.verify(v2 -> assertThat(body.toString())
            .contains("vertx_http_client_requests{local=\"?\",method=\"GET\",path=\"/metrics\",remote=\"localhost:9090\"")
            .doesNotContain("vertx_http_client_responseTime_seconds_bucket"));
          async.complete();
      }));
  });
  async.awaitSuccess(10000);
}
 
Example #2
Source File: TopicOperatorBaseIT.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setupKubeCluster() throws IOException {
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true));
    vertx = Vertx.vertx(options);
    try {
        KubeCluster.bootstrap();
    } catch (NoClusterException e) {
        assumeTrue(false, e.getMessage());
    }
    cmdKubeClient().createNamespace(NAMESPACE);
    oldNamespace = cluster.setNamespace(NAMESPACE);
    LOGGER.info("#### Creating " + "../install/topic-operator/02-Role-strimzi-topic-operator.yaml");
    LOGGER.info(new String(Files.readAllBytes(new File("../install/topic-operator/02-Role-strimzi-topic-operator.yaml").toPath())));
    cmdKubeClient().create("../install/topic-operator/02-Role-strimzi-topic-operator.yaml");
    LOGGER.info("#### Creating " + TestUtils.CRD_TOPIC);
    LOGGER.info(new String(Files.readAllBytes(new File(TestUtils.CRD_TOPIC).toPath())));
    cmdKubeClient().create(TestUtils.CRD_TOPIC);
    LOGGER.info("#### Creating " + "src/test/resources/TopicOperatorIT-rbac.yaml");
    LOGGER.info(new String(Files.readAllBytes(new File("src/test/resources/TopicOperatorIT-rbac.yaml").toPath())));

    cmdKubeClient().create("src/test/resources/TopicOperatorIT-rbac.yaml");
}
 
Example #3
Source File: Main.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
private void deploy(Config config) {
    // Workaround for https://github.com/fabric8io/kubernetes-client/issues/2212
    // Can be removed after upgrade to Fabric8 4.10.2 or higher or to Java 11
    if (Util.shouldDisableHttp2()) {
        System.setProperty("http2.disable", "true");
    }

    DefaultKubernetesClient kubeClient = new DefaultKubernetesClient();
    Crds.registerCustomKinds();
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setJvmMetricsEnabled(true)
                    .setEnabled(true));
    Vertx vertx = Vertx.vertx(options);
    Session session = new Session(kubeClient, config);
    vertx.deployVerticle(session, ar -> {
        if (ar.succeeded()) {
            LOGGER.info("Session deployed");
        } else {
            LOGGER.error("Error deploying Session", ar.cause());
        }
    });
}
 
Example #4
Source File: CustomMicrometerMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPublishQuantilesWithProvidedRegistry(TestContext context) throws Exception {
  PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setPublishQuantiles(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .setMicrometerRegistry(registry)
      .setEnabled(true)));

  Async async = context.async();
  // Dummy connection to trigger some metrics
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", r1 -> {
    // Delay to make "sure" metrics are populated
    vertx.setTimer(500, l -> {
      assertThat(registry.scrape()).contains("vertx_http_client_responseTime_seconds_bucket{code=\"200\"");
      async.complete();
    });
  });
  async.awaitSuccess(10000);
}
 
Example #5
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPublishPercentileStats(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setPublishQuantiles(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .addLabels(Label.LOCAL, Label.HTTP_PATH, Label.REMOTE, Label.HTTP_CODE)
      .setEnabled(true)));

  Async async = context.async();
  // First "blank" connection to trigger some metrics
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", r1 -> {
    // Delay to make "sure" metrics are populated
    vertx.setTimer(500, l ->
      // Second connection, this time actually reading the metrics content
      PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", body -> {
        context.verify(v2 -> assertThat(body.toString())
          .contains("vertx_http_client_responseTime_seconds_bucket{code=\"200\""));
        async.complete();
      }));
  });
  async.awaitSuccess(10000);
}
 
Example #6
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldExcludeCategory(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .addDisabledMetricsCategory(MetricsDomain.HTTP_SERVER)
      .addLabels(Label.LOCAL, Label.REMOTE)
      .setEnabled(true)));

  Async async = context.async();
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", body -> {
    context.verify(v -> assertThat(body.toString())
      .contains("vertx_http_client_connections{local=\"?\",remote=\"localhost:9090\",} 1.0")
      .doesNotContain("vertx_http_server_connections{local=\"0.0.0.0:9090\",remote=\"_\",} 1.0"));
    async.complete();
  });
  async.awaitSuccess(10000);
}
 
Example #7
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldBindExistingServer(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
      .setEnabled(true)));

  Router router = Router.router(vertx);
  router.route("/custom").handler(routingContext -> {
    PrometheusMeterRegistry prometheusRegistry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
    String response = prometheusRegistry.scrape();
    routingContext.response().end(response);
  });
  vertx.createHttpServer().requestHandler(router).exceptionHandler(context.exceptionHandler()).listen(8081);

  Async async = context.async();
  PrometheusTestHelper.tryConnect(vertx, context, 8081, "localhost", "/custom", body -> {
    context.verify(v -> assertThat(body.toString())
          .contains("vertx_http_"));
    async.complete();
  });
  async.awaitSuccess(10000);
}
 
Example #8
Source File: JmxMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReportJmx(TestContext context) throws Exception {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setRegistryName(REGISTRY_NAME)
      .addLabels(Label.EB_ADDRESS)
      .setJmxMetricsOptions(new VertxJmxMetricsOptions().setEnabled(true)
        .setDomain("my-metrics")
        .setStep(1))
      .setEnabled(true)));

  // Send something on the eventbus and wait til it's received
  Async asyncEB = context.async();
  vertx.eventBus().consumer("test-eb", msg -> asyncEB.complete());
  vertx.eventBus().publish("test-eb", "test message");
  asyncEB.await(2000);

  // Read MBean
  MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  assertThat(mbs.getDomains()).contains("my-metrics");
  Number result = (Number) mbs.getAttribute(new ObjectName("my-metrics", "name", "vertxEventbusHandlers.address.test-eb"), "Value");
  assertThat(result).isEqualTo(1d);
}
 
Example #9
Source File: MetricsServiceImplTest.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGetJvmMetricsInSnapshot(TestContext ctx) {
  MetricsOptions metricsOptions = new MicrometerMetricsOptions()
    .setJvmMetricsEnabled(true)
    .setMicrometerRegistry(new SimpleMeterRegistry())
    .setRegistryName(registryName)
    .setEnabled(true);
  VertxOptions vertxOptions = new VertxOptions().setMetricsOptions(metricsOptions);
  Vertx vertx = Vertx.vertx(vertxOptions)
    .exceptionHandler(ctx.exceptionHandler());

  JsonObject snapshot = MetricsService.create(vertx).getMetricsSnapshot("jvm");

  assertFalse(snapshot.isEmpty());

  vertx.close(ctx.asyncAssertSuccess());
}
 
Example #10
Source File: VertxMetricsImpl.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
/**
 * @param options Vertx Prometheus options
 */
public VertxMetricsImpl(MicrometerMetricsOptions options, BackendRegistry backendRegistry) {
  super(backendRegistry.getMeterRegistry(), null);
  this.backendRegistry = backendRegistry;
  registryName = options.getRegistryName();
  MeterRegistry registry = backendRegistry.getMeterRegistry();

  eventBusMetrics = options.isMetricsCategoryDisabled(EVENT_BUS) ? null
    : new VertxEventBusMetrics(registry);
  datagramSocketMetrics = options.isMetricsCategoryDisabled(DATAGRAM_SOCKET) ? null
    : new VertxDatagramSocketMetrics(registry);
  netClientMetrics = options.isMetricsCategoryDisabled(NET_CLIENT) ? null
    : new VertxNetClientMetrics(registry);
  netServerMetrics = options.isMetricsCategoryDisabled(NET_SERVER) ? null
    : new VertxNetServerMetrics(registry);
  httpClientMetrics = options.isMetricsCategoryDisabled(HTTP_CLIENT) ? null
    : new VertxHttpClientMetrics(registry);
  httpServerMetrics = options.isMetricsCategoryDisabled(HTTP_SERVER) ? null
    : new VertxHttpServerMetrics(registry);
  poolMetrics = options.isMetricsCategoryDisabled(NAMED_POOLS) ? null
    : new VertxPoolMetrics(registry);
}
 
Example #11
Source File: BackendRegistries.java    From vertx-micrometer-metrics with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new backend registry, containing a micrometer registry, initialized with the provided options.
 * If a registry already exists with the associated name, it is just returned without any effect.
 * @param options micrometer options, including configuration related to the backend.
 *                Should be a subclass of {@link MicrometerMetricsOptions} (ex: {@link VertxInfluxDbOptions}, {@link VertxPrometheusOptions}).
 *                If the class is not recognized, a {@link NoopBackendRegistry} will be returned.
 * @return the created (or existing) {@link BackendRegistry}
 */
public static BackendRegistry setupBackend(MicrometerMetricsOptions options) {
  return REGISTRIES.computeIfAbsent(options.getRegistryName(), k -> {
    final BackendRegistry reg;
    if (options.getMicrometerRegistry() != null) {
      if (options.getPrometheusOptions() != null && options.getMicrometerRegistry() instanceof PrometheusMeterRegistry) {
        // If a Prometheus registry is provided, extra initialization steps may have to be performed
        reg = new PrometheusBackendRegistry(options.getPrometheusOptions(), (PrometheusMeterRegistry) options.getMicrometerRegistry());
      } else {
        // Other backend registries have no special extra steps
        reg = options::getMicrometerRegistry;
      }
    } else if (options.getInfluxDbOptions() != null && options.getInfluxDbOptions().isEnabled()) {
      reg = new InfluxDbBackendRegistry(options.getInfluxDbOptions());
    } else if (options.getPrometheusOptions() != null && options.getPrometheusOptions().isEnabled()) {
      reg = new PrometheusBackendRegistry(options.getPrometheusOptions());
    } else if (options.getJmxMetricsOptions() != null && options.getJmxMetricsOptions().isEnabled()) {
      reg = new JmxBackendRegistry(options.getJmxMetricsOptions());
    } else {
      // No backend setup, use global registry
      reg = NoopBackendRegistry.INSTANCE;
    }
    registerMatchers(reg.getMeterRegistry(), options.getLabels(), options.getLabelMatches());
    return reg;
  });
}
 
Example #12
Source File: Gateway.java    From vertx-in-action with MIT License 6 votes vote down vote up
public static void main(String[] args) throws UnknownHostException {
  String ipv4 = InetAddress.getLocalHost().getHostAddress();
  VertxOptions options = new VertxOptions()
    .setEventBusOptions(new EventBusOptions()
      .setHost(ipv4)
      .setClusterPublicHost(ipv4))
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions()
        .setPublishQuantiles(true)
        .setEnabled(true))
      .setEnabled(true));
  Vertx.clusteredVertx(options, ar -> {
    if (ar.succeeded()) {
      ar.result().deployVerticle(new Gateway());
    } else {
      logger.error("Could not start", ar.cause());
    }
  });
}
 
Example #13
Source File: MetricsUtils.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up promethues and returns the
 * registry
 * @return
 */
public static Pair<MicrometerMetricsOptions,MeterRegistry> setupPrometheus() {
    PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);

    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(registry)
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    return Pair.of(micrometerMetricsOptions,registry);

}
 
Example #14
Source File: DeployKonduitServing.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInference(DeploymentOptions deploymentOptions, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInference(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            deploymentOptions, eventHandler);
}
 
Example #15
Source File: TopicOperatorMockTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void before() {
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true));
    vertx = Vertx.vertx(options);
}
 
Example #16
Source File: TopicOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void before() {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true)
    ));
}
 
Example #17
Source File: DeployKonduitServing.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInference(InferenceConfiguration inferenceConfiguration, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInference(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            new DeploymentOptions().setConfig(new JsonObject(inferenceConfiguration.toJson())), eventHandler);
}
 
Example #18
Source File: KafkaUserOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void before() {
    //Setup Micrometer metrics options
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true));
    vertx = Vertx.vertx(options);
}
 
Example #19
Source File: Main.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    log.info("UserOperator {} is starting", Main.class.getPackage().getImplementationVersion());
    UserOperatorConfig config = UserOperatorConfig.fromMap(System.getenv());
    //Setup Micrometer metrics options
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setJvmMetricsEnabled(true)
                    .setEnabled(true));
    Vertx vertx = Vertx.vertx(options);

    // Workaround for https://github.com/fabric8io/kubernetes-client/issues/2212
    // Can be removed after upgrade to Fabric8 4.10.2 or higher or to Java 11
    if (Util.shouldDisableHttp2()) {
        System.setProperty("http2.disable", "true");
    }

    KubernetesClient client = new DefaultKubernetesClient();
    AdminClientProvider adminClientProvider = new DefaultAdminClientProvider();

    run(vertx, client, adminClientProvider, config).onComplete(ar -> {
        if (ar.failed()) {
            log.error("Unable to start operator", ar.cause());
            System.exit(1);
        }
    });
}
 
Example #20
Source File: OperatorMetricsTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void before() {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true)
    ));
}
 
Example #21
Source File: KafkaConnectorIT.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void before() {
    vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true)
    ));
}
 
Example #22
Source File: ClusterOperatorTest.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@BeforeAll
public static void before() {
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setEnabled(true));
    vertx = Vertx.vertx(options);
}
 
Example #23
Source File: Application.java    From strimzi-kafka-bridge with Apache License 2.0 5 votes vote down vote up
/**
 * Set up the Vert.x metrics options
 * 
 * @return instance of the MicrometerMetricsOptions on Vert.x
 */
private static MicrometerMetricsOptions metricsOptions() {
    return new MicrometerMetricsOptions()
            .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
            // define the labels on the HTTP server related metrics
            .setLabels(EnumSet.of(Label.REMOTE, Label.LOCAL, Label.HTTP_PATH, Label.HTTP_METHOD, Label.HTTP_CODE))
            // disable metrics about pool and verticles
            .setDisabledMetricsCategories(EnumSet.of(MetricsDomain.NAMED_POOLS, MetricsDomain.VERTICLES))
            .setJvmMetricsEnabled(true)
            .setEnabled(true);
}
 
Example #24
Source File: PrometheusMetricsITest.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void canMatchLabels(TestContext context) {
  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true)
        .setStartEmbeddedServer(true)
        .setEmbeddedServerOptions(new HttpServerOptions().setPort(9090)))
      .addLabels(Label.HTTP_PATH)
      .addLabelMatch(new Match()
        .setDomain(MetricsDomain.HTTP_CLIENT)
        .setValue(".*")
        .setLabel(Label.HTTP_PATH.toString())
        .setType(MatchType.REGEX))
      .setEnabled(true)));

  Async async = context.async();
  // First "blank" connection to trigger some metrics
  PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", r1 -> {
    // Delay to make "sure" metrics are populated
    vertx.setTimer(500, l ->
      // Second connection, this time actually reading the metrics content
      PrometheusTestHelper.tryConnect(vertx, context, 9090, "localhost", "/metrics", body -> {
        context.verify(v2 -> assertThat(body.toString())
          .contains("vertx_http_client_requests{method=\"GET\",path=\"/metrics\",}")
          .doesNotContain("vertx_http_client_responseTime_seconds_bucket"));
        async.complete();
      }));
  });
  async.awaitSuccess(10000);
}
 
Example #25
Source File: DeployKonduitOrchestration.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInferenceClustered(DeploymentOptions deploymentOptions, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInferenceClustered(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            deploymentOptions, eventHandler);
}
 
Example #26
Source File: DeployKonduitOrchestration.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
public static void deployInferenceClustered(InferenceConfiguration inferenceConfiguration, Handler<AsyncResult<InferenceConfiguration>> eventHandler) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    deployInferenceClustered(new VertxOptions()
                    .setMaxEventLoopExecuteTime(120)
                    .setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS)
                    .setMetricsOptions(micrometerMetricsOptions),
            new DeploymentOptions().setConfig(new JsonObject(inferenceConfiguration.toJson())), eventHandler);
}
 
Example #27
Source File: KonduitServingLauncher.java    From konduit-serving with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeStartingVertx(VertxOptions options) {
    MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
            .setMicrometerRegistry(new PrometheusMeterRegistry(PrometheusConfig.DEFAULT))
            .setPrometheusOptions(new VertxPrometheusOptions()
                    .setEnabled(true));

    log.info("Setup micro meter options.");
    BackendRegistries.setupBackend(micrometerMetricsOptions);

    options.setMetricsOptions(micrometerMetricsOptions);
    options.setMaxEventLoopExecuteTime(60);
    options.setMaxEventLoopExecuteTimeUnit(TimeUnit.SECONDS);
}
 
Example #28
Source File: InfluxDbReporterITest.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSendDataToInfluxDb(TestContext context) throws Exception {
  // Mock an influxdb server
  Async asyncInflux = context.async();
  InfluxDbTestHelper.simulateInfluxServer(vertxForSimulatedServer, context, 8086, body -> {
    if (body.contains("vertx_eventbus_handlers,address=test-eb,metric_type=gauge value=1")) {
      asyncInflux.complete();
    }
  });

  vertx = Vertx.vertx(new VertxOptions()
    .setMetricsOptions(new MicrometerMetricsOptions()
      .setInfluxDbOptions(new VertxInfluxDbOptions()
        .setStep(1)
        .setDb("mydb")
        .setEnabled(true))
      .setRegistryName(REGITRY_NAME)
      .addLabels(Label.EB_ADDRESS)
      .setEnabled(true)));

  // Send something on the eventbus and wait til it's received
  Async asyncEB = context.async();
  vertx.eventBus().consumer("test-eb", msg -> asyncEB.complete());
  vertx.eventBus().publish("test-eb", "test message");
  asyncEB.await(2000);

  // Await influx
  asyncInflux.awaitSuccess(2000);
}
 
Example #29
Source File: MetricsServiceImplTest.java    From vertx-micrometer-metrics with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext ctx) {
  vertx = Vertx.vertx(new VertxOptions().setMetricsOptions(new MicrometerMetricsOptions()
    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
    .setRegistryName(registryName)
    .setLabels(EnumSet.complementOf(EnumSet.of(Label.LOCAL, Label.REMOTE)))
    .setEnabled(true)))
    .exceptionHandler(ctx.exceptionHandler());

  // Setup server
  Async serverReady = ctx.async();
  httpServer = vertx.createHttpServer();
  httpServer
    .requestHandler(req -> {
      // Timer as artificial processing time
      vertx.setTimer(30L, handler ->
        req.response().setChunked(true).putHeader("Content-Type", "text/plain").end(SERVER_RESPONSE));
    })
    .listen(9195, "127.0.0.1", r -> {
      if (r.failed()) {
        ctx.fail(r.cause());
      } else {
        serverReady.complete();
      }
    });
  serverReady.awaitSuccess();
}
 
Example #30
Source File: Main.java    From strimzi-kafka-operator with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    log.info("ClusterOperator {} is starting", Main.class.getPackage().getImplementationVersion());
    ClusterOperatorConfig config = ClusterOperatorConfig.fromMap(System.getenv());

    String dnsCacheTtl = System.getenv("STRIMZI_DNS_CACHE_TTL") == null ? "30" : System.getenv("STRIMZI_DNS_CACHE_TTL");
    Security.setProperty("networkaddress.cache.ttl", dnsCacheTtl);

    //Setup Micrometer metrics options
    VertxOptions options = new VertxOptions().setMetricsOptions(
            new MicrometerMetricsOptions()
                    .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true))
                    .setJvmMetricsEnabled(true)
                    .setEnabled(true));
    Vertx vertx = Vertx.vertx(options);

    // Workaround for https://github.com/fabric8io/kubernetes-client/issues/2212
    // Can be removed after upgrade to Fabric8 4.10.2 or higher or to Java 11
    if (Util.shouldDisableHttp2()) {
        System.setProperty("http2.disable", "true");
    }
    
    KubernetesClient client = new DefaultKubernetesClient();

    maybeCreateClusterRoles(vertx, config, client).onComplete(crs -> {
        if (crs.succeeded())    {
            PlatformFeaturesAvailability.create(vertx, client).onComplete(pfa -> {
                if (pfa.succeeded()) {
                    log.info("Environment facts gathered: {}", pfa.result());

                    run(vertx, client, pfa.result(), config).onComplete(ar -> {
                        if (ar.failed()) {
                            log.error("Unable to start operator for 1 or more namespace", ar.cause());
                            System.exit(1);
                        }
                    });
                } else {
                    log.error("Failed to gather environment facts", pfa.cause());
                    System.exit(1);
                }
            });
        } else  {
            log.error("Failed to create Cluster Roles", crs.cause());
            System.exit(1);
        }
    });
}