LCOV - code coverage report
Current view: top level - metrics/dropwizard - MetricsCollection.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 6 13 46.2 %
Date: 2022-11-19 15:00:39 Functions: 1 4 25.0 %

          Line data    Source code
       1             : // Copyright (C) 2015 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.Metric;
      18             : import com.google.gerrit.extensions.registration.DynamicMap;
      19             : import com.google.gerrit.extensions.restapi.AuthException;
      20             : import com.google.gerrit.extensions.restapi.ChildCollection;
      21             : import com.google.gerrit.extensions.restapi.IdString;
      22             : import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
      23             : import com.google.gerrit.extensions.restapi.RestView;
      24             : import com.google.gerrit.server.config.ConfigResource;
      25             : import com.google.gerrit.server.permissions.GlobalPermission;
      26             : import com.google.gerrit.server.permissions.PermissionBackend;
      27             : import com.google.gerrit.server.permissions.PermissionBackendException;
      28             : import com.google.inject.Inject;
      29             : import com.google.inject.Provider;
      30             : import com.google.inject.Singleton;
      31             : 
      32             : @Singleton
      33             : class MetricsCollection implements ChildCollection<ConfigResource, MetricResource> {
      34             :   private final DynamicMap<RestView<MetricResource>> views;
      35             :   private final Provider<ListMetrics> list;
      36             :   private final PermissionBackend permissionBackend;
      37             :   private final DropWizardMetricMaker metrics;
      38             : 
      39             :   @Inject
      40             :   MetricsCollection(
      41             :       DynamicMap<RestView<MetricResource>> views,
      42             :       Provider<ListMetrics> list,
      43             :       PermissionBackend permissionBackend,
      44         138 :       DropWizardMetricMaker metrics) {
      45         138 :     this.views = views;
      46         138 :     this.list = list;
      47         138 :     this.permissionBackend = permissionBackend;
      48         138 :     this.metrics = metrics;
      49         138 :   }
      50             : 
      51             :   @Override
      52             :   public DynamicMap<RestView<MetricResource>> views() {
      53           0 :     return views;
      54             :   }
      55             : 
      56             :   @Override
      57             :   public RestView<ConfigResource> list() {
      58           0 :     return list.get();
      59             :   }
      60             : 
      61             :   @Override
      62             :   public MetricResource parse(ConfigResource parent, IdString id)
      63             :       throws ResourceNotFoundException, AuthException, PermissionBackendException {
      64           0 :     permissionBackend.currentUser().check(GlobalPermission.VIEW_CACHES);
      65             : 
      66           0 :     Metric metric = metrics.getMetric(id.get());
      67           0 :     if (metric == null) {
      68           0 :       throw new ResourceNotFoundException(id.get());
      69             :     }
      70           0 :     return new MetricResource(id.get(), metric);
      71             :   }
      72             : }

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