Skip to content

Commit 5b252bd

Browse files
Allows linking nodes in the message flow view as a fallback when no link could be established on OriginatingEndpoint / ProcessingEndpoint mismatch (#1171)
* Allows linking nodes if originating message is not an event in case there is no match on child.RelatedTo = parent.Id && child.OriginatingEndpoint = parent.ProcessingEndpoint * Implemented logging TODO's * Removed unneeded TODO * Resolved ESSENTIAL formatting fix IDE0055...... * Apply suggestions from code review Co-authored-by: Daniel Marbach <[email protected]> * Update src/ServiceInsight/MessageFlow/MessageFlowViewModel.cs * Using names instead of numbers for Serilog messages * Fix missing ToArray * Converted to switch for reabability of intent Co-authored-by: Daniel Marbach <[email protected]> # Conflicts: # src/ServiceInsight/MessageFlow/MessageFlowViewModel.cs
1 parent ec4a7a7 commit 5b252bd

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/ServiceInsight/Framework/Logging/LoggingConfig.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Serilog.Events;
1414
using Serilog.Filters;
1515
using ServiceControl;
16+
using ServiceInsight.MessageFlow;
1617

1718
public static class LoggingConfig
1819
{
@@ -31,7 +32,7 @@ public static void SetupLogging()
3132
.WriteTo.Trace(outputTemplate: "[{Level}] ({SourceContext}) {Message}{NewLine}{Exception}")
3233
.WriteTo.Logger(lc => lc
3334
.MinimumLevel.Verbose()
34-
.Filter.ByIncludingOnly(MatchingTypes(typeof(DefaultServiceControl), typeof(CustomMessageViewerResolver)))
35+
.Filter.ByIncludingOnly(MatchingTypes(typeof(DefaultServiceControl), typeof(CustomMessageViewerResolver), typeof(MessageFlowViewModel)))
3536
.WriteTo.Observers(logEvents => logEvents
3637
.ObserveOn(TaskPoolScheduler.Default)
3738
.Do(LogWindowViewModel.LogObserver)

src/ServiceInsight/Framework/UI/ScreenManager/ServiceInsightWindowManager.cs

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ protected override Window CreateWindow(object rootModel, bool isDialog, object c
107107

108108
static MessageChoice GetMessageChoice(MessageBoxButton button)
109109
{
110-
//TODO: Use map to avoid switch/case
111110
MessageChoice choices;
112111
switch (button)
113112
{

src/ServiceInsight/MessageFlow/MessageFlowViewModel.cs

+34-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Linq;
77
using System.Threading.Tasks;
88
using System.Windows.Input;
9+
using Anotar.Serilog;
910
using Autofac;
1011
using Caliburn.Micro;
1112
using Mindscape.WpfDiagramming;
@@ -259,18 +260,44 @@ void LinkConversationNodes(IEnumerable<MessageNode> relatedMessagesTask)
259260
{
260261
foreach (var msg in relatedMessagesTask)
261262
{
262-
if (msg.Message.RelatedToMessageId == null &&
263-
msg.Message.RelatedToMessageId != msg.Message.MessageId)
263+
if (string.IsNullOrEmpty(msg.Message.RelatedToMessageId) && msg.Message.RelatedToMessageId != msg.Message.MessageId)
264264
{
265265
continue;
266266
}
267267

268-
// [CM] I don't know how it's happening, but a user reported an
269-
// error where multiple results were returned from this query.
270268
var parentMessages = nodeMap.Values.Where(m =>
271-
m.Message != null && m.Message.ReceivingEndpoint != null && m.Message.SendingEndpoint != null &&
272-
m.Message.MessageId == msg.Message.RelatedToMessageId &&
273-
m.Message.ReceivingEndpoint.Name == msg.Message.SendingEndpoint.Name);
269+
m.Message != null && m.Message.ReceivingEndpoint != null && m.Message.SendingEndpoint != null
270+
&& m.Message.MessageId == msg.Message.RelatedToMessageId
271+
&& m.Message.ReceivingEndpoint.Name == msg.Message.SendingEndpoint.Name // Needed with publishes as identical events can be consumed by multiple endpoints
272+
)
273+
.ToArray();
274+
275+
// Fallback, get "parent" when originating message is not an event (publish)
276+
if (!parentMessages.Any())
277+
{
278+
parentMessages = nodeMap.Values.Where(m =>
279+
m.Message != null && m.Message.ReceivingEndpoint != null && m.Message.SendingEndpoint != null &&
280+
m.Message.MessageId == msg.Message.RelatedToMessageId && m.Message.MessageIntent != MessageIntent.Publish
281+
).ToArray();
282+
283+
if (parentMessages.Any())
284+
{
285+
LogTo.Warning("Fall back to match only on RelatedToMessageId for message with Id '{MessageId}' matched but link could be invalid.", msg.Message.MessageId);
286+
}
287+
}
288+
289+
switch (parentMessages.Length)
290+
{
291+
case 0:
292+
LogTo.Information("No parent could be resolved for the message with Id '{MessageId}' which has RelatedToMessageId set. This can happen if the parent has been purged due to retention expiration, an ServiceControl node to be unavailable, or because the parent message not been stored (yet).", msg.Message.MessageId);
293+
break;
294+
case 1:
295+
// Log nothing, this is what it should be
296+
break;
297+
default:
298+
LogTo.Error("Multiple parents matched for message id '{MessageId}' possibly due to more-than-once processing, linking to all as it is unknown which processing attempt generated the message.", msg.Message.MessageId);
299+
break;
300+
}
274301

275302
foreach (var parentMessage in parentMessages)
276303
{

0 commit comments

Comments
 (0)