Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Rotation Management #63

Merged
merged 13 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.flipkart.gjex.core.setup;
package com.flipkart.gjex.core.healthcheck;

import java.util.SortedMap;
import java.util.concurrent.ExecutorService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.flipkart.gjex.core.healthcheck;

import com.flipkart.gjex.core.logging.Logging;
import io.dropwizard.metrics5.health.HealthCheck;

import javax.inject.Singleton;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* Rotation management based health check for the app
* @author ajay.jalgaonkar
*/

@Singleton
public class RotationManagementBasedHealthCheck extends HealthCheck implements Logging {
private static final String BIR = "bir";
private static final String OOR = "oor";
private static final AtomicBoolean rotationStatus = new AtomicBoolean(true);
spawn92 marked this conversation as resolved.
Show resolved Hide resolved

public RotationManagementBasedHealthCheck() {}

@Override
protected Result check() {
if (isBir()) {
return Result.healthy("Server is " + getStatus());
} else {
return Result.unhealthy("Server is " + getStatus());
}
}

public String getStatus() {
return isBir() ? BIR : OOR;
}

public String makeOor() {
rotationStatus.set(false);
return OOR;
}

public String makeBir() {
rotationStatus.set(true);
return BIR;
}

public boolean isBir() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this method to inRotation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return rotationStatus.get();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.validation.Validator;
import javax.validation.ValidatorFactory;

import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry;
import io.dropwizard.metrics5.MetricRegistry;
import io.dropwizard.metrics5.jmx.JmxReporter;
import io.dropwizard.metrics5.jvm.BufferPoolMetricSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package com.flipkart.gjex.core.setup;

import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry;
import io.dropwizard.metrics5.MetricRegistry;

import java.util.concurrent.Executors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import javax.ws.rs.core.Response;

import io.dropwizard.metrics5.health.HealthCheck;
import com.flipkart.gjex.core.setup.HealthCheckRegistry;
import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry;

/**
* Servlet Resource for the HealthCheck API
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.flipkart.gjex.core.web;

import com.flipkart.gjex.core.healthcheck.RotationManagementBasedHealthCheck;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
* Resource for rotation management
* @author ajay.jalgaonkar
*/

@Singleton
@Path("/")
@Named
public class RotationManagementResource {

@Inject
public RotationManagementResource(RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck) {
this.rotationManagementBasedHealthCheck = rotationManagementBasedHealthCheck;
}

private RotationManagementBasedHealthCheck rotationManagementBasedHealthCheck;

@GET
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajay-jalgaonkar Lets not have this as GET's. A modification status should be an request which cannot be triggered by mistake or by automatic refresh. Lets move this to POST. Same with bir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Path("/oor")
@Produces(MediaType.APPLICATION_JSON)
public Response oor() {
String response = this.rotationManagementBasedHealthCheck.makeOor();
return Response.status(Response.Status.OK).entity(response).build();
}

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/bir")
public Response bir() {
String response = this.rotationManagementBasedHealthCheck.makeBir();
return Response.status(Response.Status.OK).entity(response).build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,20 @@
*/
package com.flipkart.gjex.examples.helloworld.guice;

import org.glassfish.jersey.server.ResourceConfig;

import io.dropwizard.metrics5.health.HealthCheck;
import com.flipkart.gjex.core.filter.Filter;
import com.flipkart.gjex.core.tracing.TracingSampler;
import com.flipkart.gjex.examples.helloworld.filter.AuthFilter;
import com.flipkart.gjex.examples.helloworld.filter.LoggingFilter;
import com.flipkart.gjex.examples.helloworld.healthcheck.AllIsWellHealthCheck;
import com.flipkart.gjex.examples.helloworld.service.GreeterService;
import com.flipkart.gjex.examples.helloworld.tracing.AllWhitelistTracingSampler;
import com.flipkart.gjex.examples.helloworld.web.HelloWorldResourceConfig;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;

import io.grpc.BindableService;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
import io.grpc.examples.helloworld.GreeterGrpc;


import org.glassfish.jersey.server.ResourceConfig;

/**
* Guice module for wiring sample Service to GJEX runtime
Expand All @@ -56,7 +50,6 @@ protected void configure() {
bind(Filter.class).annotatedWith(Names.named("LoggingFilter")).to(LoggingFilter.class);
bind(Filter.class).annotatedWith(Names.named("AuthFilter")).to(AuthFilter.class);
bind(TracingSampler.class).to(AllWhitelistTracingSampler.class);
bind(HealthCheck.class).to(AllIsWellHealthCheck.class);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kingster Should we remove AllIsWellHealthCheck.java altogether considering we are providing a health check implementation by default as part of server?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but then users shouldn't need to bind this. This should be part of the defaults then.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed AllIsWellHealthCheck

Copy link
Member

@kingster kingster Apr 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be by default now. Lets change this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now binding of RotationManagementBasedHealthCheck is done in ApiModule

bind(ResourceConfig.class).annotatedWith(Names.named("HelloWorldResourceConfig")).to(HelloWorldResourceConfig.class);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
package com.flipkart.gjex.guice.module;

import com.flipkart.gjex.core.GJEXConfiguration;
import com.flipkart.gjex.core.healthcheck.RotationManagementBasedHealthCheck;
import com.flipkart.gjex.core.logging.Logging;
import com.flipkart.gjex.core.service.Api;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.matcher.AbstractMatcher;
import com.google.inject.matcher.Matchers;
import io.dropwizard.metrics5.health.HealthCheck;
import io.grpc.BindableService;
import io.grpc.Context;
import org.aopalliance.intercept.MethodInterceptor;
Expand Down Expand Up @@ -50,6 +52,7 @@ protected void configure() {
ApiMethodInterceptor methodInterceptor = new ApiMethodInterceptor();
requestInjection(methodInterceptor);
bindInterceptor(Matchers.any(), new ApiMethodMatcher(), methodInterceptor);
bind(HealthCheck.class).to(RotationManagementBasedHealthCheck.class);
}

@Named("ApiScheduledExecutor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import javax.inject.Named;
import javax.inject.Singleton;

import com.flipkart.gjex.core.web.RotationManagementResource;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.DefaultServlet;
Expand All @@ -43,7 +44,7 @@
import com.flipkart.gjex.core.GJEXConfiguration;
import com.flipkart.gjex.core.logging.Logging;
import com.flipkart.gjex.core.setup.Bootstrap;
import com.flipkart.gjex.core.setup.HealthCheckRegistry;
import com.flipkart.gjex.core.healthcheck.HealthCheckRegistry;
import com.flipkart.gjex.core.tracing.TracingSamplerHolder;
import com.flipkart.gjex.core.web.DashboardResource;
import com.flipkart.gjex.core.web.HealthCheckResource;
Expand Down Expand Up @@ -139,13 +140,21 @@ Server getDashboardJettyServer(@Named("Dashboard.service.port") int port,
@Singleton
Server getAPIJettyServer(@Named("APIVanillaJettyServer")Server server,
@Named("ApiServletContext") ServletContextHandler context,
@Named("HealthCheckResourceConfig")ResourceConfig healthcheckResourceConfig,
@Named("HealthCheckResourceConfig") ResourceConfig healthCheckResourceConfig,
@Named("RotationManagementResourceConfig") ResourceConfig rotationManagementResourceConfig,
@Named("TracingResourceConfig")ResourceConfig tracingResourceConfig,
@Named("TracingSamplerHolder")TracingSamplerHolder tracingSamplerHolder,
@Named("JSONMarshallingProvider")JacksonJaxbJsonProvider provider) throws URISyntaxException, UnknownHostException {
healthcheckResourceConfig.register(provider);
ServletHolder healthcheckServlet = new ServletHolder(new ServletContainer(healthcheckResourceConfig));
context.addServlet(healthcheckServlet, "/healthcheck"); // registering Health Check servlet under the /healthcheck path
healthCheckResourceConfig.register(provider);
ServletHolder healthCheckServlet =
new ServletHolder(new ServletContainer(healthCheckResourceConfig));
context.addServlet(healthCheckServlet, "/healthcheck"); // registering Health Check servlet under the /healthcheck path

rotationManagementResourceConfig.register(provider);
ServletHolder rotationManagementServlet =
new ServletHolder(new ServletContainer(rotationManagementResourceConfig));
context.addServlet(rotationManagementServlet, "/rotation/*"); // registering Rotation
// Management servlet under the /rotation path

tracingResourceConfig.register(provider);
ServletHolder tracingServlet = new ServletHolder(new ServletContainer(tracingResourceConfig));
Expand Down Expand Up @@ -209,6 +218,16 @@ ResourceConfig getAPIResourceConfig(HealthCheckResource healthCheckResource) {
return resourceConfig;
}

@Named("RotationManagementResourceConfig")
@Singleton
@Provides
ResourceConfig getRotationManagementResourceConfig(RotationManagementResource rotationManagementResource) {
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(rotationManagementResource);
resourceConfig.setApplicationName(Constants.GJEX_CORE_APPLICATION);
return resourceConfig;
}

@Named("TracingResourceConfig")
@Singleton
@Provides
Expand Down