Skip to content

Commit

Permalink
Remaining todos (#4022)
Browse files Browse the repository at this point in the history
* remove unnecessary TODO which is a left over

* Remove left over TODO in CachingHttpHandler (we remove the other ones too)

* Align the monitor http logging with the other instances

* Previously we used AllowAnyHeader = false and AllowAnyHeader = false. We are explicitely adding headers and methods that we allow.

* We know SP isn't using SignalR at all, and that will have to be added back in as a new feature later

* Address TODO in GetRetryPendingMessages for now but we probably should also change the RemoveFailedMessageRetryDocument to be batch oriented
  • Loading branch information
danielmarbach committed Mar 22, 2024
1 parent 8c6fd7d commit 7f83336
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 31 deletions.
Expand Up @@ -6,7 +6,6 @@ class CachingHttpHandler : IResultFilter
{
public void OnResultExecuting(ResultExecutingContext context)
{
// TODO do we even need to do this
var response = context.HttpContext.Response;
if (!response.Headers.ContainsKey("Cache-Control"))
{
Expand Down
Expand Up @@ -53,9 +53,7 @@ public static class HostApplicationBuilderExtensions

services.AddHttpLogging(options =>
{
// TODO Do we need to expose the host?
// we could also include the time it took to process the request
options.LoggingFields = HttpLoggingFields.RequestPath | HttpLoggingFields.RequestMethod | HttpLoggingFields.ResponseStatusCode;
options.LoggingFields = HttpLoggingFields.RequestPath | HttpLoggingFields.RequestMethod | HttpLoggingFields.ResponseStatusCode | HttpLoggingFields.Duration;
});

// Core registers the message dispatcher to be resolved from the transport seam. The dispatcher
Expand Down
3 changes: 0 additions & 3 deletions src/ServiceControl.Monitoring/WebApplicationExtensions.cs
Expand Up @@ -10,9 +10,6 @@ public static void UseServiceControlMonitoring(this WebApplication appBuilder)

appBuilder.UseCors(policyBuilder =>
{
// TODO verify that the default is no headers and no methods allowed
//builder.AllowAnyHeader();
//builder.AllowAnyMethod();
policyBuilder.AllowAnyOrigin();
policyBuilder.WithExposedHeaders(["ETag", "Last-Modified", "Link", "Total-Count", "X-Particular-Version"]);
policyBuilder.WithHeaders(["Origin", "X-Requested-With", "Content-Type", "Accept"]);
Expand Down
34 changes: 13 additions & 21 deletions src/ServiceControl.Persistence.RavenDB/ErrorMessagesDataStore.cs
Expand Up @@ -609,34 +609,26 @@ public async Task RemoveFailedMessageRetryDocument(string uniqueMessageId)
await session.Advanced.RequestExecutor.ExecuteAsync(new DeleteDocumentCommand(FailedMessageRetry.MakeDocumentId(uniqueMessageId), null), session.Advanced.Context);
}

// TODO: Once using .NET, consider using IAsyncEnumerable here as this is an unbounded query
public async Task<string[]> GetRetryPendingMessages(DateTime from, DateTime to, string queueAddress)
{
var ids = new List<string>();

using var session = documentStore.OpenAsyncSession();
var query = session.Advanced
.AsyncDocumentQuery<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.WhereEquals("Status", (int)FailedMessageStatus.RetryIssued)
.AndAlso()
.WhereBetween(options => options.LastModified, from.Ticks, to.Ticks)
.AndAlso()
.WhereEquals(o => o.QueueAddress, queueAddress)
.SelectFields<FailedMessage>()
.ToQueryable()
.TransformToFailedMessageView();

await using (var ie = await session.Advanced.StreamAsync(query))
var query = session
.Query<FailedMessageViewIndex.SortAndFilterOptions, FailedMessageViewIndex>()
.Where(o => o.Status == FailedMessageStatus.RetryIssued && o.LastModified >= from.Ticks && o.LastModified <= to.Ticks && o.QueueAddress == queueAddress)
.OfType<FailedMessageProjection>();

int index = 0;
await using var streamResults = await session.Advanced.StreamAsync(query, out var streamQueryStatistics);
string[] ids = new string[streamQueryStatistics.TotalResults];
while (await streamResults.MoveNextAsync())
{
while (await ie.MoveNextAsync())
{
ids.Add(ie.Current.Document.Id);
}
ids[index++] = streamResults.Current.Document.UniqueMessageId;
}

return ids.ToArray();
return ids;
}

record struct FailedMessageProjection(string UniqueMessageId);

public async Task<byte[]> FetchFromFailedMessage(string uniqueMessageId)
{
byte[] body = null;
Expand Down
2 changes: 0 additions & 2 deletions src/ServiceControl/Hosting/Commands/MaintenanceModeCommand.cs
Expand Up @@ -26,9 +26,7 @@ public override async Task Execute(HostArguments args, Settings settings)
hostBuilder.Services.AddSingleton<IHostLifetime, PersisterInitializingConsoleLifetime>();
}

// TODO: Update to use the same pattern as the main Bootstrapper
var host = hostBuilder.Build();

await host.RunAsync();
}
}
Expand Down
Expand Up @@ -27,7 +27,6 @@ public MessageStreamerHub(IMessageDispatcher sender, IReadOnlySettings settings,
localAddress = receiveAddresses.MainReceiveAddress;
}

// TODO Change service pulse to call this method instead?
public async Task SendMessage(string data)
{
try
Expand Down

0 comments on commit 7f83336

Please sign in to comment.