Skip to content

Commit 74be0ca

Browse files
Remove excess logs in dab validate command (#3651)
## Why make this change? - Solves issue #3266 ## What is this change? Remove excessive logs when the user uses `dab validate`. This includes: - Removing unnecessary one-liner information logs - Reducing warning logs so that only more general warnings appear (e.g. logs related to entities missing `field` descriptions when using MCP) - Only showing certain relevant information logs when the user uses `dab start`. All of this is done in order to ensure that the logs in `dab validate` are not cluttered. (e.g. logs related to REST paths for entities when enabled) - Removed logs assertion in tests that used it, as those logs were removed. ## How was this tested? - [ ] Integration Tests - [ ] Unit Tests - [x] Manual Tests Tested manually by running `dab validate` and seeing that the logs are as expected, and ran `dab start` to ensure previous logs didn't change. ## Sample Request(s) Previous `dab validate` logs: <img width="959" height="442" alt="image" src="https://github.com/user-attachments/assets/4d13c362-5e7d-4a82-93a2-0282719b5913" /> New `dab validate` logs: <img width="1469" height="266" alt="image" src="https://github.com/user-attachments/assets/d15db9be-098c-4e8c-bc6d-6a67e54f6570" />
1 parent 71e7f6a commit 74be0ca

8 files changed

Lines changed: 85 additions & 59 deletions

File tree

src/Cli.Tests/ValidateConfigTests.cs

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ public void TestCleanup()
4040
Environment.SetEnvironmentVariable($"database-type", null);
4141
Environment.SetEnvironmentVariable($"sp_param1_int", null);
4242
Environment.SetEnvironmentVariable($"sp_param2_bool", null);
43+
44+
// Set output back to the default for other tests.
45+
Console.SetOut(new StreamWriter(Console.OpenStandardOutput())
46+
{
47+
AutoFlush = true
48+
});
49+
Console.SetError(new StreamWriter(Console.OpenStandardError())
50+
{
51+
AutoFlush = true
52+
});
4353
}
4454

4555
/// <summary>
@@ -294,9 +304,6 @@ public void ValidateConfigSchemaWhereConfigReferencesEnvironmentVariables()
294304
Assert.IsFalse(
295305
condition: loggerOutput.Contains("Failed to validate config against schema due to"),
296306
message: "Unexpected errors encountered when validating config schema in RuntimeConfigValidator::ValidateConfigSchema(...).");
297-
Assert.IsTrue(
298-
condition: loggerOutput.Contains("The config satisfies the schema requirements."),
299-
message: "RuntimeConfigValidator::ValidateConfigSchema(...) didn't communicate successful config schema validation.");
300307
}
301308

302309
/// <summary>
@@ -405,6 +412,37 @@ public void TestValidateNonRootZeroEntitiesWithInvalidConnectionString()
405412
Assert.IsFalse(isValid);
406413
}
407414

415+
/// <summary>
416+
/// Tests that logs related to suppressed messages do not appear.
417+
/// </summary>
418+
[TestMethod]
419+
public async Task TestValidateSuppressedLogsDoNotAppear()
420+
{
421+
// Arrange
422+
StringWriter writer = new();
423+
Console.SetOut(writer);
424+
425+
string config = AddPropertiesToJson(INITIAL_CONFIG, SINGLE_ENTITY);
426+
427+
((MockFileSystem)_fileSystem!).AddFile(
428+
path: TEST_RUNTIME_CONFIG_FILE,
429+
mockFile: config);
430+
ValidateOptions validateOptions = new(TEST_RUNTIME_CONFIG_FILE);
431+
432+
// Act
433+
Utils.LoggerFactoryForCli = Utils.GetLoggerFactoryForCli();
434+
ConfigGenerator.IsConfigValid(validateOptions, _runtimeConfigLoader!, _fileSystem!);
435+
436+
// Assert
437+
string loggerOutput = writer.ToString();
438+
Assert.IsTrue(
439+
condition: !loggerOutput.Contains("REST path:"),
440+
message: "RuntimeConfigValidator should not contain any messages indicating REST path for individual entities");
441+
Assert.IsTrue(
442+
condition: !loggerOutput.Contains("REST calls are disabled for the entity:"),
443+
message: "RuntimeConfigValidator should not contain any messages related to REST calls for individual entities");
444+
}
445+
408446
/// <summary>
409447
/// Validates that a root config (with data-source-files pointing to children)
410448
/// that has no data-source and no entities is considered structurally valid

src/Cli/Commands/ValidateOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSy
3838
}
3939
else
4040
{
41-
logger.LogError("Config is invalid.");
41+
logger.LogInformation("Config is invalid.");
4242
}
4343

4444
return isValidConfig ? CliReturnCode.SUCCESS : CliReturnCode.GENERAL_ERROR;

src/Cli/ConfigGenerator.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,8 +3166,6 @@ public static bool IsConfigValid(ValidateOptions options, FileSystemRuntimeConfi
31663166
return false;
31673167
}
31683168

3169-
_logger.LogInformation("Validating config file: {runtimeConfigFile}", runtimeConfigFile);
3170-
31713169
RuntimeConfigProvider runtimeConfigProvider = new(loader);
31723170

