class MetricsInstrumentationInterceptor implements MongoInterceptor {

    @VisibleForTesting
    void addMetrics(long startTime, HttpServerExchange exchange) {
        if (configuration.gatheringAboveOrEqualToLevel(ROOT)) {
            var request = MongoRequest.of(exchange);
            
            long endTime = System.currentTimeMillis();
            long duration = endTime - startTime;

            addDefaultMetrics(metrics.registry(), duration, exchange);

            if (isFilledAndNotMetrics(request.getDBName()) && configuration.gatheringAboveOrEqualToLevel(DATABASE)) {
                final MetricRegistry dbRegistry = metrics.registry(request.getDBName());
                addDefaultMetrics(dbRegistry, duration, exchange);

                if (isFilledAndNotMetrics(request.getCollectionName()) && configuration.gatheringAboveOrEqualToLevel(COLLECTION)) {
                    final MetricRegistry collectionRegistry = metrics.registry(request.getDBName(), request.getCollectionName());
                    addDefaultMetrics(collectionRegistry, duration, exchange);
                }
            }
        }
    }

}