Skip to content

Commit 29aaddf

Browse files
authored
Fix measuring duration of processor and command (#3040)
I noticed this when i had my migration run for a long time and at the end I wanted to know, how long it really took. The migration duration was zero. ## Processor Although the log outputs `Duration` of the processor activity, this is always zero. Its because `Duration` is not dynamic – it does not return real current duration. Its value is calculated and updated only when `Stop()` is called. ## Command base Basically the same problem as in `Processor`, but from the other side. The activity is stopped immediately after it is started, so it reports zero duration at the end. Even when the telemetry is disabled, there is no need to not measure duration of the command. Because even wihout telemetry, we want to see duration in the log outputs. And `Stop()` basically does nothing just updates duration. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Enhanced activity lifecycle management within telemetry and processing workflows. * Removed unused code dependencies. * **Style** * Minor formatting improvements. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 9a8779e + 6964aea commit 29aaddf

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/MigrationTools.Host/Commands/CommandBase.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public sealed override async Task<int> ExecuteAsync(CommandContext context, TSet
6565
{
6666
Log.Debug("Disabling Telemetry {CommandName}", this.GetType().Name);
6767
CommandActivity.AddTag("DisableTelemetry", settings.DisableTelemetry);
68-
CommandActivity.Stop();
6968
ActivitySourceProvider.DisableActivitySource();
7069
}
7170
//Enable Debug Trace
@@ -105,7 +104,7 @@ public sealed override async Task<int> ExecuteAsync(CommandContext context, TSet
105104

106105
internal virtual Task<int> ExecuteInternalAsync(CommandContext context, TSettings settings)
107106
{
108-
return Task.FromResult( 0);
107+
return Task.FromResult(0);
109108
}
110109

111110
public void RunStartupLogic(TSettings settings)

src/MigrationTools/Processors/Infrastructure/Processor.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.ComponentModel.Design;
43
using System.Diagnostics;
54
using System.Linq;
65
using Microsoft.Extensions.DependencyInjection;
76
using Microsoft.Extensions.Logging;
87
using Microsoft.Extensions.Options;
9-
using MigrationTools._EngineV1.Configuration;
108
using MigrationTools.Endpoints;
11-
using MigrationTools.Endpoints.Infrastructure;
129
using MigrationTools.Enrichers;
1310
using MigrationTools.Exceptions;
1411
using MigrationTools.Services;
@@ -139,6 +136,7 @@ public void Execute()
139136
}
140137
finally
141138
{
139+
ProcessorActivity.Stop();
142140
Log.LogInformation("{ProcessorName} completed in {ProcessorDuration} ", Name, ProcessorActivity.Duration.ToString("c"));
143141
}
144142

@@ -172,4 +170,4 @@ protected static void AddParameter(string name, IDictionary<string, string> stor
172170
if (!store.ContainsKey(name)) store.Add(name, value);
173171
}
174172
}
175-
}
173+
}

0 commit comments

Comments
 (0)