Skip to content

Commit

Permalink
Only poll queue metrics in the same process that is running the stack…
Browse files Browse the repository at this point in the history
… event count job
  • Loading branch information
ejsmith committed Dec 18, 2024
1 parent e6d7709 commit 757ec52
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/Exceptionless.Core/Configuration/QueueOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class QueueOptions

public string Scope { get; internal set; } = null!;
public string ScopePrefix { get; internal set; } = null!;
public bool MetricsPollingEnabled { get; set; } = true;
public TimeSpan MetricsPollingInterval { get; set; } = TimeSpan.FromSeconds(5);

public static QueueOptions ReadFromConfiguration(IConfiguration config, AppOptions appOptions)
{
Expand Down Expand Up @@ -44,6 +46,8 @@ public static QueueOptions ReadFromConfiguration(IConfiguration config, AppOptio

options.ConnectionString = options.Data.BuildConnectionString(new HashSet<string> { nameof(options.Provider) });

options.MetricsPollingInterval = appOptions.AppMode == AppMode.Development ? TimeSpan.FromSeconds(15) : TimeSpan.FromSeconds(5);

return options;
}
}
4 changes: 2 additions & 2 deletions src/Exceptionless.Core/Exceptionless.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="FluentValidation" Version="11.11.0" />
<PackageReference Include="Foundatio.Extensions.Hosting" Version="11.0.6" />
<PackageReference Include="Foundatio.JsonNet" Version="11.0.6" />
<PackageReference Include="Foundatio.Extensions.Hosting" Version="11.0.7-alpha.0.3" />
<PackageReference Include="Foundatio.JsonNet" Version="11.0.7-alpha.0.3" />
<PackageReference Include="MiniValidation" Version="0.9.1" />
<PackageReference Include="NEST.JsonNetSerializer" Version="7.17.5" />
<PackageReference Include="Handlebars.Net" Version="2.1.6" />
Expand Down
12 changes: 9 additions & 3 deletions src/Exceptionless.Insulation/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ private static IQueue<T> CreateAzureStorageQueue<T>(IServiceProvider container,
WorkItemTimeout = workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5.0)),
Serializer = container.GetRequiredService<ISerializer>(),
TimeProvider = container.GetRequiredService<TimeProvider>(),
LoggerFactory = container.GetRequiredService<ILoggerFactory>()
LoggerFactory = container.GetRequiredService<ILoggerFactory>(),
MetricsPollingEnabled = options.MetricsPollingEnabled,
MetricsPollingInterval = options.MetricsPollingInterval
});
}

Expand All @@ -305,7 +307,9 @@ private static IQueue<T> CreateRedisQueue<T>(IServiceProvider container, QueueOp
RunMaintenanceTasks = runMaintenanceTasks,
Serializer = container.GetRequiredService<ISerializer>(),
TimeProvider = container.GetRequiredService<TimeProvider>(),
LoggerFactory = container.GetRequiredService<ILoggerFactory>()
LoggerFactory = container.GetRequiredService<ILoggerFactory>(),
MetricsPollingEnabled = options.MetricsPollingEnabled,
MetricsPollingInterval = options.MetricsPollingInterval
});
}

Expand Down Expand Up @@ -333,7 +337,9 @@ private static IQueue<T> CreateSQSQueue<T>(IServiceProvider container, QueueOpti
WorkItemTimeout = workItemTimeout.GetValueOrDefault(TimeSpan.FromMinutes(5.0)),
Serializer = container.GetRequiredService<ISerializer>(),
TimeProvider = container.GetRequiredService<TimeProvider>(),
LoggerFactory = container.GetRequiredService<ILoggerFactory>()
LoggerFactory = container.GetRequiredService<ILoggerFactory>(),
MetricsPollingEnabled = options.MetricsPollingEnabled,
MetricsPollingInterval = options.MetricsPollingInterval
});
}

Expand Down
33 changes: 18 additions & 15 deletions src/Exceptionless.Job/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using Exceptionless.Core;
using Exceptionless.Core.Configuration;
using Exceptionless.Core.Extensions;
Expand Down Expand Up @@ -60,6 +60,9 @@ public static IHostBuilder CreateHostBuilder(string[] args)
.ForContext<Program>();

var options = AppOptions.ReadFromConfiguration(config);
// only poll the queue metrics if this process is going to run the stack event count job
options.QueueOptions.MetricsPollingEnabled = jobOptions.StackEventCount;

var apmConfig = new ApmConfig(config, $"job-{jobOptions.JobName.ToLowerUnderscoredWords('-')}", options.InformationalVersion, options.CacheOptions.Provider == "redis");