31733171
if (!runtimeConfigProvider.TryGetConfig(out RuntimeConfig? _))
@@ -3196,14 +3194,21 @@ public static bool IsConfigValid(ValidateOptions options, FileSystemRuntimeConfi
31963194
bool mcpEnabled = config.IsMcpEnabled;
31973195
if (mcpEnabled)
31983196
{
3197+
bool missingFields = false;
31993198
foreach (KeyValuePair<string, Entity> entity in config.Entities)
32003199
{
32013200
if (entity.Value.Fields == null || !entity.Value.Fields.Any())
32023201
{
3203-
_logger.LogWarning($"Entity '{entity.Key}' is missing 'fields' definition while MCP is enabled. " +
3204-
"It's recommended to define fields explicitly to ensure optimal performance with MCP.");
3202+
missingFields = true;
3203+
_logger.LogDebug($"Entity '{entity.Key}' is missing 'fields' definition while MCP is enabled.");
32053204
}
32063205
}
3206+
3207+
if (missingFields)
3208+
{
3209+
_logger.LogWarning("One or more entities are missing `fields` definition while MCP is enabled. " +
3210+
"It's recommended to define fields explicitly to ensure optimal performance with MCP.");
3211+
}
32073212
}
32083213

32093214
// Warn if Unauthenticated provider is used with authenticated or custom roles

src/Core/Configurations/JsonConfigSchemaValidator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public JsonSchemaValidationResult ValidateJsonConfigWithSchema(string jsonSchema
4848

4949
if (isValid)
5050
{
51-
_logger!.LogInformation("The config satisfies the schema requirements.");
5251
return new(isValid: true, errors: null);
5352
}
5453
else

src/Core/Configurations/RuntimeConfigValidator.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ public async Task<bool> TryValidateConfig(
475475
ValidateConfigProperties();
476476
ValidatePermissionsInConfig(runtimeConfig);
477477

478-
_logger.LogInformation("Validating entity relationships.");
479478
ValidateRelationshipConfigCorrectness(runtimeConfig);
480479

481480
// This function initializes the metadata providers which in turn validates the connectivity to the

src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,19 @@ public override async Task PopulateTriggerMetadataForTable(string entityName, st
8181
if ("UPDATE".Equals(type_desc))
8282
{
8383
sourceDefinition.IsUpdateDMLTriggerEnabled = true;
84-
_logger.LogInformation($"An update trigger is enabled for the entity: {entityName}");
84+
if (!_isValidateOnly)
85+
{
86+
_logger.LogInformation($"An update trigger is enabled for the entity: {entityName}");
87+
}
8588
}
8689

8790
if ("INSERT".Equals(type_desc))
8891
{
8992
sourceDefinition.IsInsertDMLTriggerEnabled = true;
90-
_logger.LogInformation($"An insert trigger is enabled for the entity: {entityName}");
93+
if (!_isValidateOnly)
94+
{
95+
_logger.LogInformation($"An insert trigger is enabled for the entity: {entityName}");
96+
}
9197
}
9298
}
9399
}
@@ -362,15 +368,6 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
362368
subStatusCode: DataApiBuilderException.SubStatusCodes.ErrorInInitialization);
363369
}
364370

365-
if (runtimeConfig.IsRestEnabled)
366-
{
367-
_logger.LogInformation("[{entity}] REST path: {globalRestPath}/{entityRestPath}", entityName, runtimeConfig.RestPath, entityName);
368-
}
369-
else
370-
{
371-
_logger.LogInformation(message: "REST calls are disabled for the entity: {entity}", entityName);
372-
}
373-
374371
addedEntities++;
375372
}
376373

@@ -383,6 +380,7 @@ protected override async Task GenerateAutoentitiesIntoEntities(IReadOnlyDictiona
383380
runtimeConfig.AutoentityResolutionCounts[autoentityName] = addedEntities;
384381
}
385382

383+
LogRestPathsForEntities(runtimeConfig, entities);
386384
_runtimeConfigProvider.AddMergedEntitiesToConfig(entities);
387385
}
388386

