Search code examples
javadropwizardhealth-monitoringcodahale-metrics

DropWizard not registering my health check


In my DropWizard (v0.7.0) app, I have a DummyHealthCheck like so:

public class DummyHealthCheck extends HealthCheck {
    @Override
    protected Result check() throws Exception {
        return Result.healthy();
    }
}

Then in my main Application impl:

public class MyApplication extends Application<MyConfiguration> {
    @Override
    public void run(MyConfiguration configuration, Environment environment)
            throws Exception {
        environment.jersey().register(new DummyHealthCheck());
    }
}

When I start up the server, it starts successfuly (no exceptions/errors), however I get the following message:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!    THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW      !
!     IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE      !
!    LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR    !
!         APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT.       !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

But when I go to http://localhost:8081/healthcheck I see:

{"deadlocks":{"healthy":true}}
  1. What is going on here? How do I register my health check?
  2. Also, I have configured DropWizard to use SSL (self-signed) on port 8443; I have verified this works with my normal endpoints. I am surprised, however, to see that my admin app is still exposed on 8081 over HTTP. How do I configure it for HTTPS as well?

Solution

  • Question 1:

    You don't register it with Jersey, as Health Checks are DropWizard specific. They should be registered as follows

    environment.healthChecks().register("dummy", new DummyHealthCheck());
    

    as explained here. If it was registered as above, you would see

    {"deadlocks":{"healthy":true}, "dummy":{"healthy":true}}
    

    Question 2:

    I assume you already have done something similar to

    server:
      applicationConnectors:
        - type: https
          port: 8443
          keyStorePath: example.keystore
          keyStorePassword: example
          validateCerts: false
    

    in your yaml, as seen here. That is just for the application. You will also need to configure the admin

    server:
      applicationConnectors:
      - ...
      adminConnectors:
      - type: https
        port: 8444    // should a different port from the application
        keyStorePath: example.keystore
        keyStorePassword: example
        validateCerts: false