Skip to content

Commit 31b2012

Browse files
committed
Retire known-endpoints scatter-gather and audit KnownEndpoints storage
Retire known-endpoints scatter-gather and audit KnownEndpoints storage The audit instance's KnownEndpoint documents (and their LastSeen field) were written on every ingested batch but only ever read back by the /endpoints/known scatter-gather, which no shipping client depends on: ServicePulse never calls the route, and ServiceInsight only consumes identity fields that the primary can serve locally. Endpoint discovery already flows to the primary via RegisterNewEndpoint queue messages, so the remote query added nothing but edge cases (pre-4.5 endpoints without a HostId, in-flight registrations, primary-deleted endpoints still present in audit data). - Primary GET /endpoints/known now serves from the in-memory endpoint registry; GetKnownEndpointsApi is deleted - PATCH /endpoints/{id} returns 404 for unknown endpoints instead of crashing with KeyNotFoundException (500) - Audit ingestion no longer records KnownEndpoint documents; the model, RecordKnownEndpoint, and QueryKnownEndpoints are removed from the persistence seam and both implementations - The audit /endpoints/known route remains as a backwards-compatibility stub returning an empty result so older primaries that still scatter-gather get a valid response instead of a 404 Existing audit KnownEndpoint documents expire on their own via the RavenDB @expires metadata; no migration is needed.
1 parent a6c17c6 commit 31b2012

16 files changed

Lines changed: 21 additions & 305 deletions

File tree

src/ServiceControl.Audit.Persistence.InMemory/InMemoryAuditDataStore.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,11 @@
99
using ServiceControl.Audit.Auditing.BodyStorage;
1010
using ServiceControl.Audit.Auditing.MessagesView;
1111
using ServiceControl.Audit.Infrastructure;
12-
using ServiceControl.Audit.Monitoring;
13-
using ServiceControl.Audit.Persistence.Infrastructure;
14-
using ServiceControl.Audit.Persistence.Monitoring;
1512
using ServiceControl.SagaAudit;
1613

1714
class InMemoryAuditDataStore : IAuditDataStore
1815
{
1916
IBodyStorage bodyStorage;
20-
public List<KnownEndpoint> knownEndpoints;
2117
public List<FailedAuditImport> failedAuditImports;
2218

2319
public InMemoryAuditDataStore(IBodyStorage bodyStorage)
@@ -26,7 +22,6 @@ public InMemoryAuditDataStore(IBodyStorage bodyStorage)
2622
sagaHistories = [];
2723
messageViews = [];
2824
processedMessages = [];
29-
knownEndpoints = [];
3025
failedAuditImports = [];
3126
}
3227

@@ -176,25 +171,6 @@ Task<MessageBodyView> GetMessageBodyFromMetadata(string messageId)
176171
return Task.FromResult(MessageBodyView.FromString(body, contentType, bodySize, string.Empty));
177172
}
178173