src/Core/Services/MetadataProviders/SqlMetadataProvider.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,7 @@ public SqlMetadataProvider(
123123
_databaseType = runtimeConfig.GetDataSourceFromDataSourceName(dataSourceName).DatabaseType;
124124
_logger = logger;
125125
_isValidateOnly = isValidateOnly;
126-
foreach ((string entityName, Entity entityMetatdata) in Entities)
127-
{
128-
if (runtimeConfig.IsRestEnabled)
129-
{
130-
string restPath = entityMetatdata.Rest?.Path ?? entityName;
131-
_logger.LogInformation("[{entity}] REST path: {globalRestPath}/{entityRestPath}", entityName, runtimeConfig.RestPath, restPath);
132-
}
133-
else
134-
{
135-
_logger.LogInformation(message: "REST calls are disabled for the entity: {entity}", entityName);
136-
}
137-
}
126+
LogRestPathsForEntities(runtimeConfig, Entities);
138127

139128
ConnectionString = runtimeConfig.GetDataSourceFromDataSourceName(dataSourceName).ConnectionString;
140129
EntitiesDataSet = new();
@@ -1019,6 +1008,30 @@ protected virtual void PopulateMetadataForLinkingObject(
10191008
return;
10201009
}
10211010

1011+
/// <summary>
1012+
/// Helper method that logs the REST paths for all entities and shows if the REST calls are enabled/disabled for any entity.
1013+
/// </summary>
1014+
/// <param name="runtimeConfig"></param>
1015+
/// <param name="entities"></param>
1016+
protected void LogRestPathsForEntities(RuntimeConfig runtimeConfig, IReadOnlyDictionary<string, Entity> entities)
1017+
{
1018+
if (!_isValidateOnly)
1019+
{
1020+
foreach ((string entityName, Entity entityMetatdata) in entities)
1021+
{
1022+
if (runtimeConfig.IsRestEnabled)
1023+
{
1024+
string restPath = entityMetatdata.Rest?.Path ?? entityName;
1025+
_logger.LogInformation("[{entity}] REST path: {globalRestPath}/{entityRestPath}", entityName, runtimeConfig.RestPath, restPath);
1026+
}
1027+
else
1028+
{
1029+
_logger.LogInformation(message: "REST calls are disabled for the entity: {entity}", entityName);
1030+
}
1031+
}
1032+
}
1033+
}
1034+
10221035
/// <summary>
10231036
/// Adds a new foreign key definition for the target entity in the relationship metadata.
10241037
/// The last argument "relationshipData" is modified (hydrated with the new foreign key definition)

src/Service.Tests/Configuration/ConfigurationTests.cs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,6 @@ public async Task TestSqlMetadataValidationForEntitiesWithInvalidSource()
18561856
/// <summary>
18571857
/// This test method validates a sample DAB runtime config file against DAB's JSON schema definition.
18581858
/// It asserts that the validation is successful and there are no validation failures.
1859-
/// It also verifies that the expected log message is logged.
18601859
/// </summary>
18611860
[TestMethod("Validates the config file schema."), TestCategory(TestCategory.MSSQL)]
18621861
public void TestConfigSchemaIsValid()
@@ -1874,20 +1873,11 @@ public void TestConfigSchemaIsValid()
18741873
JsonSchemaValidationResult result = jsonSchemaValidator.ValidateJsonConfigWithSchema(jsonSchema, jsonData);
18751874
Assert.IsTrue(result.IsValid);
18761875
Assert.IsTrue(EnumerableUtilities.IsNullOrEmpty(result.ValidationErrors));
1877-
schemaValidatorLogger.Verify(
1878-
x => x.Log(
1879-
LogLevel.Information,
1880-
It.IsAny<EventId>(),
1881-
It.Is<It.IsAnyType>((o, t) => o.ToString()!.Contains($"The config satisfies the schema requirements.")),
1882-
It.IsAny<Exception>(),
1883-
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()),
1884-
Times.Once);
18851876
}
18861877

18871878
/// <summary>
18881879
/// This test method validates a sample DAB runtime config file against DAB's JSON schema definition.
18891880
/// It asserts that the validation is successful and there are no validation failures when no optional fields are used.
1890-
/// It also verifies that the expected log message is logged.
18911881
/// </summary>
18921882
[DataTestMethod]
18931883
[DataRow(CONFIG_FILE_WITH_NO_OPTIONAL_FIELD, DisplayName = "Validates schema of the config file with no optional fields.")]
@@ -1906,14 +1896,6 @@ public void TestBasicConfigSchemaWithNoOptionalFieldsIsValid(string jsonData)
19061896
Assert.IsTrue(EnumerableUtilities.IsNullOrEmpty(result.ValidationErrors));
19071897

19081898
Assert.IsTrue(result.IsValid);
1909-
schemaValidatorLogger.Verify(
1910-
x => x.Log(
1911-
LogLevel.Information,
1912-
It.IsAny<EventId>(),
1913-
It.Is<It.IsAnyType>((o, t) => o.ToString()!.Contains($"The config satisfies the schema requirements.")),
1914-
It.IsAny<Exception>(),
1915-
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()),
1916-
Times.Once);
19171899
}
19181900

19191901
[DataTestMethod]
@@ -1940,14 +1922,6 @@ public void TestBasicConfigSchemaWithFlexibleBoolean(string Value)
19401922
Assert.IsTrue(EnumerableUtilities.IsNullOrEmpty(result.ValidationErrors), "Validation Erros null of empty");
19411923

19421924
Assert.IsTrue(result.IsValid, "Result should be valid");
1943-
schemaValidatorLogger.Verify(
1944-
x => x.Log(
1945-
LogLevel.Information,
1946-
It.IsAny<EventId>(),
1947-
It.Is<It.IsAnyType>((o, t) => o.ToString()!.Contains($"The config satisfies the schema requirements.")),
1948-
It.IsAny<Exception>(),
1949-
(Func<It.IsAnyType, Exception, string>)It.IsAny<object>()),
1950-
Times.Once);
19511925
}
19521926

19531927
/// <summary>

0 commit comments

Comments
 (0)