/* * Copyright 2018 The Cartographer Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ namespace CartographerSharp.Metrics; /// /// Family of metrics with labels. /// public abstract class Family where TMetricType : class { /// /// Family instance that does nothing. Safe for use in static initializers. /// public static Family Null() { return new NullFamily(); } /// /// Adds a metric instance with the specified labels. /// public abstract TMetricType Add(Dictionary labels); } /// /// Null implementation of family that does nothing. /// internal class NullFamily : Family where TMetricType : class { public override TMetricType Add(Dictionary labels) { // Return null metric instance if (typeof(TMetricType) == typeof(Counter)) return (TMetricType)(object)Counter.Null(); if (typeof(TMetricType) == typeof(Gauge)) return (TMetricType)(object)Gauge.Null(); if (typeof(TMetricType) == typeof(Histogram)) return (TMetricType)(object)Histogram.Null(); return null!; } } /// /// Factory for creating metric families. /// public abstract class FamilyFactory { /// /// Creates a new counter family. /// public abstract Family NewCounterFamily(string name, string description); /// /// Creates a new gauge family. /// public abstract Family NewGaugeFamily(string name, string description); /// /// Creates a new histogram family. /// public abstract Family NewHistogramFamily( string name, string description, Histogram.BucketBoundaries boundaries); }