179-
public async Task<QueryResult<IList<KnownEndpointsView>>> QueryKnownEndpoints(CancellationToken cancellationToken)
180-
{
181-
var knownEndpointsView = knownEndpoints
182-
.Select(x => new KnownEndpointsView
183-
{
184-
Id = DeterministicGuid.MakeId(x.Name, x.HostId.ToString()),
185-
EndpointDetails = new EndpointDetails
186-
{
187-
Host = x.Host,
188-
HostId = x.HostId,
189-
Name = x.Name
190-
},
191-
HostDisplayName = x.Host
192-
})
193-
.ToList();
194-
195-
return await Task.FromResult(new QueryResult<IList<KnownEndpointsView>>(knownEndpointsView, new QueryStatsInfo(string.Empty, knownEndpointsView.Count)));
196-
}
197-
198174
public Task<QueryResult<IList<AuditCount>>> QueryAuditCounts(string endpointName, CancellationToken cancellationToken)
199175
{
200176
var results = messageViews

src/ServiceControl.Audit.Persistence.InMemory/InMemoryAuditIngestionUnitOfWork.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using Auditing.BodyStorage;
77
using ServiceControl.Audit.Auditing;
8-
using ServiceControl.Audit.Persistence.Monitoring;
98
using ServiceControl.Audit.Persistence.UnitOfWork;
109
using ServiceControl.SagaAudit;
1110

@@ -16,12 +15,6 @@ class InMemoryAuditIngestionUnitOfWork(
1615
{
1716
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
1817

19-
public Task RecordKnownEndpoint(KnownEndpoint knownEndpoint, CancellationToken cancellationToken)
20-
{
21-
dataStore.knownEndpoints.Add(knownEndpoint);
22-
return Task.CompletedTask;
23-
}
24-
2518
public async Task RecordProcessedMessage(ProcessedMessage processedMessage, ReadOnlyMemory<byte> body, CancellationToken cancellationToken)
2619
{
2720
if (!body.IsEmpty)

src/ServiceControl.Audit.Persistence.RavenDB/RavenAuditDataStore.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
using Auditing.MessagesView;
99
using Extensions;
1010
using Indexes;
11-
using Monitoring;
1211
using Raven.Client.Documents;
1312
using ServiceControl.Audit.Auditing;
1413
using ServiceControl.Audit.Infrastructure;
15-
using ServiceControl.Audit.Monitoring;
16-
using ServiceControl.Audit.Persistence.Infrastructure;
1714
using ServiceControl.SagaAudit;
1815
using Transformers;
1916

@@ -125,27 +122,6 @@ public async Task<MessageBodyView> GetMessageBody(string messageId, Cancellation
125122
);
126123
}
127124

128-
public async Task<QueryResult<IList<KnownEndpointsView>>> QueryKnownEndpoints(CancellationToken cancellationToken)
129-
{
130-
using var session = await sessionProvider.OpenSession(cancellationToken: cancellationToken);
131-
var endpoints = await session.Advanced.LoadStartingWithAsync<KnownEndpoint>(KnownEndpoint.CollectionName, pageSize: 1024, token: cancellationToken);
132-
133-
var knownEndpoints = endpoints
134-
.Select(x => new KnownEndpointsView
135-
{
136-
Id = DeterministicGuid.MakeId(x.Name, x.HostId.ToString()),
137-
EndpointDetails = new EndpointDetails
138-
{
139-
Host = x.Host,
140-
HostId = x.HostId,
141-
Name = x.Name
142-
},
143-
HostDisplayName = x.Host
144-
})
145-
.ToList();
146-
147-
return new QueryResult<IList<KnownEndpointsView>>(knownEndpoints, new QueryStatsInfo(string.Empty, knownEndpoints.Count));
148-
}
149125

150126
public async Task<QueryResult<IList<AuditCount>>> QueryAuditCounts(string endpointName, CancellationToken cancellationToken)
151127
{

src/ServiceControl.Audit.Persistence.RavenDB/UnitOfWork/RavenAuditIngestionUnitOfWork.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Threading.Tasks;
77
using Auditing;
88
using Auditing.BodyStorage;
9-
using Monitoring;
109
using NServiceBus;
1110
using Persistence.UnitOfWork;
1211
using Raven.Client;
@@ -50,9 +49,6 @@ MetadataAsDictionary GetExpirationMetadata() =>
5049
public Task RecordSagaSnapshot(SagaSnapshot sagaSnapshot, CancellationToken cancellationToken)
5150
=> bulkInsert.StoreAsync(sagaSnapshot, GetExpirationMetadata());
5251

53-
public Task RecordKnownEndpoint(KnownEndpoint knownEndpoint, CancellationToken cancellationToken)
54-
=> bulkInsert.StoreAsync(knownEndpoint, GetExpirationMetadata());
55-
5652
public async ValueTask DisposeAsync()
5753
{
5854
await bulkInsert.DisposeAsync();

src/ServiceControl.Audit.Persistence.Tests.RavenDB/EmbeddedLifecycleTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Threading.Tasks;
66
using NUnit.Framework;
7+
using ServiceControl.Audit.Infrastructure;
78
using ServiceControl.Audit.Persistence.RavenDB;
89
using TestHelper;
910

@@ -35,7 +36,7 @@ public override async Task Setup()
3536
[Test]
3637
public async Task Verify_embedded_database()
3738
{
38-
await DataStore.QueryKnownEndpoints(TestContext.CurrentContext.CancellationToken);
39+
await DataStore.GetMessages(false, new PagingInfo(), new SortInfo("Id", "asc"), cancellationToken: TestContext.CurrentContext.CancellationToken);
3940

4041
using (Assert.EnterMultipleScope())
4142
{

src/ServiceControl.Audit.Persistence.Tests.RavenDB/RetentionTests.cs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Collections.Generic;
55
using System.Threading.Tasks;
66
using Auditing;
7-
using Monitoring;
87
using NServiceBus;
98
using NUnit.Framework;
109
using SagaAudit;
@@ -44,36 +43,6 @@ public async Task AuditMessageRetention()
4443
}
4544
}
4645

47-
[Test]
48-
public async Task KnownEndpointRetention()
49-
{
50-
var knownEndpoint = new KnownEndpoint()
51-
{
52-
Host = "Myself",
53-
HostId = Guid.NewGuid(),
54-
Id = "KnownEndpoints/1234123",
55-
LastSeen = DateTime.UtcNow,
56-
Name = "Wazowsky"
57-
};
58-
59-
await IngestKnownEndpoints(
60-
knownEndpoint
61-
);
62-
63-
var queryResultBeforeExpiration = await DataStore.QueryKnownEndpoints(TestContext.CurrentContext.CancellationToken);
64-
65-
await Task.Delay(4000);
66-
67-
var queryResultAfterExpiration = await DataStore.QueryKnownEndpoints(TestContext.CurrentContext.CancellationToken);
68-
69-
Assert.That(queryResultBeforeExpiration.Results, Has.Count.EqualTo(1));
70-
using (Assert.EnterMultipleScope())
71-
{
72-
Assert.That(queryResultBeforeExpiration.Results[0].EndpointDetails.Name, Is.EqualTo("Wazowsky"));
73-
Assert.That(queryResultAfterExpiration.Results.Count, Is.EqualTo(0));
74-
}
75-
}
76-
7746
[Test]
7847
public async Task SagaSnapshotRetention()
7948
{
@@ -147,17 +116,6 @@ async Task IngestProcessedMessagesAudits(params ProcessedMessage[] processedMess
147116
await configuration.CompleteDBOperation();
148117
}
149118

150-
async Task IngestKnownEndpoints(params KnownEndpoint[] knownEndpoints)
151-
{
152-
var unitOfWork = await StartAuditUnitOfWork(knownEndpoints.Length);
153-
foreach (var knownEndpoint in knownEndpoints)
154-
{
155-
await unitOfWork.RecordKnownEndpoint(knownEndpoint);
156-
}
157-
await unitOfWork.DisposeAsync();
158-
await configuration.CompleteDBOperation();
159-
}
160-
161119
async Task IngestSagaAudits(params SagaSnapshot[] snapshots)
162120
{
163121
var unitOfWork = await StartAuditUnitOfWork(snapshots.Length);

src/ServiceControl.Audit.Persistence.Tests/KnownEndpointsTests.cs

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/ServiceControl.Audit.Persistence/IAuditDataStore.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
public interface IAuditDataStore
1414
{
15-
Task<QueryResult<IList<KnownEndpointsView>>> QueryKnownEndpoints(CancellationToken cancellationToken);
1615
Task<QueryResult<SagaHistory>> QuerySagaHistoryById(Guid input, CancellationToken cancellationToken);
1716
Task<QueryResult<IList<MessagesView>>> GetMessages(bool includeSystemMessages, PagingInfo pagingInfo, SortInfo sortInfo, DateTimeRange timeSentRange = null, CancellationToken cancellationToken = default);
1817
Task<QueryResult<IList<MessagesView>>> QueryMessages(string searchParam, PagingInfo pagingInfo, SortInfo sortInfo, DateTimeRange timeSentRange = null, CancellationToken cancellationToken = default);

src/ServiceControl.Audit.Persistence/Monitoring/KnownEndpoint.cs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/ServiceControl.Audit.Persistence/UnitOfWork/IAuditIngestionUnitOfWork.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
using System.Threading;
55
using System.Threading.Tasks;
66
using Auditing;
7-
using Monitoring;
87
using ServiceControl.SagaAudit;
98

109
public interface IAuditIngestionUnitOfWork : IAsyncDisposable
1110
{
1211
Task RecordProcessedMessage(ProcessedMessage processedMessage, ReadOnlyMemory<byte> body = default, CancellationToken cancellationToken = default);
1312
Task RecordSagaSnapshot(SagaSnapshot sagaSnapshot, CancellationToken cancellationToken = default);
14-
Task RecordKnownEndpoint(KnownEndpoint knownEndpoint, CancellationToken cancellationToken = default);
1513
}
1614
}

0 commit comments

Comments
 (0)