How to disable logging for Dropwizard healthcheck
Asked Answered
M

3

9

I've got an application I've developed in Dropwizard (0.9), and part of our internal infrastructure routinely pings the admin healthcheck REST endpoint to validate that the service is up. This adds a great deal of:

127.0.0.1 - - [26/Sep/2016:21:47:04 +0000] "GET /healthcheck HTTP/1.1" 200 - "-" "curl/7.43.0" 27

to the logfiles. Adjusting our internal tools is out of scope, so I'd like to configure the logger to silence these entries. Unfortunately, I can't identify the class generating these messages. Which class is responsible for the built-in /healthcheck endpoint, and will a simple:

logging:
    loggers:
        "com.class.that.is.responsible": ERROR

entry in the yaml config suppress them?

Minute answered 26/9, 2016 at 23:11 Comment(3)
Looks like a standard logging from an HTTP service. Which one do you use?Ralph
You could do this via filters as well. Though i think DW does not necessarily make it easy to add filters to itAuscultation
Did you ever find a solution for this? I have the same issue.Tabbi
C
1

You can filter out the healthcheck requests with a logging filter.

That means there's a filter class:

    @JsonTypeName("healthcheck-filter-factory")
public class HealthCheckLogFilter implements FilterFactory<IAccessEvent> {
    @Override
    public Filter<IAccessEvent> build() {
        return new Filter<IAccessEvent>() {
            @Override
            public FilterReply decide(IAccessEvent event) {
                if (event.getRequestURI().equals("/") || event.getRequestURI().equals("/healthcheck")) {
                    return FilterReply.DENY;
                } else {
                    return FilterReply.NEUTRAL;
                }
            }
        };
    }
}

Then you register the filter class by writing its package name and class name into META-INF/services/io.dropwizard.logging.filter.FilterFactory file:

com.my.package.path.goes.here.HealthCheckLogFilter

And finally you add it to the configuration .yaml file:

requestLog:
  appenders:
    - type: console
      filterFactories:
        - type: healthcheck-filter-factory
Clarisaclarise answered 29/10, 2020 at 21:14 Comment(0)
C
1

If you're using DropWizard v2.0.0 or later, you can use the built-in UriFilterFactory. You can omit logs for specific endpoints by adding this to your dropwizard configuration .yaml:

server:
  requestLog:
    appenders:
      - type: console
        filterFactories:
          - type: uri
            uris:
              - "/healthcheck"

Note: the DropWizard documentation uses type: URI, which will not work. The @JsonTypeName in the source code is uri, so you have to use the lowercase name.

Consecution answered 13/4, 2021 at 17:53 Comment(0)
T
0

You can suppress it by adding this to your YAML config:

server:
  requestLog:
    appenders: []

Those log entries are from request log, more information here:

https://www.dropwizard.io/en/latest/manual/configuration.html#request-log

Turnstone answered 28/10, 2020 at 11:34 Comment(1)
Wouldn't this suppress ALL resource logs, not just /healthcheck?Consecution

© 2022 - 2024 — McMap. All rights reserved.