Initial commit

This commit is contained in:
2026-07-03 16:37:12 +07:00
commit 63b8c1ea8b
1931 changed files with 640587 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
/*
* 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;
/// <summary>
/// Family of metrics with labels.
/// </summary>
public abstract class Family<TMetricType> where TMetricType : class
{
/// <summary>
/// Family instance that does nothing. Safe for use in static initializers.
/// </summary>
public static Family<TMetricType> Null()
{
return new NullFamily<TMetricType>();
}
/// <summary>
/// Adds a metric instance with the specified labels.
/// </summary>
public abstract TMetricType Add(Dictionary<string, string> labels);
}
/// <summary>
/// Null implementation of family that does nothing.
/// </summary>
internal class NullFamily<TMetricType> : Family<TMetricType> where TMetricType : class
{
public override TMetricType Add(Dictionary<string, string> 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!;
}
}
/// <summary>
/// Factory for creating metric families.
/// </summary>
public abstract class FamilyFactory
{
/// <summary>
/// Creates a new counter family.
/// </summary>
public abstract Family<Counter> NewCounterFamily(string name, string description);
/// <summary>
/// Creates a new gauge family.
/// </summary>
public abstract Family<Gauge> NewGaugeFamily(string name, string description);
/// <summary>
/// Creates a new histogram family.
/// </summary>
public abstract Family<Histogram> NewHistogramFamily(
string name,
string description,
Histogram.BucketBoundaries boundaries);
}