Skip to content

Commit 3d378e5

Browse files
committed
delete AddLegacyMetrics from GCTotalMemoryCollector
1 parent 7dc2cda commit 3d378e5

File tree

5 files changed

+8
-89
lines changed

5 files changed

+8
-89
lines changed
Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Prometheus.Client.Collectors.DotNetStats;
32
using Prometheus.Client.Collectors.ProcessStats;
43

@@ -18,19 +17,4 @@ public static ICollectorRegistry UseDefaultCollectors(this ICollectorRegistry re
1817

1918
return registry;
2019
}
21-
22-
[Obsolete("'addLegacyMetrics' will be removed in future versions")]
23-
public static ICollectorRegistry UseDefaultCollectors(this ICollectorRegistry registry, bool addLegacyMetrics)
24-
{
25-
return UseDefaultCollectors(registry, string.Empty, addLegacyMetrics);
26-
}
27-
28-
[Obsolete("'addLegacyMetrics' will be removed in future versions")]
29-
public static ICollectorRegistry UseDefaultCollectors(this ICollectorRegistry registry, string prefixName, bool addLegacyMetrics)
30-
{
31-
registry.UseDotNetStats(prefixName, addLegacyMetrics);
32-
registry.UseProcessStats(prefixName);
33-
34-
return registry;
35-
}
3620
}

src/Prometheus.Client/Collectors/DotNetStats/CollectorRegistryExtensions.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,4 @@ public static ICollectorRegistry UseDotNetStats(this ICollectorRegistry registry
1616

1717
return registry;
1818
}
19-
20-
[Obsolete("'addLegacyMetrics' will be removed in future versions")]
21-
public static ICollectorRegistry UseDotNetStats(this ICollectorRegistry registry, bool addLegacyMetrics)
22-
{
23-
return UseDotNetStats(registry, string.Empty, addLegacyMetrics);
24-
}
25-
26-
[Obsolete("'addLegacyMetrics' will be removed in future versions")]
27-
public static ICollectorRegistry UseDotNetStats(this ICollectorRegistry registry, string prefixName, bool addLegacyMetrics)
28-
{
29-
registry.Add(new GCCollectionCountCollector(prefixName));
30-
registry.Add(new GCTotalMemoryCollector(prefixName, addLegacyMetrics));
31-
32-
return registry;
33-
}
3419
}

src/Prometheus.Client/Collectors/DotNetStats/GCCollectionCountCollector.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Prometheus.Client.Collectors.DotNetStats;
66

7+
/// <summary>
8+
/// Collector for GC collection count.
9+
/// </summary>
710
public class GCCollectionCountCollector : ICollector
811
{
912
private const string _help = "GC collection count";
@@ -23,7 +26,7 @@ public GCCollectionCountCollector(string prefixName)
2326
{
2427
_name = prefixName + "dotnet_collection_count_total";
2528
Configuration = new CollectorConfiguration(nameof(GCCollectionCountCollector));
26-
MetricNames = new[] { _name };
29+
MetricNames = [_name];
2730
_genNames = new string[GC.MaxGeneration + 1];
2831
for (var gen = 0; gen <= GC.MaxGeneration; gen++)
2932
_genNames[gen] = gen.ToString();

src/Prometheus.Client/Collectors/DotNetStats/GCTotalMemoryCollector.cs

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
using System.Collections.Generic;
33
using Prometheus.Client.MetricsWriter;
44

5-
#pragma warning disable CS0618
6-
75
namespace Prometheus.Client.Collectors.DotNetStats;
86

7+
/// <summary>
8+
/// Collector for GC total known allocated memory.
9+
/// </summary>
910
public class GCTotalMemoryCollector : ICollector
1011
{
1112
private const string _help = "Total known allocated memory in bytes";
1213
private readonly string _name;
13-
private readonly string _legacyName;
14-
private readonly bool _addLegacyMetrics;
1514

1615
public CollectorConfiguration Configuration { get; }
1716
public IReadOnlyList<string> MetricNames { get; }
@@ -22,39 +21,17 @@ public GCTotalMemoryCollector()
2221
}
2322

2423
public GCTotalMemoryCollector(string prefixName)
25-
: this(prefixName, false)
2624
{
27-
}
28-
29-
[Obsolete("'addLegacyMetrics' will be removed in future versions")]
30-
public GCTotalMemoryCollector(bool addLegacyMetrics)
31-
: this(string.Empty, addLegacyMetrics)
32-
{
33-
}
34-
35-
[Obsolete("'addLegacyMetrics' will be removed in future versions")]
36-
public GCTotalMemoryCollector(string prefixName, bool addLegacyMetrics)
37-
{
38-
_legacyName = prefixName + "dotnet_totalmemory";
3925
_name = prefixName + "dotnet_total_memory_bytes";
4026

41-
_addLegacyMetrics = addLegacyMetrics;
42-
4327
Configuration = new CollectorConfiguration(nameof(GCTotalMemoryCollector));
44-
MetricNames = _addLegacyMetrics ? new[] { _legacyName, _name } : new[] { _name };
28+
MetricNames = [_name];
4529
}
4630

4731
public void Collect(IMetricsWriter writer)
4832
{
4933
writer.WriteMetricHeader(_name, MetricType.Gauge, _help);
5034
writer.WriteSample(GC.GetTotalMemory(false));
5135
writer.EndMetric();
52-
53-
if (_addLegacyMetrics)
54-
{
55-
writer.WriteMetricHeader(_legacyName, MetricType.Gauge, _help);
56-
writer.WriteSample(GC.GetTotalMemory(false));
57-
writer.EndMetric();
58-
}
5936
}
6037
}

tests/Prometheus.Client.Tests/CollectorTests/GCTotalMemoryCollectorTests.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ public void Check_MetricNames(string prefixName)
2121
Assert.Equal(prefixName + "dotnet_total_memory_bytes", collector.MetricNames.First());
2222
}
2323

24-
[Theory]
25-
[InlineData("")]
26-
[InlineData("123")]
27-
[InlineData("promitor_")]
28-
[InlineData("myprefix_")]
29-
public void Check_MetricNames_WithAddLegacy(string prefixName)
30-
{
31-
var collector = new GCTotalMemoryCollector(prefixName, true);
32-
33-
var legacyMetric = collector.MetricNames[0];
34-
var metric = collector.MetricNames[1];
35-
36-
Assert.Equal(prefixName + "dotnet_totalmemory", legacyMetric);
37-
Assert.Equal(prefixName + "dotnet_total_memory_bytes", metric);
38-
}
39-
4024
[Fact]
4125
public void Check_Collect_NoPrefix()
4226
{
@@ -51,20 +35,6 @@ public void Check_Collect_NoPrefix()
5135
Assert.Contains("# TYPE dotnet_total_memory_bytes gauge", response);
5236
}
5337

54-
[Fact]
55-
public void Check_Collect_NoPrefix_WithAddLegacy()
56-
{
57-
using var stream = new MemoryStream();
58-
var metricWriter = new MetricsTextWriter(stream);
59-
var collector = new GCTotalMemoryCollector(true);
60-
collector.Collect(metricWriter);
61-
metricWriter.FlushAsync();
62-
63-
var response = Encoding.UTF8.GetString(stream.ToArray());
64-
65-
Assert.Contains("# TYPE dotnet_totalmemory gauge", response);
66-
}
67-
6838
[Theory]
6939
[InlineData("")]
7040
[InlineData("123")]

0 commit comments

Comments
 (0)