Log.Information("Bootstrapping Exceptionless {JobName} job(s) in {AppMode} mode ({InformationalVersion}) on {MachineName} with options {@Options}", jobOptions.JobName ?? "All", environment, options.InformationalVersion, Environment.MachineName, options);
Expand Down Expand Up @@ -146,42 +149,42 @@ private static void AddJobs(IServiceCollection services, JobRunnerOptions option
services.AddJob<CleanupOrphanedDataJob>();

if (options.CloseInactiveSessions)
services.AddJob<CloseInactiveSessionsJob>(o => o.WaitForStartupActions(true));
services.AddJob<CloseInactiveSessionsJob>(o => o.WaitForStartupActions());
if (options.DailySummary)
services.AddJob<DailySummaryJob>(o => o.WaitForStartupActions(true));
services.AddJob<DailySummaryJob>(o => o.WaitForStartupActions());
if (options.DataMigration)
services.AddJob<DataMigrationJob>(o => o.WaitForStartupActions(true));
services.AddJob<DataMigrationJob>(o => o.WaitForStartupActions());

if (options is { DownloadGeoIPDatabase: true, AllJobs: true })
services.AddCronJob<DownloadGeoIPDatabaseJob>("0 1 * * *");
if (options is { DownloadGeoIPDatabase: true, AllJobs: false })
services.AddJob<DownloadGeoIPDatabaseJob>(o => o.WaitForStartupActions(true));
services.AddJob<DownloadGeoIPDatabaseJob>(o => o.WaitForStartupActions());

if (options.EventNotifications)
services.AddJob<EventNotificationsJob>(o => o.WaitForStartupActions(true));
services.AddJob<EventNotificationsJob>(o => o.WaitForStartupActions());
if (options.EventPosts)
services.AddJob<EventPostsJob>(o => o.WaitForStartupActions(true));
services.AddJob<EventPostsJob>(o => o.WaitForStartupActions());
if (options.EventUsage)
services.AddJob<EventUsageJob>(o => o.WaitForStartupActions(true));
services.AddJob<EventUsageJob>(o => o.WaitForStartupActions());
if (options.EventUserDescriptions)
services.AddJob<EventUserDescriptionsJob>(o => o.WaitForStartupActions(true));
services.AddJob<EventUserDescriptionsJob>(o => o.WaitForStartupActions());
if (options.MailMessage)
services.AddJob<MailMessageJob>(o => o.WaitForStartupActions(true));
services.AddJob<MailMessageJob>(o => o.WaitForStartupActions());

if (options is { MaintainIndexes: true, AllJobs: true })
services.AddCronJob<MaintainIndexesJob>("10 */2 * * *");
if (options is { MaintainIndexes: true, AllJobs: false })
services.AddJob<MaintainIndexesJob>();

if (options.Migration)
services.AddJob<MigrationJob>(o => o.WaitForStartupActions(true));
services.AddJob<MigrationJob>(o => o.WaitForStartupActions());
if (options.StackStatus)
services.AddJob<StackStatusJob>(o => o.WaitForStartupActions(true));
services.AddJob<StackStatusJob>(o => o.WaitForStartupActions());
if (options.StackEventCount)
services.AddJob<StackEventCountJob>(o => o.WaitForStartupActions(true));
services.AddJob<StackEventCountJob>(o => o.WaitForStartupActions());
if (options.WebHooks)
services.AddJob<WebHooksJob>(o => o.WaitForStartupActions(true));
services.AddJob<WebHooksJob>(o => o.WaitForStartupActions());
if (options.WorkItem)
services.AddJob<WorkItemJob>(o => o.WaitForStartupActions(true));
services.AddJob<WorkItemJob>(o => o.WaitForStartupActions());
}
}
3 changes: 3 additions & 0 deletions src/Exceptionless.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ public static IHostBuilder CreateHostBuilder(IConfigurationRoot config, string e
.ForContext<Program>();

var options = AppOptions.ReadFromConfiguration(config);
// only poll the queue metrics if this process is going to host the jobs
options.QueueOptions.MetricsPollingEnabled = options.RunJobsInProcess;

var apmConfig = new ApmConfig(config, "web", options.InformationalVersion, options.CacheOptions.Provider == "redis");

Log.Information("Bootstrapping Exceptionless Web in {AppMode} mode ({InformationalVersion}) on {MachineName} with options {@Options}", environment, options.InformationalVersion, Environment.MachineName, options);
Expand Down

0 comments on commit 757ec52

Please sign in to comment.