Skip to content

Commit

Permalink
Merge branch 'main' into mwo/add-doc-val-to-rsm-12-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MWO1024 authored Dec 11, 2024
2 parents 547521f + acb21cb commit afbe20a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Diagnostics;
using Energinet.DataHub.EDI.BuildingBlocks.Domain.Models;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Abstractions;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Validation;
using Energinet.DataHub.EDI.IncomingMessages.Domain.Validation.ValidationErrors;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Repositories.MessageId;
using Energinet.DataHub.EDI.IncomingMessages.Infrastructure.Repositories.TransactionId;
using Microsoft.Extensions.Logging;

namespace Energinet.DataHub.EDI.IncomingMessages.Application.UseCases;

Expand All @@ -28,7 +30,8 @@ public class ValidateIncomingMessage(
IMessageTypeValidator messageTypeValidator,
IProcessTypeValidator processTypeValidator,
IBusinessTypeValidator businessTypeValidator,
ITransactionIdRepository transactionIdRepository)
ITransactionIdRepository transactionIdRepository,
ILogger<ValidateIncomingMessage> logger)
{
private const int MaxMessageIdLength = 36;
private const int MaxTransactionIdLength = 36;
Expand All @@ -54,8 +57,11 @@ public async Task<Result> ValidateAsync(
// It is slightly annoying since all we do is FirstOrDefaultAsync which we await.
// And read access shouldn't be that much of a problem wrt concurrency.
// It is also a bit silly to have this as a separate call, but it works.
var stopwatch = Stopwatch.StartNew();
var transactionIdErrors =
await CheckTransactionIdsAsync(incomingMessage, cancellationToken).ConfigureAwait(false);
stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage CheckTransactionIdsAsync execution time: {stopwatch.ElapsedMilliseconds} ms");

var allErrors = errors.Concat(transactionIdErrors).ToArray();

Expand All @@ -64,20 +70,26 @@ public async Task<Result> ValidateAsync(

private async Task<IReadOnlyCollection<ValidationError>> AuthorizeSenderAsync(IIncomingMessage message)
{
var stopwatch = Stopwatch.StartNew();
var allSeriesAreDelegated = message.Series.Count > 0 && message.Series.All(s => s.IsDelegated);

var result = await senderAuthorizer
.AuthorizeAsync(message, allSeriesAreDelegated)
.ConfigureAwait(false);
stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage AuthorizeSenderAsync execution time: {stopwatch.ElapsedMilliseconds} ms");

return result.Errors;
}

private async Task<IReadOnlyCollection<ValidationError>> VerifyReceiverAsync(IIncomingMessage message)
{
var stopwatch = Stopwatch.StartNew();
var receiverVerification = await receiverValidator
.VerifyAsync(message.ReceiverNumber, message.ReceiverRoleCode)
.ConfigureAwait(false);
stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage VerifyReceiverAsync execution time: {stopwatch.ElapsedMilliseconds} ms");

return receiverVerification.Errors;
}
Expand All @@ -86,6 +98,7 @@ private async Task<IReadOnlyCollection<ValidationError>> CheckMessageIdAsync(
IIncomingMessage message,
CancellationToken cancellationToken)
{
var stopwatch = Stopwatch.StartNew();
var errors = new List<ValidationError>();

if (string.IsNullOrEmpty(message.MessageId))
Expand All @@ -104,15 +117,21 @@ private async Task<IReadOnlyCollection<ValidationError>> CheckMessageIdAsync(
errors.Add(new DuplicateMessageIdDetected(message.MessageId));
}

stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage CheckMessageIdAsync execution time: {stopwatch.ElapsedMilliseconds} ms");

return errors;
}

private async Task<IReadOnlyCollection<ValidationError>> CheckMessageTypeAsync(
IIncomingMessage message,
CancellationToken cancellationToken)
{
var stopwatch = Stopwatch.StartNew();
var result = await messageTypeValidator.ValidateAsync(message, cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage CheckMessageTypeAsync execution time: {stopwatch.ElapsedMilliseconds} ms");
return result.Errors;
}

Expand All @@ -121,17 +140,23 @@ private async Task<IReadOnlyCollection<ValidationError>> CheckBusinessReasonAsyn
DocumentFormat documentFormat,
CancellationToken cancellationToken)
{
var stopwatch = Stopwatch.StartNew();
var result = await processTypeValidator.ValidateAsync(message, documentFormat, cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage CheckBusinessReasonAsync execution time: {stopwatch.ElapsedMilliseconds} ms");
return result.Errors;
}

private async Task<IReadOnlyCollection<ValidationError>> CheckBusinessTypeAsync(
IIncomingMessage message,
CancellationToken cancellationToken)
{
var stopwatch = Stopwatch.StartNew();
var result = await businessTypeValidator.ValidateAsync(message.BusinessType, cancellationToken)
.ConfigureAwait(false);
stopwatch.Stop();
logger.LogInformation($"ValidateIncomingMessage CheckBusinessTypeAsync execution time: {stopwatch.ElapsedMilliseconds} ms");
return result.Errors;
}

Expand Down

0 comments on commit afbe20a

Please sign in to comment.