Skip to content

Commit 29a1b7d

Browse files
Fix logs for autoentities (#3299)
## Why make this change? - Closes #3263 - Closes #3264 - Closes #3265 Currently some of the logs for autoentities are not completely clear or they are too noisy. Which is why the messages need to be changed. ## What is this change? This changes the log messages so they are more clear by adding `' '` to the definition names from the autoentities, and stating that they are definition names beforehand. We also change the name from `Autoentities` to `autoentities` in the logs so that they are all consistent. Lastly we also change some of the logs from `Information` to `Debug`. ## How was this tested? Tested locally since all the changes are related to the messages written in the logs.
1 parent 209b2cd commit 29a1b7d

6 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/Cli/ConfigGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,7 +3268,7 @@ public static bool TrySimulateAutoentities(AutoConfigSimulateOptions options, Fi
32683268

32693269
if (runtimeConfig.DataSource.DatabaseType != DatabaseType.MSSQL)
32703270
{
3271-
_logger.LogError("Autoentities simulation is only supported for MSSQL databases. Current database type: {DatabaseType}.", runtimeConfig.DataSource.DatabaseType);
3271+
_logger.LogError("The autoentities simulation is only supported for MSSQL databases. Current database type: {DatabaseType}.", runtimeConfig.DataSource.DatabaseType);
32723272
return false;
32733273
}
32743274

@@ -3360,7 +3360,7 @@ public static bool TrySimulateAutoentities(AutoConfigSimulateOptions options, Fi
33603360
/// <param name="results">The simulation results keyed by filter (definition) name.</param>
33613361
private static void WriteSimulationResultsToConsole(Dictionary<string, List<(string EntityName, string SchemaName, string ObjectName)>> results)
33623362
{
3363-
Console.WriteLine("AutoEntities Simulation Results");
3363+
Console.WriteLine("Autoentities Simulation Results");
33643364
Console.WriteLine();
33653365

33663366
foreach ((string filterName, List<(string EntityName, string SchemaName, string ObjectName)> matches) in results)

src/Config/ObjectModel/RuntimeConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public string GetDataSourceNameFromAutoentityName(string autoentityName)
507507
if (!_autoentityNameToDataSourceName.TryGetValue(autoentityName, out string? autoentityDataSource))
508508
{
509509
throw new DataApiBuilderException(
510-
message: $"{autoentityName} is not a valid autoentity.",
510+
message: $"'{autoentityName}' is not a valid autoentities definition.",
511511
statusCode: HttpStatusCode.NotFound,
512512
subStatusCode: DataApiBuilderException.SubStatusCodes.EntityNotFound);
513513
}

src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
305305
foreach ((string autoentityName, Autoentity autoentity) in autoentities)
306306
{
307307
int addedEntities = 0;
308-
JsonArray? resultArray = await QueryAutoentitiesAsync(autoentity);
308+
JsonArray? resultArray = await QueryAutoentitiesAsync(autoentityName, autoentity);
309309
if (resultArray is null)
310310
{
311311
continue;
@@ -316,7 +316,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
316316
if (resultObject is null)
317317
{
318318
throw new DataApiBuilderException(
319-
message: $"Cannot create new entity from autoentity pattern due to an internal error.",
319+
message: $"Cannot create new entity from autoentities definition '{autoentityName}' due to an internal error.",
320320
statusCode: HttpStatusCode.InternalServerError,
321321
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
322322
}
@@ -329,7 +329,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
329329

330330
if (string.IsNullOrWhiteSpace(entityName) || string.IsNullOrWhiteSpace(objectName) || string.IsNullOrWhiteSpace(schemaName))
331331
{
332-
_logger.LogError("Skipping autoentity generation: entity_name or object is null or empty for autoentity pattern '{AutoentityName}'.", autoentityName);
332+
_logger.LogError("Skipping autoentity generation: 'entity_name', 'object', or 'schema' is null or empty for autoentities definition '{autoentityName}'.", autoentityName);
333333
continue;
334334
}
335335

@@ -357,7 +357,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
357357
if (!entities.TryAdd(entityName, generatedEntity) || !runtimeConfig.TryAddGeneratedAutoentityNameToDataSourceName(entityName, autoentityName))
358358
{
359359
throw new DataApiBuilderException(
360-
message: $"Entity with name '{entityName}' already exists. Cannot create new entity from autoentity pattern with definition-name '{autoentityName}'.",
360+
message: $"Entity with name '{entityName}' already exists. Cannot create new entity from autoentities definition '{autoentityName}'.",
361361
statusCode: HttpStatusCode.BadRequest,
362362
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
363363
}
@@ -376,14 +376,14 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
376376

377377
if (addedEntities == 0)
378378
{
379-
_logger.LogWarning("No new entities were generated from the autoentity {autoentityName} defined in the configuration.", autoentityName);
379+
_logger.LogWarning("No new entities were generated from the autoentities definition '{autoentityName}'.", autoentityName);
380380
}
381381
}
382382

383383
_runtimeConfigProvider.AddMergedEntitiesToConfig(entities);
384384
}
385385

386-
public async Task<JsonArray?> QueryAutoentitiesAsync(Autoentity autoentity)
386+
public async Task<JsonArray?> QueryAutoentitiesAsync(string autoentityName, Autoentity autoentity)
387387
{
388388
string include = string.Join(",", autoentity.Patterns.Include);
389389
string exclude = string.Join(",", autoentity.Patterns.Exclude);
@@ -396,10 +396,10 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
396396
{ $"{BaseQueryStructure.PARAM_NAME_PREFIX}name_pattern", new(namePattern, null, SqlDbType.NVarChar) }
397397
};
398398

399-
_logger.LogInformation("Query for Autoentities is being executed with the following parameters.");
400-
_logger.LogInformation($"Autoentities include pattern: {include}");
401-
_logger.LogInformation($"Autoentities exclude pattern: {exclude}");
402-
_logger.LogInformation($"Autoentities name pattern: {namePattern}");
399+
_logger.LogDebug("Query for autoentities is being executed with the following parameters.");
400+
_logger.LogDebug("The autoentities definition '{autoentityName}' include pattern: {include}", autoentityName, include);
401+
_logger.LogDebug("The autoentities definition '{autoentityName}' exclude pattern: {exclude}", autoentityName, exclude);
402+
_logger.LogDebug("The autoentities definition '{autoentityName}' name pattern: {namePattern}", autoentityName, namePattern);
403403

404404
JsonArray? resultArray = await QueryExecutor.ExecuteQueryAsync(
405405
sqltext: getAutoentitiesQuery,

src/Core/Services/MetadataProviders/SqlMetadataProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ private void GenerateDatabaseObjectForEntities()
717717
/// </summary>
718718
protected virtual Task GenerateAutoentitiesIntoEntities(IReadOnlyDictionary<string, Autoentity>? autoentities)
719719
{
720-
throw new NotSupportedException($"{GetType().Name} does not support Autoentities yet.");
720+
throw new NotSupportedException($"{GetType().Name} does not support autoentities yet.");
721721
}
722722

723723
/// <summary>

src/Service.Tests/Configuration/ConfigurationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5611,7 +5611,7 @@ public async Task TestAutoentitiesAreGeneratedIntoEntities(bool useEntities, int
56115611
/// <returns></returns>
56125612
[TestCategory(TestCategory.MSSQL)]
56135613
[DataTestMethod]
5614-
[DataRow("publishers", "uniqueSingularPublisher", "uniquePluralPublishers", "/unique/publisher", "Entity with name 'publishers' already exists. Cannot create new entity from autoentity pattern with definition-name 'PublisherAutoEntity'.", DisplayName = "Autoentities fail due to entity name")]
5614+
[DataRow("publishers", "uniqueSingularPublisher", "uniquePluralPublishers", "/unique/publisher", "Entity with name 'publishers' already exists. Cannot create new entity from autoentities definition 'PublisherAutoEntity'.", DisplayName = "Autoentities fail due to entity name")]
56155615
[DataRow("UniquePublisher", "publishers", "uniquePluralPublishers", "/unique/publisher", "Entity publishers generates queries/mutation that already exist", DisplayName = "Autoentities fail due to graphql singular type")]
56165616
[DataRow("UniquePublisher", "uniqueSingularPublisher", "publishers", "/unique/publisher", "Entity publishers generates queries/mutation that already exist", DisplayName = "Autoentities fail due to graphql plural type")]
56175617
[DataRow("UniquePublisher", "uniqueSingularPublisher", "uniquePluralPublishers", "/publishers", "The rest path: publishers specified for entity: publishers is already used by another entity.", DisplayName = "Autoentities fail due to rest path")]

src/Service.Tests/UnitTests/SqlMetadataProviderUnitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ public async Task CheckAutoentitiesQuery(string[] include, string[] exclude, str
634634

635635
// Act
636636
MsSqlMetadataProvider metadataProvider = (MsSqlMetadataProvider)_sqlMetadataProvider;
637-
JsonArray resultArray = await metadataProvider.QueryAutoentitiesAsync(autoentity);
637+
JsonArray resultArray = await metadataProvider.QueryAutoentitiesAsync("autoentity", autoentity);
638638

639639
// Assert
640640
Assert.IsNotNull(resultArray);

0 commit comments

Comments
 (0)