io.vertx.micrometer.VertxPrometheusOptions Java Examples

The following examples show how to use io.vertx.micrometer.VertxPrometheusOptions. 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 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 #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 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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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 #25
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);
        }
    });
}
 
Example #26
Source File: InferenceVerticleHttp.java    From konduit-serving with Apache License 2.0 4 votes vote down vote up
public Router createRouter() {
    InferenceHttpApi inferenceHttpApi = new InferenceHttpApi(pipelineExecutor);

    Router inferenceRouter = Router.router(vertx);
    ServiceLoader<MetricsProvider> sl = ServiceLoader.load(MetricsProvider.class);
    Iterator<MetricsProvider> iterator = sl.iterator();
    MetricsProvider metricsProvider = null;
    if (iterator.hasNext()) {
        metricsProvider = iterator.next();
    }

    Object endpoint = metricsProvider == null ? null : metricsProvider.getEndpoint();
    if (endpoint != null) {
        log.info("MetricsProvider implementation detected, adding endpoint /metrics");
        MicrometerMetricsOptions micrometerMetricsOptions = new MicrometerMetricsOptions()
                .setMicrometerRegistry(MicrometerRegistry.getRegistry())
                .setPrometheusOptions(new VertxPrometheusOptions().setEnabled(true));
        BackendRegistries.setupBackend(micrometerMetricsOptions);

        inferenceRouter.get("/metrics").handler((Handler<RoutingContext>) endpoint)
                .failureHandler(failureHandler -> {
                    if (failureHandler.failure() != null) {
                        log.error("Failed to scrape metrics", failureHandler.failure());
                    }

                    failureHandler.response()
                            .setStatusCode(500)
                            .end(failureHandler.failure().toString());
                });
    }

    inferenceRouter.post().handler(BodyHandler.create()
            .setUploadsDirectory(DirectoryFetcher.getFileUploadsDir().getAbsolutePath())
            .setDeleteUploadedFilesOnEnd(true)
            .setMergeFormAttributes(true))
            .failureHandler(failureHandler -> {
                Throwable throwable = failureHandler.failure();
                int statusCode = failureHandler.statusCode();

                if (statusCode == 404) {
                    log.warn("404 at route {}" + failureHandler.request().path());
                } else if (failureHandler.failed()) {
                    if (throwable != null) {
                        log.error("Request failed with cause ", throwable);
                    } else {
                        log.error("Request failed with unknown cause.");
                    }
                }

                if (throwable instanceof KonduitServingHttpException) {
                    sendErrorResponse(failureHandler, ((KonduitServingHttpException) throwable).getErrorResponse());
                } else {
                    failureHandler.response()
                            .setStatusCode(500)
                            .end(throwable != null ? throwable.toString() : "Internal Server Exception");
                }
            });

    inferenceRouter.post("/predict")
            .consumes(APPLICATION_JSON.toString())
            .consumes(APPLICATION_OCTET_STREAM.toString())
            .produces(APPLICATION_JSON.toString())
            .produces(APPLICATION_OCTET_STREAM.toString())
            .handler(inferenceHttpApi::predict);


    //Custom endpoints:
    if (inferenceConfiguration.customEndpoints() != null && !inferenceConfiguration.customEndpoints().isEmpty()) {
        addCustomEndpoints(inferenceHttpApi, inferenceRouter);
    }

    return inferenceRouter;
}
 
Example #27
Source File: PrometheusBackendRegistry.java    From vertx-micrometer-metrics with Apache License 2.0 4 votes vote down vote up
public PrometheusBackendRegistry(VertxPrometheusOptions options) {
  this(options, new PrometheusMeterRegistry(PrometheusConfig.DEFAULT));
}