Skip to content

Commit

Permalink
Fix: The path value is ignored when configuring endpoint options with…
Browse files Browse the repository at this point in the history
… an alternative ID and an empty path (SteeltoeOSS#1402)
  • Loading branch information
bart-vmware authored Nov 1, 2024
1 parent 5716f75 commit 5ace2a9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public virtual string? Path
{
get
{
if (!string.IsNullOrEmpty(_path))
if (_path != null)
{
return _path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal sealed class MetricsEndpointMiddleware(
internal string GetMetricName(HttpRequest request)
{
string? baseRequestPath = ManagementOptionsMonitor.CurrentValue.GetBaseRequestPath(request);
string path = $"{baseRequestPath}/{EndpointHandler.Options.Id}".Replace("//", "/", StringComparison.Ordinal);
string path = $"{baseRequestPath}/{EndpointHandler.Options.Path}".Replace("//", "/", StringComparison.Ordinal);

return GetMetricName(request, path);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Management/src/Prometheus/PrometheusExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public static IApplicationBuilder UsePrometheusActuator(this IApplicationBuilder
PrometheusEndpointOptions? prometheusOptions = builder.ApplicationServices.GetServices<EndpointOptions>()
.OfType<PrometheusEndpointOptions>().FirstOrDefault();

string root = managementOptions?.Path ?? "/actuator";
string id = prometheusOptions?.Id ?? "prometheus";
string path = root + "/" + id;
string basePath = managementOptions?.Path ?? "/actuator";
string endpointPath = prometheusOptions?.Path ?? "prometheus";
string path = $"{basePath}/{endpointPath}".Replace("//", "/", StringComparison.Ordinal);

return builder.UseOpenTelemetryPrometheusScrapingEndpoint(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,19 @@ public void Constructor_BindsConfigurationCorrectly()
Assert.Equal("info", options.Id);
Assert.Equal("infopath", options.Path);
}

[Fact]
public void CanSetEmptyPathWithDifferentId()
{
var appSettings = new Dictionary<string, string?>
{
["Management:Endpoints:Actuator:Id"] = "some",
["Management:Endpoints:Actuator:Path"] = string.Empty
};

HypermediaEndpointOptions options = GetOptionsFromSettings<HypermediaEndpointOptions, ConfigureHypermediaEndpointOptions>(appSettings);

options.Id.Should().Be("some");
options.Path.Should().BeEmpty();
}
}

0 comments on commit 5ace2a9

Please sign in to comment.