Skip to content

Commit

Permalink
chore: log incoming message execution time (#1414)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsDue authored Dec 10, 2024
1 parent 2fa8a45 commit f52e219
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/B2BApi/IncomingMessages/IncomingMessageReceiver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics;
using System.Net;
using System.Text;
using Energinet.DataHub.EDI.AuditLog.AuditLogger;
Expand Down Expand Up @@ -55,6 +56,7 @@ public async Task<HttpResponseData> RunAsync(
CancellationToken hostCancellationToken)
{
ArgumentNullException.ThrowIfNull(request);
var stopwatch = Stopwatch.StartNew();
var cancellationToken = request.GetCancellationToken(hostCancellationToken);

if (!await _featureFlagManager.ReceiveMeteredDataForMeasurementPointsAsync().ConfigureAwait(false))
Expand Down Expand Up @@ -113,6 +115,9 @@ public async Task<HttpResponseData> RunAsync(
var httpResponseData = await CreateResponseAsync(request, httpStatusCode, documentFormat, responseMessage)
.ConfigureAwait(false);

stopwatch.Stop();
_logger.LogInformation($"IncomingMessage Execution time: {stopwatch.ElapsedMilliseconds} ms");

return httpResponseData;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics;
using Energinet.DataHub.EDI.ArchivedMessages.Interfaces;
using Energinet.DataHub.EDI.ArchivedMessages.Interfaces.Models;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Authentication;
Expand Down Expand Up @@ -78,12 +79,18 @@ public async Task<ResponseMessage> ReceiveIncomingMarketMessageAsync(
{
ArgumentNullException.ThrowIfNull(documentType);
ArgumentNullException.ThrowIfNull(incomingMarketMessageStream);
var stopwatch = Stopwatch.StartNew();

var incomingMarketMessageParserResult = await ParseIncomingMessageAsync(
incomingMarketMessageStream,
incomingDocumentFormat,
documentType,
cancellationToken)
.ConfigureAwait(false);

stopwatch.Stop();
_logger.LogInformation($"IncomingMessage Parsing execution time: {stopwatch.ElapsedMilliseconds} ms");

if (incomingMarketMessageParserResult.Errors.Count != 0
|| incomingMarketMessageParserResult.IncomingMessage == null)
{
Expand All @@ -99,21 +106,30 @@ public async Task<ResponseMessage> ReceiveIncomingMarketMessageAsync(

if (ShouldArchive(documentType))
{
stopwatch.Restart();
await ArchiveIncomingMessageAsync(
incomingMarketMessageStream,
incomingMarketMessageParserResult.IncomingMessage,
documentType,
cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
_logger.LogInformation($"IncomingMessage Archiving execution time: {stopwatch.ElapsedMilliseconds} ms");
}

stopwatch.Restart();
await _delegateIncomingMessage
.DelegateAsync(incomingMarketMessageParserResult.IncomingMessage, documentType, cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
_logger.LogInformation($"IncomingMessage Delegation execution time: {stopwatch.ElapsedMilliseconds} ms");

stopwatch.Restart();
var validationResult = await _validateIncomingMessage
.ValidateAsync(incomingMarketMessageParserResult.IncomingMessage, incomingDocumentFormat, cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
_logger.LogInformation($"IncomingMessage Validation execution time: {stopwatch.ElapsedMilliseconds} ms");

if (!validationResult.Success)
{
Expand All @@ -124,11 +140,14 @@ await _delegateIncomingMessage
return _responseFactory.From(validationResult, responseDocumentFormat);
}

stopwatch.Restart();
var result = await _incomingMessageReceiver
.ReceiveAsync(
incomingMarketMessageParserResult.IncomingMessage,
cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
_logger.LogInformation($"IncomingMessage Receiving execution time: {stopwatch.ElapsedMilliseconds} ms");

if (result.Success)
{
Expand Down

0 comments on commit f52e219

Please sign in to comment.