From e2ac4cfdf5f2d12ff51e2376db27835a03dbc091 Mon Sep 17 00:00:00 2001 From: Jesper Justesen <1972142+FirestarJes@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:14:25 +0200 Subject: [PATCH 1/2] chore: Add logging of query and params (#28) * Add logging of query and params * Update DatabricksSqlQueryBuilder.cs * Update DatabricksSqlQueryBuilder.cs * Update DatabricksSqlQueryBuilder.cs * Added loggerfactory * Log executed sql as information * Update host.json --- .../Orchestration.SettlementReports/host.json | 3 +++ .../Experimental/DatabricksContextBase.cs | 6 ++++-- .../Experimental/DatabricksSqlQueryBuilder.cs | 13 +++++++++++-- .../DatabricksSqlQueryExecutor.cs | 6 ++++-- .../SettlementReportDatabricksContext.cs | 6 ++++-- ...eportFileRequestHandlerIntegrationTests.cs | 19 +++++++++++++------ ...tReportChargeLinkPeriodsRepositoryTests.cs | 6 +++++- ...lementReportChargePricesRepositoryTests.cs | 6 +++++- ...lementReportEnergyResultRepositoryTests.cs | 6 +++++- ...tMeteringPointMasterDataRepositoryTests.cs | 6 +++++- ...ingPointTimeSeriesResultRepositoryTests.cs | 6 +++++- ...ementReportMonthlyAmountRepositoryTests.cs | 6 +++++- ...ReportMonthlyAmountTotalRepositoryTests.cs | 6 +++++- ...ettlementReportWholesaleRepositoryTests.cs | 6 +++++- 14 files changed, 79 insertions(+), 22 deletions(-) diff --git a/source/settlement-report/Orchestration.SettlementReports/host.json b/source/settlement-report/Orchestration.SettlementReports/host.json index d635d6a..07be6d1 100644 --- a/source/settlement-report/Orchestration.SettlementReports/host.json +++ b/source/settlement-report/Orchestration.SettlementReports/host.json @@ -12,6 +12,9 @@ "isEnabled": true, "excludedTypes": "Request" }, + "logLevel": { + "default": "Information" + }, "enableLiveMetricsFilters": true } } diff --git a/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksContextBase.cs b/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksContextBase.cs index 219c49a..cae6a7e 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksContextBase.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksContextBase.cs @@ -20,6 +20,7 @@ using Microsoft.EntityFrameworkCore.Query; using Microsoft.EntityFrameworkCore.Query.SqlExpressions; using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Energinet.DataHub.SettlementReport.Infrastructure.Experimental; @@ -31,10 +32,11 @@ public abstract class DatabricksContextBase : IDisposable protected DatabricksContextBase( DatabricksSqlWarehouseQueryExecutor databricksSqlWarehouseQueryExecutor, - IOptions options) + IOptions options, + ILoggerFactory loggerFactory) { _dbContext = new DbContextCore(OnModelCreating); - _executor = new DatabricksSqlQueryExecutor(_dbContext, databricksSqlWarehouseQueryExecutor, options); + _executor = new DatabricksSqlQueryExecutor(_dbContext, databricksSqlWarehouseQueryExecutor, options, loggerFactory); } public void Dispose() diff --git a/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryBuilder.cs b/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryBuilder.cs index 2a92a1a..43e9ddd 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryBuilder.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryBuilder.cs @@ -20,6 +20,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Energinet.DataHub.SettlementReport.Infrastructure.Experimental; @@ -28,11 +29,16 @@ public sealed class DatabricksSqlQueryBuilder { private readonly DbContext _context; private readonly IOptions _options; + private readonly ILogger _logger; - public DatabricksSqlQueryBuilder(DbContext context, IOptions options) + public DatabricksSqlQueryBuilder( + DbContext context, + IOptions options, + ILoggerFactory loggerFactory) { _context = context; _options = options; + _logger = loggerFactory.CreateLogger(); } public DatabricksStatement Build(DatabricksSqlQueryable query) @@ -101,7 +107,10 @@ private string PrepareSqlStatement(DatabricksSqlQueryable query, Func $"Parameter Name: {x.Key} | Value: {x.Value}")); + _logger.LogInformation(logString); + return translated; } private string TranslateTransactToAnsi(StringBuilder transactSqlQuery) diff --git a/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryExecutor.cs b/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryExecutor.cs index 8cb86cf..11263ba 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryExecutor.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/Experimental/DatabricksSqlQueryExecutor.cs @@ -17,6 +17,7 @@ using Energinet.DataHub.Core.Databricks.SqlStatementExecution.Formats; using Energinet.DataHub.SettlementReport.Common.Infrastructure.Options; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Energinet.DataHub.SettlementReport.Infrastructure.Experimental; @@ -30,9 +31,10 @@ public sealed class DatabricksSqlQueryExecutor public DatabricksSqlQueryExecutor( DbContext dbContext, DatabricksSqlWarehouseQueryExecutor databricksSqlWarehouseQueryExecutor, - IOptions options) + IOptions options, + ILoggerFactory loggerFactory) { - _sqlQueryBuilder = new DatabricksSqlQueryBuilder(dbContext, options); + _sqlQueryBuilder = new DatabricksSqlQueryBuilder(dbContext, options, loggerFactory); _sqlRowHydrator = new DatabricksSqlRowHydrator(); _databricksSqlWarehouseQueryExecutor = databricksSqlWarehouseQueryExecutor; } diff --git a/source/settlement-report/SettlementReports.Infrastructure/Persistence/Databricks/SettlementReportDatabricksContext.cs b/source/settlement-report/SettlementReports.Infrastructure/Persistence/Databricks/SettlementReportDatabricksContext.cs index 0acea5e..dfc910a 100644 --- a/source/settlement-report/SettlementReports.Infrastructure/Persistence/Databricks/SettlementReportDatabricksContext.cs +++ b/source/settlement-report/SettlementReports.Infrastructure/Persistence/Databricks/SettlementReportDatabricksContext.cs @@ -16,6 +16,7 @@ using Energinet.DataHub.SettlementReport.Common.Infrastructure.Options; using Energinet.DataHub.SettlementReport.Infrastructure.Experimental; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace Energinet.DataHub.SettlementReport.Infrastructure.Persistence.Databricks; @@ -26,8 +27,9 @@ public sealed class SettlementReportDatabricksContext : DatabricksContextBase, I public SettlementReportDatabricksContext( IOptions deltaTableOptions, - DatabricksSqlWarehouseQueryExecutor sqlWarehouseQueryExecutor) - : base(sqlWarehouseQueryExecutor, deltaTableOptions) + DatabricksSqlWarehouseQueryExecutor sqlWarehouseQueryExecutor, + ILoggerFactory loggerFactory) + : base(sqlWarehouseQueryExecutor, deltaTableOptions, loggerFactory) { _deltaTableOptions = deltaTableOptions; } diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs index bbd0d35..5a6163e 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Application/SettlementReports/SettlementReportFileRequestHandlerIntegrationTests.cs @@ -22,6 +22,8 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Options; using Moq; using NodaTime; @@ -58,7 +60,7 @@ public SettlementReportFileRequestHandlerIntegrationTests( Fixture.Inject(mockedOptions); var sqlWarehouseQueryExecutor = _databricksSqlStatementApiFixture.GetDatabricksExecutor(); - var databricksContext = new SettlementReportDatabricksContext(mockedOptions.Object, sqlWarehouseQueryExecutor); + var databricksContext = new SettlementReportDatabricksContext(mockedOptions.Object, sqlWarehouseQueryExecutor, NullLoggerFactory.Instance); var settlementReportDataRepository = new SettlementReportEnergyResultRepository(databricksContext); var settlementReportWholesaleRepository = new SettlementReportWholesaleRepository(databricksContext); @@ -66,23 +68,28 @@ public SettlementReportFileRequestHandlerIntegrationTests( var settlementReportMeteringPointMasterDataRepository = new SettlementReportMeteringPointMasterDataRepository(new SettlementReportDatabricksContext( mockedOptions.Object, - sqlWarehouseQueryExecutor)); + sqlWarehouseQueryExecutor, + NullLoggerFactory.Instance)); var settlementReportMeteringPointTimeSeriesResultRepository = new SettlementReportMeteringPointTimeSeriesResultRepository(new SettlementReportDatabricksContext( mockedOptions.Object, - sqlWarehouseQueryExecutor)); + sqlWarehouseQueryExecutor, + NullLoggerFactory.Instance)); var settlementReportMonthlyAmountRepository = new SettlementReportMonthlyAmountRepository(new SettlementReportDatabricksContext( mockedOptions.Object, - sqlWarehouseQueryExecutor)); + sqlWarehouseQueryExecutor, + NullLoggerFactory.Instance)); var settlementReportChargePriceRepository = new SettlementReportChargePriceRepository(new SettlementReportDatabricksContext( mockedOptions.Object, - sqlWarehouseQueryExecutor)); + sqlWarehouseQueryExecutor, + NullLoggerFactory.Instance)); var settlementReportMonthlyAmountTotalRepository = new SettlementReportMonthlyAmountTotalRepository(new SettlementReportDatabricksContext( mockedOptions.Object, - sqlWarehouseQueryExecutor)); + sqlWarehouseQueryExecutor, + NullLoggerFactory.Instance)); Fixture.Inject(new SettlementReportFileGeneratorFactory( settlementReportDataRepository, diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargeLinkPeriodsRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargeLinkPeriodsRepositoryTests.cs index cb6f481..a8874e4 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargeLinkPeriodsRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargeLinkPeriodsRepositoryTests.cs @@ -21,6 +21,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; using FluentAssertions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -39,7 +42,8 @@ public SettlementReportChargeLinkPeriodsRepositoryTests(MigrationsFreeDatabricks Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargePricesRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargePricesRepositoryTests.cs index 103c405..763c7de 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargePricesRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportChargePricesRepositoryTests.cs @@ -20,6 +20,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -50,7 +53,8 @@ public SettlementReportChargePricesRepositoryTests(MigrationsFreeDatabricksSqlSt Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportEnergyResultRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportEnergyResultRepositoryTests.cs index 0a4d75c..6d423bc 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportEnergyResultRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportEnergyResultRepositoryTests.cs @@ -20,6 +20,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -38,7 +41,8 @@ public SettlementReportEnergyResultRepositoryTests(MigrationsFreeDatabricksSqlSt Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepositoryTests.cs index 5d6264a..a4f1071 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointMasterDataRepositoryTests.cs @@ -21,6 +21,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; using FluentAssertions; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -39,7 +42,8 @@ public SettlementReportMeteringPointMasterDataRepositoryTests(MigrationsFreeData Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointTimeSeriesResultRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointTimeSeriesResultRepositoryTests.cs index 638db09..fc9c854 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointTimeSeriesResultRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMeteringPointTimeSeriesResultRepositoryTests.cs @@ -21,6 +21,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -39,7 +42,8 @@ public SettlementReportMeteringPointTimeSeriesResultRepositoryTests(MigrationsFr Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountRepositoryTests.cs index aa93945..cef0810 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountRepositoryTests.cs @@ -20,6 +20,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -38,7 +41,8 @@ public SettlementReportMonthlyAmountRepositoryTests(MigrationsFreeDatabricksSqlS Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountTotalRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountTotalRepositoryTests.cs index bcf9955..f59d8b8 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountTotalRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportMonthlyAmountTotalRepositoryTests.cs @@ -20,6 +20,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -38,7 +41,8 @@ public SettlementReportMonthlyAmountTotalRepositoryTests(MigrationsFreeDatabrick Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] diff --git a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportWholesaleRepositoryTests.cs b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportWholesaleRepositoryTests.cs index 5dd89fc..092cfc7 100644 --- a/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportWholesaleRepositoryTests.cs +++ b/source/settlement-report/SettlementReports.IntegrationTests/Infrastructure/SettlementReports_v2/SettlementReportWholesaleRepositoryTests.cs @@ -20,6 +20,9 @@ using Energinet.DataHub.SettlementReport.Interfaces.Models; using Energinet.DataHub.SettlementReport.Interfaces.SettlementReports_v2.Models; using Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Fixtures; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Moq; using Xunit; namespace Energinet.DataHub.Wholesale.CalculationResults.IntegrationTests.Infrastructure.SettlementReports_v2; @@ -38,7 +41,8 @@ public SettlementReportWholesaleRepositoryTests(MigrationsFreeDatabricksSqlState Fixture.Inject(new SettlementReportDatabricksContext( _databricksSqlStatementApiFixture.DatabricksSchemaManager.DeltaTableOptions, - _databricksSqlStatementApiFixture.GetDatabricksExecutor())); + _databricksSqlStatementApiFixture.GetDatabricksExecutor(), + NullLoggerFactory.Instance)); } [Fact(Skip = "Performance testing")] From 415af41b57045a150334703c0b4e66dd5b4653c1 Mon Sep 17 00:00:00 2001 From: Vitalie Belinschi <55790049+vbelinschi@users.noreply.github.com> Date: Mon, 23 Sep 2024 08:27:11 +0200 Subject: [PATCH 2/2] reduce concurrent activity functions in host.json (#25) --- .../SettlementReportListHttpTrigger.cs | 24 ++++++++++++------- .../Orchestration.SettlementReports/host.json | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/source/settlement-report/Orchestration.SettlementReports/Functions/SettlementReports/SettlementReportListHttpTrigger.cs b/source/settlement-report/Orchestration.SettlementReports/Functions/SettlementReports/SettlementReportListHttpTrigger.cs index 31736d9..01a1700 100644 --- a/source/settlement-report/Orchestration.SettlementReports/Functions/SettlementReports/SettlementReportListHttpTrigger.cs +++ b/source/settlement-report/Orchestration.SettlementReports/Functions/SettlementReports/SettlementReportListHttpTrigger.cs @@ -99,16 +99,22 @@ private async Task> CheckStatusOfSettl { var updatedReport = settlementReport; - if (settlementReport.Status == SettlementReportStatus.InProgress && settlementReport.JobId == null) + var instanceInfo = await durableTaskClient + .GetInstanceAsync(settlementReport.RequestId.Id, getInputsAndOutputs: true) + .ConfigureAwait(false); + + if (instanceInfo == null) + { + // If the orchestration instance is not found, we assume it is running on the other orchestration, + // either the heavy or the light one + continue; + } + + if (settlementReport.Status == SettlementReportStatus.InProgress) { - var instanceInfo = await durableTaskClient - .GetInstanceAsync(settlementReport.RequestId.Id, getInputsAndOutputs: true) - .ConfigureAwait(false); - - if (instanceInfo == null || instanceInfo.RuntimeStatus - is not OrchestrationRuntimeStatus.Running - and not OrchestrationRuntimeStatus.Pending - and not OrchestrationRuntimeStatus.Suspended) + if (instanceInfo.RuntimeStatus + is OrchestrationRuntimeStatus.Terminated + or OrchestrationRuntimeStatus.Failed) { await _updateFailedSettlementReportsHandler .UpdateFailedReportAsync(settlementReport.RequestId) diff --git a/source/settlement-report/Orchestration.SettlementReports/host.json b/source/settlement-report/Orchestration.SettlementReports/host.json index 07be6d1..4e18ee8 100644 --- a/source/settlement-report/Orchestration.SettlementReports/host.json +++ b/source/settlement-report/Orchestration.SettlementReports/host.json @@ -2,7 +2,7 @@ "version": "2.0", "extensions": { "durableTask": { - "maxConcurrentActivityFunctions": 6, + "maxConcurrentActivityFunctions": 2, "hubName": "%OrchestrationsTaskHubName%" } },