diff --git a/src/Promitor.Agents.Scraper/Extensions/IApplicationBuilderExtensions.cs b/src/Promitor.Agents.Scraper/Extensions/IApplicationBuilderExtensions.cs
index 58d557090..858d743ff 100644
--- a/src/Promitor.Agents.Scraper/Extensions/IApplicationBuilderExtensions.cs
+++ b/src/Promitor.Agents.Scraper/Extensions/IApplicationBuilderExtensions.cs
@@ -32,11 +32,14 @@ public static IApplicationBuilder UseMetricSinks(this IApplicationBuilder app, I
/// Path where the scrape endpoint will be exposed
public static IApplicationBuilder AddPrometheusScraperMetricSink(this IApplicationBuilder app, string scrapeEndpointPath)
{
- app.UsePrometheusServer(prometheusOptions =>
+ if (string.IsNullOrWhiteSpace(scrapeEndpointPath) == false)
{
- prometheusOptions.MapPath = scrapeEndpointPath;
- prometheusOptions.UseDefaultCollectors = false;
- });
+ app.UsePrometheusServer(prometheusOptions =>
+ {
+ prometheusOptions.MapPath = scrapeEndpointPath;
+ prometheusOptions.UseDefaultCollectors = false;
+ });
+ }
return app;
}
diff --git a/src/Promitor.Agents.Scraper/Startup.cs b/src/Promitor.Agents.Scraper/Startup.cs
index b047151e4..ff05df8d8 100644
--- a/src/Promitor.Agents.Scraper/Startup.cs
+++ b/src/Promitor.Agents.Scraper/Startup.cs
@@ -14,7 +14,6 @@
using Promitor.Agents.Scraper.Validation;
using Promitor.Core.Scraping.Configuration.Serialization.v1.Mapping;
using Promitor.Integrations.AzureMonitor.Logging;
-using Promitor.Integrations.Sinks.Prometheus.Configuration;
using Serilog;
using Swashbuckle.AspNetCore.SwaggerUI;
@@ -24,19 +23,19 @@ public class Startup : AgentStartup
{
private const string ApiName = "Promitor - Scraper API";
private const string ComponentName = "Promitor Scraper";
- private readonly string _prometheusBaseUriPath;
+ private readonly string _legacyPrometheusUriPath;
public Startup(IConfiguration configuration)
: base(configuration)
{
- var scrapeEndpointConfiguration = configuration.GetSection("prometheus:scrapeEndpoint").Get();
- _prometheusBaseUriPath = scrapeEndpointConfiguration.BaseUriPath;
+ var runtimeConfiguration = configuration.Get();
+ _legacyPrometheusUriPath = runtimeConfiguration?.Prometheus?.ScrapeEndpoint?.BaseUriPath;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
- string openApiDescription = BuildOpenApiDescription(Configuration);
+ string openApiDescription = BuildOpenApiDescription(Configuration, _legacyPrometheusUriPath);
services.UseWebApi()
.AddHttpCorrelation()
.AddAutoMapper(typeof(V1MappingProfile).Assembly)
@@ -65,7 +64,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
.UseHttpCorrelation()
.UseRouting()
.UseMetricSinks(Configuration)
- .AddPrometheusScraperMetricSink(_prometheusBaseUriPath) // Deprecated and will be gone in 2.0
+ .AddPrometheusScraperMetricSink(_legacyPrometheusUriPath) // Deprecated and will be gone in 2.0
.ExposeOpenApiUi() // New Swagger UI
.ExposeOpenApiUi(ApiName, swaggerUiOptions =>
{
@@ -100,7 +99,7 @@ protected override LoggerConfiguration FilterTelemetry(LoggerConfiguration logge
return standardConfiguration;
}
- private string BuildOpenApiDescription(IConfiguration configuration)
+ private string BuildOpenApiDescription(IConfiguration configuration, string legacyPrometheusUriPath)
{
var metricSinkConfiguration = configuration.GetSection("metricSinks").Get();
@@ -108,6 +107,11 @@ private string BuildOpenApiDescription(IConfiguration configuration)
openApiDescriptionBuilder.Append("Collection of APIs to manage the Promitor Scraper.\r\n\r\n");
openApiDescriptionBuilder.AppendLine("Configured metric sinks are:\r\n");
+ if (string.IsNullOrWhiteSpace(legacyPrometheusUriPath) == false)
+ {
+ openApiDescriptionBuilder.AppendLine($"Legacy Prometheus scrape endpoint is exposed at {legacyPrometheusUriPath}");
+ }
+
if (metricSinkConfiguration.PrometheusScrapingEndpoint != null)
{
var prometheusScrapingBaseUri = metricSinkConfiguration.PrometheusScrapingEndpoint.BaseUriPath;
@@ -118,7 +122,7 @@ private string BuildOpenApiDescription(IConfiguration configuration)
{
openApiDescriptionBuilder.AppendLine($"StatsD server located on {metricSinkConfiguration.Statsd.Host}:{metricSinkConfiguration.Statsd.Port}");
}
-
+
return openApiDescriptionBuilder.ToString();
}
}