yifan-c commented on code in PR #200: URL: https://github.com/apache/cassandra-sidecar/pull/200#discussion_r1980447705
########## server/src/main/java/org/apache/cassandra/sidecar/modules/HealthCheckModule.java: ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.cassandra.sidecar.modules; + +import java.util.Collections; +import java.util.Map; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.ProvidesIntoMap; +import org.apache.cassandra.sidecar.cluster.InstancesMetadata; +import org.apache.cassandra.sidecar.concurrent.ExecutorPools; +import org.apache.cassandra.sidecar.config.SidecarConfiguration; +import org.apache.cassandra.sidecar.handlers.CassandraHealthHandler; +import org.apache.cassandra.sidecar.handlers.GossipHealthHandler; +import org.apache.cassandra.sidecar.handlers.RouteBuilder; +import org.apache.cassandra.sidecar.metrics.SidecarMetrics; +import org.apache.cassandra.sidecar.modules.multibindings.KeyClassMapKey; +import org.apache.cassandra.sidecar.modules.multibindings.PeriodicTaskMapKeys; +import org.apache.cassandra.sidecar.modules.multibindings.VertxRouteMapKeys; +import org.apache.cassandra.sidecar.routes.VertxRoute; +import org.apache.cassandra.sidecar.tasks.HealthCheckPeriodicTask; +import org.apache.cassandra.sidecar.tasks.PeriodicTask; + +/** + * Provides the capability to perform health checks on various components in both Sidecar and Cassandra + */ +public class HealthCheckModule extends AbstractModule +{ + public static final Map<String, String> OK_STATUS = Collections.singletonMap("status", "OK"); + public static final Map<String, String> NOT_OK_STATUS = Collections.singletonMap("status", "NOT_OK"); + + @ProvidesIntoMap + @KeyClassMapKey(PeriodicTaskMapKeys.HealthCheckPeriodicTaskKey.class) + PeriodicTask healthCheckPeriodicTask(SidecarConfiguration configuration, + InstancesMetadata instancesMetadata, + ExecutorPools executorPools, + SidecarMetrics metrics) + { + return new HealthCheckPeriodicTask(configuration, instancesMetadata, executorPools, metrics); + } + + @ProvidesIntoMap + @KeyClassMapKey(VertxRouteMapKeys.SidecarHealthRouteKey.class) + VertxRoute sidecarHealthRoute(RouteBuilder.Factory factory) + { + return factory.builderForUnprotectedRoute() + .handler(context -> context.json(OK_STATUS)) + .build(); + } + + @Deprecated + @ProvidesIntoMap + @KeyClassMapKey(VertxRouteMapKeys.CassandraHealthRouteKey.class) + VertxRoute cassandraHealthRoute(RouteBuilder.Factory factory, + CassandraHealthHandler cassandraHealthHandler) + { + // Backwards compatibility for the Cassandra health endpoint + return factory.builderForUnprotectedRoute() Review Comment: sounds good! I did not put much thought on the name. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org