LCOV - code coverage report
Current view: top level - metrics/dropwizard - DropWizardReservoirProvider.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 9 11 81.8 %
Date: 2022-11-19 15:00:39 Functions: 1 1 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2022 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.metrics.dropwizard;
      16             : 
      17             : import com.codahale.metrics.ExponentiallyDecayingReservoir;
      18             : import com.codahale.metrics.Reservoir;
      19             : import com.codahale.metrics.SlidingTimeWindowArrayReservoir;
      20             : import com.codahale.metrics.SlidingTimeWindowReservoir;
      21             : import com.codahale.metrics.SlidingWindowReservoir;
      22             : import com.codahale.metrics.UniformReservoir;
      23             : import com.google.gerrit.metrics.MetricsReservoirConfig;
      24             : import com.google.gerrit.metrics.ReservoirType;
      25             : import java.util.concurrent.TimeUnit;
      26             : 
      27             : class DropWizardReservoirProvider {
      28             : 
      29             :   private DropWizardReservoirProvider() {}
      30             : 
      31             :   static Reservoir get(MetricsReservoirConfig config) {
      32          16 :     ReservoirType reservoirType = config.reservoirType();
      33          16 :     switch (reservoirType) {
      34             :       case ExponentiallyDecaying:
      35          16 :         return new ExponentiallyDecayingReservoir(config.reservoirSize(), config.reservoirAlpha());
      36             :       case SlidingTimeWindowArray:
      37           1 :         return new SlidingTimeWindowArrayReservoir(
      38           1 :             config.reservoirWindow().toMillis(), TimeUnit.MILLISECONDS);
      39             :       case SlidingTimeWindow:
      40           1 :         return new SlidingTimeWindowReservoir(
      41           1 :             config.reservoirWindow().toMillis(), TimeUnit.MILLISECONDS);
      42             :       case SlidingWindow:
      43           1 :         return new SlidingWindowReservoir(config.reservoirSize());
      44             :       case Uniform:
      45           1 :         return new UniformReservoir(config.reservoirSize());
      46             : 
      47             :       default:
      48           0 :         throw new IllegalArgumentException(
      49           0 :             "Unsupported metrics reservoir type " + reservoirType.name());
      50             :     }
      51             :   }
      52             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750