Skip to content

Commit 1041f95

Browse files
authored
Merge pull request #81 from prom-client-net/feat/minor-impr
feat: minor improvements
2 parents 048186c + f738152 commit 1041f95

6 files changed

+150
-82
lines changed

src/Defaults.cs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Prometheus.Client.MetricServer;
2+
3+
internal static class Defaults
4+
{
5+
internal const string MapPath = "/metrics";
6+
internal const string ContentType = "text/plain; version=0.0.4";
7+
}

src/MetricServer.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public MetricServer(MetricServerOptions options)
3434
if (options == null)
3535
throw new ArgumentNullException(nameof(options));
3636

37-
if (string.IsNullOrEmpty(options.MapPath) || !options.MapPath.StartsWith("/"))
38-
throw new ArgumentException($"mapPath '{options.MapPath}' should start with '/'");
37+
if (!options.MapPath.StartsWith("/"))
38+
options.MapPath = "/" + options.MapPath;
3939

4040
_options = options;
4141

@@ -97,24 +97,18 @@ internal class Startup : IStartup
9797
public Startup(MetricServerOptions options)
9898
{
9999
_options = options;
100-
101-
var builder = new ConfigurationBuilder();
102-
Configuration = builder.Build();
103100
}
104101

105-
public IConfigurationRoot Configuration { get; }
106-
107102
public IServiceProvider ConfigureServices(IServiceCollection services)
108103
{
109104
return services.BuildServiceProvider();
110105
}
111106

112107
public void Configure(IApplicationBuilder app)
113108
{
114-
var contentType = "text/plain; version=0.0.4";
115-
116-
if (_options.ResponseEncoding != null)
117-
contentType += $"; charset={_options.ResponseEncoding.BodyName}";
109+
var contentType = _options.ResponseEncoding != null
110+
? $"{Defaults.ContentType}; charset={_options.ResponseEncoding.BodyName}"
111+
: Defaults.ContentType;
118112

119113
app.Map(_options.MapPath, coreapp =>
120114
{

src/MetricServerOptions.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class MetricServerOptions
2323
/// <summary>
2424
/// Endpoint path
2525
/// </summary>
26-
public string MapPath { get; set; } = "/metrics";
26+
public string MapPath { get; set; } = Defaults.MapPath;
2727

2828
/// <summary>
2929
/// Https certificate
@@ -38,7 +38,7 @@ public class MetricServerOptions
3838
/// <summary>
3939
/// Use default collectors(dotnet and process stats)
4040
/// </summary>
41-
public bool UseDefaultCollectors { get; set; } = false;
41+
public bool UseDefaultCollectors { get; set; } = true;
4242

4343
/// <summary>
4444
/// Charset of text response.
@@ -48,7 +48,7 @@ public class MetricServerOptions
4848
/// <summary>
4949
/// Metric prefix for Default collectors
5050
/// </summary>
51-
public string MetricPrefixName { get; set; } = "";
51+
public string MetricPrefixName { get; set; } = string.Empty;
5252

5353
/// <summary>
5454
/// Add legacy metrics to Default collectors

src/Prometheus.Client.MetricServer.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@
1010
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1111
<PackageReference Include="Prometheus.Client" Version="[5.2.0,6.0.0)" />
1212
</ItemGroup>
13+
<ItemGroup>
14+
<InternalsVisibleTo Include="$(MSBuildProjectName).Tests, PublicKey=002400000480000094000000060200000024000052534131000400000100010035b85a8ca7e3391c4ac9123c6e51491977a1229b85e572e70350884579334c7d44e3c00de913f684eaab330ceeaba6eb41bbb359b7157ff17542a4e112856c4a18ab521eb7acb4f5a03f3d0a7e849e5406bae28d6780bb2453122e60b52aa76ae10611a1d4a0ffba682558c05ae2b5a0709c260b8a0c3afb15cf2ca0eed949ee" />
15+
</ItemGroup>
1316
</Project>

0 commit comments

Comments
 (0)