From 333e63b88fbb763745da770b474d267a48cd6587 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 18:08:16 +0000 Subject: [PATCH 1/9] Initial plan From c24904c5f0a992174f8b2bd234123cecfdfd714a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 18:13:56 +0000 Subject: [PATCH 2/9] Initial exploration and planning for file sink telemetry feature Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com> --- global.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/global.json b/global.json index 08b8436e55..0e5b329395 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.411", + "version": "8.0.117", "rollForward": "latestFeature" } } From c258d60d99af8d4d31c13c94d095f488b5f440ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 18:34:30 +0000 Subject: [PATCH 3/9] Implement file sink telemetry configuration for CLI Co-authored-by: RubenCerna2079 <32799214+RubenCerna2079@users.noreply.github.com> --- schemas/dab.draft.schema.json | 34 ++++ src/Cli.Tests/ConfigureOptionsTests.cs | 215 +++++++++++++++++++++ src/Cli/Commands/ConfigureOptions.cs | 26 +++ src/Cli/ConfigGenerator.cs | 97 ++++++++++ src/Config/ObjectModel/FileOptions.cs | 37 ++++ src/Config/ObjectModel/TelemetryOptions.cs | 2 +- 6 files changed, 410 insertions(+), 1 deletion(-) create mode 100644 src/Config/ObjectModel/FileOptions.cs diff --git a/schemas/dab.draft.schema.json b/schemas/dab.draft.schema.json index 692b82b642..61fc4c19b9 100644 --- a/schemas/dab.draft.schema.json +++ b/schemas/dab.draft.schema.json @@ -410,6 +410,40 @@ }, "required": ["endpoint"] }, + "file": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "description": "Enable/disable file sink telemetry logging.", + "default": false + }, + "path": { + "type": "string", + "description": "File path for telemetry logs.", + "default": "/logs/dab-log.txt" + }, + "rolling-interval": { + "type": "string", + "description": "Rolling interval for log files.", + "default": "day", + "enum": ["hour", "day", "week"] + }, + "retained-file-count-limit": { + "type": "integer", + "description": "Maximum number of retained log files.", + "default": 1, + "minimum": 1 + }, + "file-size-limit-bytes": { + "type": "integer", + "description": "Maximum file size in bytes before rolling.", + "default": 1048576, + "minimum": 1 + } + } + }, "log-level": { "type": "object", "description": "Global configuration of log level, defines logging severity levels for specific classes, when 'null' it will set logging level based on 'host: mode' property", diff --git a/src/Cli.Tests/ConfigureOptionsTests.cs b/src/Cli.Tests/ConfigureOptionsTests.cs index 8ee064e262..886e240615 100644 --- a/src/Cli.Tests/ConfigureOptionsTests.cs +++ b/src/Cli.Tests/ConfigureOptionsTests.cs @@ -819,5 +819,220 @@ private void SetupFileSystemWithInitialConfig(string jsonConfig) Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(jsonConfig, out RuntimeConfig? config)); Assert.IsNotNull(config.Runtime); } + + /// + /// Tests that running "dab configure --runtime.telemetry.file.enabled" on a config with various values results + /// in runtime config update. Takes in updated value for telemetry file enabled and + /// validates whether the runtime config reflects those updated values + /// + [DataTestMethod] + [DataRow(true, DisplayName = "Enable file sink telemetry.")] + [DataRow(false, DisplayName = "Disable file sink telemetry.")] + public void TestUpdateTelemetryFileEnabled(bool updatedEnabledValue) + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + // Act: Attempts to update file enabled flag + ConfigureOptions options = new( + runtimeTelemetryFileEnabled: updatedEnabledValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate the Enabled Flag is updated + Assert.IsTrue(isSuccess); + string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); + Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.Enabled); + Assert.AreEqual(updatedEnabledValue, runtimeConfig.Runtime.Telemetry.File.Enabled); + } + + /// + /// Tests that running "dab configure --runtime.telemetry.file.path" on a config with various values results + /// in runtime config update. Takes in updated value for telemetry file path and + /// validates whether the runtime config reflects those updated values + /// + [DataTestMethod] + [DataRow("/logs/custom-dab.log", DisplayName = "Update file path to custom location.")] + [DataRow("/var/log/dab-application.log", DisplayName = "Update file path to var log directory.")] + [DataRow("./logs/dab.log", DisplayName = "Update file path to relative location.")] + public void TestUpdateTelemetryFilePath(string updatedPathValue) + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + // Act: Attempts to update file path value + ConfigureOptions options = new( + runtimeTelemetryFilePath: updatedPathValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate the Path is updated + Assert.IsTrue(isSuccess); + string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); + Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.Path); + Assert.AreEqual(updatedPathValue, runtimeConfig.Runtime.Telemetry.File.Path); + } + + /// + /// Tests that running "dab configure --runtime.telemetry.file.rolling-interval" on a config with various values results + /// in runtime config update. Takes in updated value for telemetry file rolling interval and + /// validates whether the runtime config reflects those updated values + /// + [DataTestMethod] + [DataRow(RollingInterval.Hour, DisplayName = "Update rolling interval to Hour.")] + [DataRow(RollingInterval.Day, DisplayName = "Update rolling interval to Day.")] + [DataRow(RollingInterval.Week, DisplayName = "Update rolling interval to Week.")] + public void TestUpdateTelemetryFileRollingInterval(RollingInterval updatedRollingIntervalValue) + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + // Act: Attempts to update rolling interval value + ConfigureOptions options = new( + runtimeTelemetryFileRollingInterval: updatedRollingIntervalValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate the Rolling Interval is updated + Assert.IsTrue(isSuccess); + string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); + Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.RollingInterval); + Assert.AreEqual(updatedRollingIntervalValue, runtimeConfig.Runtime.Telemetry.File.RollingInterval); + } + + /// + /// Tests that running "dab configure --runtime.telemetry.file.retained-file-count-limit" on a config with various values results + /// in runtime config update. Takes in updated value for retained file count limit and + /// validates whether the runtime config reflects those updated values + /// + [DataTestMethod] + [DataRow(1, DisplayName = "Update retained file count limit to 1.")] + [DataRow(7, DisplayName = "Update retained file count limit to 7.")] + [DataRow(30, DisplayName = "Update retained file count limit to 30.")] + public void TestUpdateTelemetryFileRetainedFileCountLimit(int updatedRetainedFileCountLimitValue) + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + // Act: Attempts to update retained file count limit value + ConfigureOptions options = new( + runtimeTelemetryFileRetainedFileCountLimit: updatedRetainedFileCountLimitValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate the Retained File Count Limit is updated + Assert.IsTrue(isSuccess); + string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); + Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.RetainedFileCountLimit); + Assert.AreEqual(updatedRetainedFileCountLimitValue, runtimeConfig.Runtime.Telemetry.File.RetainedFileCountLimit); + } + + /// + /// Tests that running "dab configure --runtime.telemetry.file.file-size-limit-bytes" on a config with various values results + /// in runtime config update. Takes in updated value for file size limit bytes and + /// validates whether the runtime config reflects those updated values + /// + [DataTestMethod] + [DataRow(1048576, DisplayName = "Update file size limit to 1MB.")] + [DataRow(10485760, DisplayName = "Update file size limit to 10MB.")] + [DataRow(104857600, DisplayName = "Update file size limit to 100MB.")] + public void TestUpdateTelemetryFileFileSizeLimitBytes(int updatedFileSizeLimitBytesValue) + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + // Act: Attempts to update file size limit bytes value + ConfigureOptions options = new( + runtimeTelemetryFileFileSizeLimitBytes: updatedFileSizeLimitBytesValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate the File Size Limit Bytes is updated + Assert.IsTrue(isSuccess); + string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); + Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.FileSizeLimitBytes); + Assert.AreEqual(updatedFileSizeLimitBytesValue, runtimeConfig.Runtime.Telemetry.File.FileSizeLimitBytes); + } + + /// + /// Tests that validation fails when invalid values are provided for retained file count limit and file size limit + /// + [DataTestMethod] + [DataRow(0, "retained-file-count-limit", DisplayName = "Fail when retained file count limit is 0.")] + [DataRow(-1, "retained-file-count-limit", DisplayName = "Fail when retained file count limit is negative.")] + [DataRow(0, "file-size-limit-bytes", DisplayName = "Fail when file size limit is 0.")] + [DataRow(-1, "file-size-limit-bytes", DisplayName = "Fail when file size limit is negative.")] + public void TestTelemetryFileConfigurationValidationFailures(int invalidValue, string optionType) + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + ConfigureOptions options; + if (optionType == "retained-file-count-limit") + { + options = new ConfigureOptions( + runtimeTelemetryFileRetainedFileCountLimit: invalidValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + } + else + { + options = new ConfigureOptions( + runtimeTelemetryFileFileSizeLimitBytes: invalidValue, + config: TEST_RUNTIME_CONFIG_FILE + ); + } + + // Act: Attempts to update with invalid value + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate that configuration fails + Assert.IsFalse(isSuccess); + } + + /// + /// Tests that multiple file sink telemetry options can be configured in a single command + /// + [TestMethod] + public void TestUpdateMultipleTelemetryFileOptions() + { + // Arrange -> all the setup which includes creating options. + SetupFileSystemWithInitialConfig(INITIAL_CONFIG); + + // Act: Attempts to update multiple file options at once + ConfigureOptions options = new( + runtimeTelemetryFileEnabled: true, + runtimeTelemetryFilePath: "/var/log/custom-dab.log", + runtimeTelemetryFileRollingInterval: RollingInterval.Week, + runtimeTelemetryFileRetainedFileCountLimit: 14, + runtimeTelemetryFileFileSizeLimitBytes: 52428800, + config: TEST_RUNTIME_CONFIG_FILE + ); + bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); + + // Assert: Validate all options are updated correctly + Assert.IsTrue(isSuccess); + string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); + Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); + + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File); + var fileOptions = runtimeConfig.Runtime.Telemetry.File; + + Assert.AreEqual(true, fileOptions.Enabled); + Assert.AreEqual("/var/log/custom-dab.log", fileOptions.Path); + Assert.AreEqual(RollingInterval.Week, fileOptions.RollingInterval); + Assert.AreEqual(14, fileOptions.RetainedFileCountLimit); + Assert.AreEqual(52428800, fileOptions.FileSizeLimitBytes); + } } } diff --git a/src/Cli/Commands/ConfigureOptions.cs b/src/Cli/Commands/ConfigureOptions.cs index a11d6b65f9..457701da15 100644 --- a/src/Cli/Commands/ConfigureOptions.cs +++ b/src/Cli/Commands/ConfigureOptions.cs @@ -42,6 +42,11 @@ public ConfigureOptions( string? runtimeHostAuthenticationProvider = null, string? runtimeHostAuthenticationJwtAudience = null, string? runtimeHostAuthenticationJwtIssuer = null, + bool? runtimeTelemetryFileEnabled = null, + string? runtimeTelemetryFilePath = null, + RollingInterval? runtimeTelemetryFileRollingInterval = null, + int? runtimeTelemetryFileRetainedFileCountLimit = null, + int? runtimeTelemetryFileFileSizeLimitBytes = null, string? config = null) : base(config) { @@ -72,6 +77,12 @@ public ConfigureOptions( RuntimeHostAuthenticationProvider = runtimeHostAuthenticationProvider; RuntimeHostAuthenticationJwtAudience = runtimeHostAuthenticationJwtAudience; RuntimeHostAuthenticationJwtIssuer = runtimeHostAuthenticationJwtIssuer; + // File Sink Telemetry + RuntimeTelemetryFileEnabled = runtimeTelemetryFileEnabled; + RuntimeTelemetryFilePath = runtimeTelemetryFilePath; + RuntimeTelemetryFileRollingInterval = runtimeTelemetryFileRollingInterval; + RuntimeTelemetryFileRetainedFileCountLimit = runtimeTelemetryFileRetainedFileCountLimit; + RuntimeTelemetryFileFileSizeLimitBytes = runtimeTelemetryFileFileSizeLimitBytes; } [Option("data-source.database-type", Required = false, HelpText = "Database type. Allowed values: MSSQL, PostgreSQL, CosmosDB_NoSQL, MySQL.")] @@ -140,6 +151,21 @@ public ConfigureOptions( [Option("runtime.host.authentication.jwt.issuer", Required = false, HelpText = "Configure the entity that issued the Jwt Token.")] public string? RuntimeHostAuthenticationJwtIssuer { get; } + [Option("runtime.telemetry.file.enabled", Required = false, HelpText = "Enable/disable file sink telemetry logging. Default: false (boolean).")] + public bool? RuntimeTelemetryFileEnabled { get; } + + [Option("runtime.telemetry.file.path", Required = false, HelpText = "File path for telemetry logs. Default: '/logs/dab-log.txt' (string).")] + public string? RuntimeTelemetryFilePath { get; } + + [Option("runtime.telemetry.file.rolling-interval", Required = false, HelpText = "Rolling interval for log files. Default: Day. Allowed values: Hour, Day, Week.")] + public RollingInterval? RuntimeTelemetryFileRollingInterval { get; } + + [Option("runtime.telemetry.file.retained-file-count-limit", Required = false, HelpText = "Maximum number of retained log files. Default: 1 (integer, minimum: 1).")] + public int? RuntimeTelemetryFileRetainedFileCountLimit { get; } + + [Option("runtime.telemetry.file.file-size-limit-bytes", Required = false, HelpText = "Maximum file size in bytes before rolling. Default: 1048576 (integer, minimum: 1).")] + public int? RuntimeTelemetryFileFileSizeLimitBytes { get; } + public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem) { logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion()); diff --git a/src/Cli/ConfigGenerator.cs b/src/Cli/ConfigGenerator.cs index 7655b84cee..7fc0781224 100644 --- a/src/Cli/ConfigGenerator.cs +++ b/src/Cli/ConfigGenerator.cs @@ -773,6 +773,29 @@ private static bool TryUpdateConfiguredRuntimeOptions( } } + // Telemetry File: Enabled, Path, Rolling-Interval, Retained-File-Count-Limit, File-Size-Limit-Bytes + if (options.RuntimeTelemetryFileEnabled != null || + options.RuntimeTelemetryFilePath != null || + options.RuntimeTelemetryFileRollingInterval != null || + options.RuntimeTelemetryFileRetainedFileCountLimit != null || + options.RuntimeTelemetryFileFileSizeLimitBytes != null) + { + TelemetryOptions? currentTelemetryOptions = runtimeConfig?.Runtime?.Telemetry; + Azure.DataApiBuilder.Config.ObjectModel.FileOptions? updatedFileOptions = currentTelemetryOptions?.File ?? new(); + bool status = TryUpdateConfiguredTelemetryFileValues(options, ref updatedFileOptions); + if (status) + { + TelemetryOptions updatedTelemetryOptions = currentTelemetryOptions is null + ? new TelemetryOptions(File: updatedFileOptions) + : currentTelemetryOptions with { File = updatedFileOptions }; + runtimeConfig = runtimeConfig! with { Runtime = runtimeConfig.Runtime! with { Telemetry = updatedTelemetryOptions } }; + } + else + { + return false; + } + } + return runtimeConfig != null; } @@ -1990,5 +2013,79 @@ public static bool TryAddTelemetry(AddTelemetryOptions options, FileSystemRuntim return WriteRuntimeConfigToFile(runtimeConfigFile, runtimeConfig, fileSystem); } + + /// + /// Attempts to update the Config parameters in the Telemetry File runtime settings based on the provided value. + /// Validates that any user-provided parameter value is valid and then returns true if the updated File options + /// need to be overwritten on the existing config parameters + /// + /// options. + /// updatedFileOptions. + /// True if the value needs to be updated in the runtime config, else false + private static bool TryUpdateConfiguredTelemetryFileValues( + ConfigureOptions options, + ref Azure.DataApiBuilder.Config.ObjectModel.FileOptions? updatedFileOptions) + { + object? updatedValue; + try + { + // Runtime.Telemetry.File.Enabled + updatedValue = options?.RuntimeTelemetryFileEnabled; + if (updatedValue != null) + { + updatedFileOptions = updatedFileOptions! with { Enabled = (bool)updatedValue }; + _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Enabled as '{updatedValue}'", updatedValue); + } + + // Runtime.Telemetry.File.Path + updatedValue = options?.RuntimeTelemetryFilePath; + if (updatedValue != null) + { + updatedFileOptions = updatedFileOptions! with { Path = (string)updatedValue }; + _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Path as '{updatedValue}'", updatedValue); + } + + // Runtime.Telemetry.File.Rolling-Interval + updatedValue = options?.RuntimeTelemetryFileRollingInterval; + if (updatedValue != null) + { + updatedFileOptions = updatedFileOptions! with { RollingInterval = (RollingInterval)updatedValue }; + _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Rolling-Interval as '{updatedValue}'", updatedValue); + } + + // Runtime.Telemetry.File.Retained-File-Count-Limit + updatedValue = options?.RuntimeTelemetryFileRetainedFileCountLimit; + if (updatedValue != null) + { + if ((int)updatedValue < 1) + { + _logger.LogError("Runtime.Telemetry.File.Retained-File-Count-Limit must be at least 1. Provided value: {updatedValue}", updatedValue); + return false; + } + updatedFileOptions = updatedFileOptions! with { RetainedFileCountLimit = (int)updatedValue }; + _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Retained-File-Count-Limit as '{updatedValue}'", updatedValue); + } + + // Runtime.Telemetry.File.File-Size-Limit-Bytes + updatedValue = options?.RuntimeTelemetryFileFileSizeLimitBytes; + if (updatedValue != null) + { + if ((int)updatedValue < 1) + { + _logger.LogError("Runtime.Telemetry.File.File-Size-Limit-Bytes must be at least 1. Provided value: {updatedValue}", updatedValue); + return false; + } + updatedFileOptions = updatedFileOptions! with { FileSizeLimitBytes = (int)updatedValue }; + _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.File-Size-Limit-Bytes as '{updatedValue}'", updatedValue); + } + + return true; + } + catch (Exception ex) + { + _logger.LogError("Failed to update RuntimeConfig.Telemetry.File with exception message: {exceptionMessage}.", ex.Message); + return false; + } + } } } diff --git a/src/Config/ObjectModel/FileOptions.cs b/src/Config/ObjectModel/FileOptions.cs new file mode 100644 index 0000000000..ef27920db7 --- /dev/null +++ b/src/Config/ObjectModel/FileOptions.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Text.Json.Serialization; + +namespace Azure.DataApiBuilder.Config.ObjectModel; + +/// +/// Represents the options for configuring file sink telemetry. +/// +public record FileOptions( + bool Enabled = false, + string Path = "/logs/dab-log.txt", + RollingInterval RollingInterval = RollingInterval.Day, + int RetainedFileCountLimit = 1, + int FileSizeLimitBytes = 1048576) +{ + [JsonPropertyName("rolling-interval")] + public RollingInterval RollingInterval { get; init; } = RollingInterval; + + [JsonPropertyName("retained-file-count-limit")] + public int RetainedFileCountLimit { get; init; } = RetainedFileCountLimit; + + [JsonPropertyName("file-size-limit-bytes")] + public int FileSizeLimitBytes { get; init; } = FileSizeLimitBytes; +} + +/// +/// Represents the rolling interval options for file sink. +/// +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum RollingInterval +{ + Hour, + Day, + Week +} \ No newline at end of file diff --git a/src/Config/ObjectModel/TelemetryOptions.cs b/src/Config/ObjectModel/TelemetryOptions.cs index ed2099f2a4..68c3d17b37 100644 --- a/src/Config/ObjectModel/TelemetryOptions.cs +++ b/src/Config/ObjectModel/TelemetryOptions.cs @@ -9,7 +9,7 @@ namespace Azure.DataApiBuilder.Config.ObjectModel; /// /// Represents the options for telemetry. /// -public record TelemetryOptions(ApplicationInsightsOptions? ApplicationInsights = null, OpenTelemetryOptions? OpenTelemetry = null, Dictionary? LoggerLevel = null) +public record TelemetryOptions(ApplicationInsightsOptions? ApplicationInsights = null, OpenTelemetryOptions? OpenTelemetry = null, FileOptions? File = null, Dictionary? LoggerLevel = null) { [JsonPropertyName("log-level")] public Dictionary? LoggerLevel { get; init; } = LoggerLevel; From 67b812b7f61ed0fa8b601bbbbe21f62bba385f1c Mon Sep 17 00:00:00 2001 From: Ruben Cerna Date: Sun, 6 Jul 2025 23:46:38 -0700 Subject: [PATCH 4/9] Fixed Copilot Changes --- global.json | 2 +- src/Cli/Commands/AddTelemetryOptions.cs | 30 +++++ src/Cli/Commands/ConfigureOptions.cs | 23 +--- src/Cli/ConfigGenerator.cs | 118 ++---------------- src/Cli/Properties/launchSettings.json | 4 +- src/Config/ObjectModel/FileOptions.cs | 37 ------ src/Config/ObjectModel/FileSinkOptions.cs | 25 ++++ .../FileSinkRollingIntervalMode.cs | 18 +++ src/Config/ObjectModel/TelemetryOptions.cs | 2 +- 9 files changed, 88 insertions(+), 171 deletions(-) delete mode 100644 src/Config/ObjectModel/FileOptions.cs create mode 100644 src/Config/ObjectModel/FileSinkOptions.cs create mode 100644 src/Config/ObjectModel/FileSinkRollingIntervalMode.cs diff --git a/global.json b/global.json index 0e5b329395..08b8436e55 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "8.0.117", + "version": "8.0.411", "rollForward": "latestFeature" } } diff --git a/src/Cli/Commands/AddTelemetryOptions.cs b/src/Cli/Commands/AddTelemetryOptions.cs index 8ec9313d14..f906db7429 100644 --- a/src/Cli/Commands/AddTelemetryOptions.cs +++ b/src/Cli/Commands/AddTelemetryOptions.cs @@ -27,6 +27,11 @@ public AddTelemetryOptions( string? openTelemetryHeaders = null, OtlpExportProtocol? openTelemetryExportProtocol = null, string? openTelemetryServiceName = null, + CliBool? fileSinkEnabled = null, + string? fileSinkPath = null, + RollingIntervalMode? fileSinkRollingInterval = null, + int? fileSinkRetainedFileCountLimit = null, + int? fileSinkFileSizeLimitBytes = null, string? config = null) : base(config) { AppInsightsConnString = appInsightsConnString; @@ -36,6 +41,11 @@ public AddTelemetryOptions( OpenTelemetryHeaders = openTelemetryHeaders; OpenTelemetryExportProtocol = openTelemetryExportProtocol; OpenTelemetryServiceName = openTelemetryServiceName; + FileSinkEnabled = fileSinkEnabled; + FileSinkPath = fileSinkPath; + FileSinkRollingInterval = fileSinkRollingInterval; + FileSinkRetainedFileCountLimit = fileSinkRetainedFileCountLimit; + FileSinkFileSizeLimitBytes = fileSinkFileSizeLimitBytes; } // Connection string for the Application Insights resource to which telemetry data should be sent. @@ -68,6 +78,26 @@ public AddTelemetryOptions( [Option("otel-service-name", Default = "dab", Required = false, HelpText = "(Default: dab) Headers for Open Telemetry for telemetry data")] public string? OpenTelemetryServiceName { get; } + // To specify whether File Sink telemetry should be enabled. This flag is optional and default value is false. + [Option("file-sink-enabled", Default = CliBool.False, Required = false, HelpText = "Enable/disable file sink telemetry logging. Default: false (boolean).")] + public CliBool? FileSinkEnabled { get; } + + // Path for the File Sink resource to which telemetry data should be sent. This flag is optional and default value is '/logs/dab-log.txt'. + [Option("file-sink-path", Default = "/logs/dab-log.txt", Required = false, HelpText = "File path for telemetry logs. Default: '/logs/dab-log.txt' (string).")] + public string? FileSinkPath { get; } + + // Rolling Interval for the File Sink resource to which telemetry data should be sent. This flag is optional and default value is new interval per Day. + [Option("file-sink-rolling-interval", Default = RollingIntervalMode.Day, Required = false, HelpText = "Rolling interval for log files. Default: Day. Allowed values: Hour, Day, Week.")] + public RollingIntervalMode? FileSinkRollingInterval { get; } + + // Retained File Count Limit for the File Sink resource to which telemetry data should be sent. This flag is optional and default value is 1. + [Option("file-sink-retained-file-count-limit", Default = 1, Required = false, HelpText = "Maximum number of retained log files. Default: 1 (integer, minimum: 1).")] + public int? FileSinkRetainedFileCountLimit { get; } + + // File Size Limit Bytes for the File Sink resource to which telemetry data should be sent. This flag is optional and default value is 1048576. + [Option("file-sink-file-size-limit-bytes", Default = 1048576, Required = false, HelpText = "Maximum file size in bytes before rolling. Default: 1048576 (integer, minimum: 1).")] + public int? FileSinkFileSizeLimitBytes { get; } + public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem) { logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion()); diff --git a/src/Cli/Commands/ConfigureOptions.cs b/src/Cli/Commands/ConfigureOptions.cs index 457701da15..3ef98c237d 100644 --- a/src/Cli/Commands/ConfigureOptions.cs +++ b/src/Cli/Commands/ConfigureOptions.cs @@ -44,7 +44,7 @@ public ConfigureOptions( string? runtimeHostAuthenticationJwtIssuer = null, bool? runtimeTelemetryFileEnabled = null, string? runtimeTelemetryFilePath = null, - RollingInterval? runtimeTelemetryFileRollingInterval = null, + RollingIntervalMode? runtimeTelemetryFileRollingInterval = null, int? runtimeTelemetryFileRetainedFileCountLimit = null, int? runtimeTelemetryFileFileSizeLimitBytes = null, string? config = null) @@ -77,12 +77,6 @@ public ConfigureOptions( RuntimeHostAuthenticationProvider = runtimeHostAuthenticationProvider; RuntimeHostAuthenticationJwtAudience = runtimeHostAuthenticationJwtAudience; RuntimeHostAuthenticationJwtIssuer = runtimeHostAuthenticationJwtIssuer; - // File Sink Telemetry - RuntimeTelemetryFileEnabled = runtimeTelemetryFileEnabled; - RuntimeTelemetryFilePath = runtimeTelemetryFilePath; - RuntimeTelemetryFileRollingInterval = runtimeTelemetryFileRollingInterval; - RuntimeTelemetryFileRetainedFileCountLimit = runtimeTelemetryFileRetainedFileCountLimit; - RuntimeTelemetryFileFileSizeLimitBytes = runtimeTelemetryFileFileSizeLimitBytes; } [Option("data-source.database-type", Required = false, HelpText = "Database type. Allowed values: MSSQL, PostgreSQL, CosmosDB_NoSQL, MySQL.")] @@ -151,21 +145,6 @@ public ConfigureOptions( [Option("runtime.host.authentication.jwt.issuer", Required = false, HelpText = "Configure the entity that issued the Jwt Token.")] public string? RuntimeHostAuthenticationJwtIssuer { get; } - [Option("runtime.telemetry.file.enabled", Required = false, HelpText = "Enable/disable file sink telemetry logging. Default: false (boolean).")] - public bool? RuntimeTelemetryFileEnabled { get; } - - [Option("runtime.telemetry.file.path", Required = false, HelpText = "File path for telemetry logs. Default: '/logs/dab-log.txt' (string).")] - public string? RuntimeTelemetryFilePath { get; } - - [Option("runtime.telemetry.file.rolling-interval", Required = false, HelpText = "Rolling interval for log files. Default: Day. Allowed values: Hour, Day, Week.")] - public RollingInterval? RuntimeTelemetryFileRollingInterval { get; } - - [Option("runtime.telemetry.file.retained-file-count-limit", Required = false, HelpText = "Maximum number of retained log files. Default: 1 (integer, minimum: 1).")] - public int? RuntimeTelemetryFileRetainedFileCountLimit { get; } - - [Option("runtime.telemetry.file.file-size-limit-bytes", Required = false, HelpText = "Maximum file size in bytes before rolling. Default: 1048576 (integer, minimum: 1).")] - public int? RuntimeTelemetryFileFileSizeLimitBytes { get; } - public int Handler(ILogger logger, FileSystemRuntimeConfigLoader loader, IFileSystem fileSystem) { logger.LogInformation("{productName} {version}", PRODUCT_NAME, ProductInfo.GetProductVersion()); diff --git a/src/Cli/ConfigGenerator.cs b/src/Cli/ConfigGenerator.cs index 7fc0781224..3b6aba16e3 100644 --- a/src/Cli/ConfigGenerator.cs +++ b/src/Cli/ConfigGenerator.cs @@ -773,29 +773,6 @@ private static bool TryUpdateConfiguredRuntimeOptions( } } - // Telemetry File: Enabled, Path, Rolling-Interval, Retained-File-Count-Limit, File-Size-Limit-Bytes - if (options.RuntimeTelemetryFileEnabled != null || - options.RuntimeTelemetryFilePath != null || - options.RuntimeTelemetryFileRollingInterval != null || - options.RuntimeTelemetryFileRetainedFileCountLimit != null || - options.RuntimeTelemetryFileFileSizeLimitBytes != null) - { - TelemetryOptions? currentTelemetryOptions = runtimeConfig?.Runtime?.Telemetry; - Azure.DataApiBuilder.Config.ObjectModel.FileOptions? updatedFileOptions = currentTelemetryOptions?.File ?? new(); - bool status = TryUpdateConfiguredTelemetryFileValues(options, ref updatedFileOptions); - if (status) - { - TelemetryOptions updatedTelemetryOptions = currentTelemetryOptions is null - ? new TelemetryOptions(File: updatedFileOptions) - : currentTelemetryOptions with { File = updatedFileOptions }; - runtimeConfig = runtimeConfig! with { Runtime = runtimeConfig.Runtime! with { Telemetry = updatedTelemetryOptions } }; - } - else - { - return false; - } - } - return runtimeConfig != null; } @@ -1992,100 +1969,25 @@ public static bool TryAddTelemetry(AddTelemetryOptions options, FileSystemRuntim ServiceName: options.OpenTelemetryServiceName ); + FileSinkOptions fileSinkOptions = new( + Enabled: options.FileSinkEnabled is CliBool.True ? true : false, + Path: options.FileSinkPath, + RollingInterval: options.FileSinkRollingInterval, + RetainedFileCountLimit: options.FileSinkRetainedFileCountLimit, + FileSizeLimitBytes: options.FileSinkFileSizeLimitBytes + ); + runtimeConfig = runtimeConfig with { Runtime = runtimeConfig.Runtime with { Telemetry = runtimeConfig.Runtime.Telemetry is null - ? new TelemetryOptions(ApplicationInsights: applicationInsightsOptions, OpenTelemetry: openTelemetryOptions) - : runtimeConfig.Runtime.Telemetry with { ApplicationInsights = applicationInsightsOptions, OpenTelemetry = openTelemetryOptions } - } - }; - runtimeConfig = runtimeConfig with - { - Runtime = runtimeConfig.Runtime with - { - Telemetry = runtimeConfig.Runtime.Telemetry is null - ? new TelemetryOptions(ApplicationInsights: applicationInsightsOptions) - : runtimeConfig.Runtime.Telemetry with { ApplicationInsights = applicationInsightsOptions } + ? new TelemetryOptions(ApplicationInsights: applicationInsightsOptions, OpenTelemetry: openTelemetryOptions, File: fileSinkOptions) + : runtimeConfig.Runtime.Telemetry with { ApplicationInsights = applicationInsightsOptions, OpenTelemetry = openTelemetryOptions, File = fileSinkOptions } } }; return WriteRuntimeConfigToFile(runtimeConfigFile, runtimeConfig, fileSystem); } - - /// - /// Attempts to update the Config parameters in the Telemetry File runtime settings based on the provided value. - /// Validates that any user-provided parameter value is valid and then returns true if the updated File options - /// need to be overwritten on the existing config parameters - /// - /// options. - /// updatedFileOptions. - /// True if the value needs to be updated in the runtime config, else false - private static bool TryUpdateConfiguredTelemetryFileValues( - ConfigureOptions options, - ref Azure.DataApiBuilder.Config.ObjectModel.FileOptions? updatedFileOptions) - { - object? updatedValue; - try - { - // Runtime.Telemetry.File.Enabled - updatedValue = options?.RuntimeTelemetryFileEnabled; - if (updatedValue != null) - { - updatedFileOptions = updatedFileOptions! with { Enabled = (bool)updatedValue }; - _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Enabled as '{updatedValue}'", updatedValue); - } - - // Runtime.Telemetry.File.Path - updatedValue = options?.RuntimeTelemetryFilePath; - if (updatedValue != null) - { - updatedFileOptions = updatedFileOptions! with { Path = (string)updatedValue }; - _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Path as '{updatedValue}'", updatedValue); - } - - // Runtime.Telemetry.File.Rolling-Interval - updatedValue = options?.RuntimeTelemetryFileRollingInterval; - if (updatedValue != null) - { - updatedFileOptions = updatedFileOptions! with { RollingInterval = (RollingInterval)updatedValue }; - _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Rolling-Interval as '{updatedValue}'", updatedValue); - } - - // Runtime.Telemetry.File.Retained-File-Count-Limit - updatedValue = options?.RuntimeTelemetryFileRetainedFileCountLimit; - if (updatedValue != null) - { - if ((int)updatedValue < 1) - { - _logger.LogError("Runtime.Telemetry.File.Retained-File-Count-Limit must be at least 1. Provided value: {updatedValue}", updatedValue); - return false; - } - updatedFileOptions = updatedFileOptions! with { RetainedFileCountLimit = (int)updatedValue }; - _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.Retained-File-Count-Limit as '{updatedValue}'", updatedValue); - } - - // Runtime.Telemetry.File.File-Size-Limit-Bytes - updatedValue = options?.RuntimeTelemetryFileFileSizeLimitBytes; - if (updatedValue != null) - { - if ((int)updatedValue < 1) - { - _logger.LogError("Runtime.Telemetry.File.File-Size-Limit-Bytes must be at least 1. Provided value: {updatedValue}", updatedValue); - return false; - } - updatedFileOptions = updatedFileOptions! with { FileSizeLimitBytes = (int)updatedValue }; - _logger.LogInformation("Updated RuntimeConfig with Runtime.Telemetry.File.File-Size-Limit-Bytes as '{updatedValue}'", updatedValue); - } - - return true; - } - catch (Exception ex) - { - _logger.LogError("Failed to update RuntimeConfig.Telemetry.File with exception message: {exceptionMessage}.", ex.Message); - return false; - } - } } } diff --git a/src/Cli/Properties/launchSettings.json b/src/Cli/Properties/launchSettings.json index 43a4439fdb..4988682498 100644 --- a/src/Cli/Properties/launchSettings.json +++ b/src/Cli/Properties/launchSettings.json @@ -2,8 +2,8 @@ "profiles": { "Cli": { "commandName": "Project", - "commandLineArgs": "start", + "commandLineArgs": "add-telemetry --config C:\\Users\\rcernaserna\\DAB\\data-api-builder\\src\\Service\\dab-config.MsSql.json --otel-enabled false --file-sink-enabled false", "httpPort": 5002 } } -} +} \ No newline at end of file diff --git a/src/Config/ObjectModel/FileOptions.cs b/src/Config/ObjectModel/FileOptions.cs deleted file mode 100644 index ef27920db7..0000000000 --- a/src/Config/ObjectModel/FileOptions.cs +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using System.Text.Json.Serialization; - -namespace Azure.DataApiBuilder.Config.ObjectModel; - -/// -/// Represents the options for configuring file sink telemetry. -/// -public record FileOptions( - bool Enabled = false, - string Path = "/logs/dab-log.txt", - RollingInterval RollingInterval = RollingInterval.Day, - int RetainedFileCountLimit = 1, - int FileSizeLimitBytes = 1048576) -{ - [JsonPropertyName("rolling-interval")] - public RollingInterval RollingInterval { get; init; } = RollingInterval; - - [JsonPropertyName("retained-file-count-limit")] - public int RetainedFileCountLimit { get; init; } = RetainedFileCountLimit; - - [JsonPropertyName("file-size-limit-bytes")] - public int FileSizeLimitBytes { get; init; } = FileSizeLimitBytes; -} - -/// -/// Represents the rolling interval options for file sink. -/// -[JsonConverter(typeof(JsonStringEnumConverter))] -public enum RollingInterval -{ - Hour, - Day, - Week -} \ No newline at end of file diff --git a/src/Config/ObjectModel/FileSinkOptions.cs b/src/Config/ObjectModel/FileSinkOptions.cs new file mode 100644 index 0000000000..d01ba3f1ce --- /dev/null +++ b/src/Config/ObjectModel/FileSinkOptions.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Azure.DataApiBuilder.Config.ObjectModel; + +/// +/// Represents the options for configuring file sink telemetry. +/// +public record FileSinkOptions( + bool Enabled = false, + string? Path = "/logs/dab-log.txt", + RollingIntervalMode? RollingInterval = RollingIntervalMode.Day, + int? RetainedFileCountLimit = 1, + int? FileSizeLimitBytes = 1048576) +{ + public bool Enabled { get; init; } = Enabled; + + public string? Path { get; init; } = Path; + + public RollingIntervalMode? RollingInterval { get; init; } = RollingInterval; + + public int? RetainedFileCountLimit { get; init; } = RetainedFileCountLimit; + + public int? FileSizeLimitBytes { get; init; } = FileSizeLimitBytes; +} diff --git a/src/Config/ObjectModel/FileSinkRollingIntervalMode.cs b/src/Config/ObjectModel/FileSinkRollingIntervalMode.cs new file mode 100644 index 0000000000..a807a9b0aa --- /dev/null +++ b/src/Config/ObjectModel/FileSinkRollingIntervalMode.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System.Text.Json.Serialization; + +namespace Azure.DataApiBuilder.Config.ObjectModel; + +/// +/// Represents the rolling interval options for file sink. +/// The time it takes between the creation of new files. +/// +[JsonConverter(typeof(JsonStringEnumConverter))] +public enum RollingIntervalMode +{ + Hour, + Day, + Week +} diff --git a/src/Config/ObjectModel/TelemetryOptions.cs b/src/Config/ObjectModel/TelemetryOptions.cs index 68c3d17b37..9956deee82 100644 --- a/src/Config/ObjectModel/TelemetryOptions.cs +++ b/src/Config/ObjectModel/TelemetryOptions.cs @@ -9,7 +9,7 @@ namespace Azure.DataApiBuilder.Config.ObjectModel; /// /// Represents the options for telemetry. /// -public record TelemetryOptions(ApplicationInsightsOptions? ApplicationInsights = null, OpenTelemetryOptions? OpenTelemetry = null, FileOptions? File = null, Dictionary? LoggerLevel = null) +public record TelemetryOptions(ApplicationInsightsOptions? ApplicationInsights = null, OpenTelemetryOptions? OpenTelemetry = null, FileSinkOptions? File = null, Dictionary? LoggerLevel = null) { [JsonPropertyName("log-level")] public Dictionary? LoggerLevel { get; init; } = LoggerLevel; From e58fb27fb9ddf7a290782aa73698a76edd7c3c1d Mon Sep 17 00:00:00 2001 From: Ruben Cerna Date: Sun, 6 Jul 2025 23:57:31 -0700 Subject: [PATCH 5/9] Fix unit tests --- src/Cli.Tests/ConfigureOptionsTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Cli.Tests/ConfigureOptionsTests.cs b/src/Cli.Tests/ConfigureOptionsTests.cs index 886e240615..05278bf334 100644 --- a/src/Cli.Tests/ConfigureOptionsTests.cs +++ b/src/Cli.Tests/ConfigureOptionsTests.cs @@ -883,10 +883,10 @@ public void TestUpdateTelemetryFilePath(string updatedPathValue) /// validates whether the runtime config reflects those updated values /// [DataTestMethod] - [DataRow(RollingInterval.Hour, DisplayName = "Update rolling interval to Hour.")] - [DataRow(RollingInterval.Day, DisplayName = "Update rolling interval to Day.")] - [DataRow(RollingInterval.Week, DisplayName = "Update rolling interval to Week.")] - public void TestUpdateTelemetryFileRollingInterval(RollingInterval updatedRollingIntervalValue) + [DataRow(RollingIntervalMode.Hour, DisplayName = "Update rolling interval to Hour.")] + [DataRow(RollingIntervalMode.Day, DisplayName = "Update rolling interval to Day.")] + [DataRow(RollingIntervalMode.Week, DisplayName = "Update rolling interval to Week.")] + public void TestUpdateTelemetryFileRollingInterval(RollingIntervalMode updatedRollingIntervalValue) { // Arrange -> all the setup which includes creating options. SetupFileSystemWithInitialConfig(INITIAL_CONFIG); @@ -1013,7 +1013,7 @@ public void TestUpdateMultipleTelemetryFileOptions() ConfigureOptions options = new( runtimeTelemetryFileEnabled: true, runtimeTelemetryFilePath: "/var/log/custom-dab.log", - runtimeTelemetryFileRollingInterval: RollingInterval.Week, + runtimeTelemetryFileRollingInterval: RollingIntervalMode.Week, runtimeTelemetryFileRetainedFileCountLimit: 14, runtimeTelemetryFileFileSizeLimitBytes: 52428800, config: TEST_RUNTIME_CONFIG_FILE @@ -1024,13 +1024,13 @@ public void TestUpdateMultipleTelemetryFileOptions() Assert.IsTrue(isSuccess); string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - + Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File); - var fileOptions = runtimeConfig.Runtime.Telemetry.File; - + FileSinkOptions fileOptions = runtimeConfig.Runtime.Telemetry.File; + Assert.AreEqual(true, fileOptions.Enabled); Assert.AreEqual("/var/log/custom-dab.log", fileOptions.Path); - Assert.AreEqual(RollingInterval.Week, fileOptions.RollingInterval); + Assert.AreEqual(RollingIntervalMode.Week, fileOptions.RollingInterval); Assert.AreEqual(14, fileOptions.RetainedFileCountLimit); Assert.AreEqual(52428800, fileOptions.FileSizeLimitBytes); } From 8642be18c90b8e08c107f776a908c2906ee53a3c Mon Sep 17 00:00:00 2001 From: Ruben Cerna Date: Mon, 7 Jul 2025 12:19:06 -0700 Subject: [PATCH 6/9] Fix Test Failures --- src/Cli.Tests/ConfigureOptionsTests.cs | 215 ------------------------- src/Cli/Commands/ConfigureOptions.cs | 5 - 2 files changed, 220 deletions(-) diff --git a/src/Cli.Tests/ConfigureOptionsTests.cs b/src/Cli.Tests/ConfigureOptionsTests.cs index 05278bf334..8ee064e262 100644 --- a/src/Cli.Tests/ConfigureOptionsTests.cs +++ b/src/Cli.Tests/ConfigureOptionsTests.cs @@ -819,220 +819,5 @@ private void SetupFileSystemWithInitialConfig(string jsonConfig) Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(jsonConfig, out RuntimeConfig? config)); Assert.IsNotNull(config.Runtime); } - - /// - /// Tests that running "dab configure --runtime.telemetry.file.enabled" on a config with various values results - /// in runtime config update. Takes in updated value for telemetry file enabled and - /// validates whether the runtime config reflects those updated values - /// - [DataTestMethod] - [DataRow(true, DisplayName = "Enable file sink telemetry.")] - [DataRow(false, DisplayName = "Disable file sink telemetry.")] - public void TestUpdateTelemetryFileEnabled(bool updatedEnabledValue) - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - // Act: Attempts to update file enabled flag - ConfigureOptions options = new( - runtimeTelemetryFileEnabled: updatedEnabledValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate the Enabled Flag is updated - Assert.IsTrue(isSuccess); - string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); - Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.Enabled); - Assert.AreEqual(updatedEnabledValue, runtimeConfig.Runtime.Telemetry.File.Enabled); - } - - /// - /// Tests that running "dab configure --runtime.telemetry.file.path" on a config with various values results - /// in runtime config update. Takes in updated value for telemetry file path and - /// validates whether the runtime config reflects those updated values - /// - [DataTestMethod] - [DataRow("/logs/custom-dab.log", DisplayName = "Update file path to custom location.")] - [DataRow("/var/log/dab-application.log", DisplayName = "Update file path to var log directory.")] - [DataRow("./logs/dab.log", DisplayName = "Update file path to relative location.")] - public void TestUpdateTelemetryFilePath(string updatedPathValue) - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - // Act: Attempts to update file path value - ConfigureOptions options = new( - runtimeTelemetryFilePath: updatedPathValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate the Path is updated - Assert.IsTrue(isSuccess); - string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); - Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.Path); - Assert.AreEqual(updatedPathValue, runtimeConfig.Runtime.Telemetry.File.Path); - } - - /// - /// Tests that running "dab configure --runtime.telemetry.file.rolling-interval" on a config with various values results - /// in runtime config update. Takes in updated value for telemetry file rolling interval and - /// validates whether the runtime config reflects those updated values - /// - [DataTestMethod] - [DataRow(RollingIntervalMode.Hour, DisplayName = "Update rolling interval to Hour.")] - [DataRow(RollingIntervalMode.Day, DisplayName = "Update rolling interval to Day.")] - [DataRow(RollingIntervalMode.Week, DisplayName = "Update rolling interval to Week.")] - public void TestUpdateTelemetryFileRollingInterval(RollingIntervalMode updatedRollingIntervalValue) - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - // Act: Attempts to update rolling interval value - ConfigureOptions options = new( - runtimeTelemetryFileRollingInterval: updatedRollingIntervalValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate the Rolling Interval is updated - Assert.IsTrue(isSuccess); - string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); - Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.RollingInterval); - Assert.AreEqual(updatedRollingIntervalValue, runtimeConfig.Runtime.Telemetry.File.RollingInterval); - } - - /// - /// Tests that running "dab configure --runtime.telemetry.file.retained-file-count-limit" on a config with various values results - /// in runtime config update. Takes in updated value for retained file count limit and - /// validates whether the runtime config reflects those updated values - /// - [DataTestMethod] - [DataRow(1, DisplayName = "Update retained file count limit to 1.")] - [DataRow(7, DisplayName = "Update retained file count limit to 7.")] - [DataRow(30, DisplayName = "Update retained file count limit to 30.")] - public void TestUpdateTelemetryFileRetainedFileCountLimit(int updatedRetainedFileCountLimitValue) - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - // Act: Attempts to update retained file count limit value - ConfigureOptions options = new( - runtimeTelemetryFileRetainedFileCountLimit: updatedRetainedFileCountLimitValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate the Retained File Count Limit is updated - Assert.IsTrue(isSuccess); - string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); - Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.RetainedFileCountLimit); - Assert.AreEqual(updatedRetainedFileCountLimitValue, runtimeConfig.Runtime.Telemetry.File.RetainedFileCountLimit); - } - - /// - /// Tests that running "dab configure --runtime.telemetry.file.file-size-limit-bytes" on a config with various values results - /// in runtime config update. Takes in updated value for file size limit bytes and - /// validates whether the runtime config reflects those updated values - /// - [DataTestMethod] - [DataRow(1048576, DisplayName = "Update file size limit to 1MB.")] - [DataRow(10485760, DisplayName = "Update file size limit to 10MB.")] - [DataRow(104857600, DisplayName = "Update file size limit to 100MB.")] - public void TestUpdateTelemetryFileFileSizeLimitBytes(int updatedFileSizeLimitBytesValue) - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - // Act: Attempts to update file size limit bytes value - ConfigureOptions options = new( - runtimeTelemetryFileFileSizeLimitBytes: updatedFileSizeLimitBytesValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate the File Size Limit Bytes is updated - Assert.IsTrue(isSuccess); - string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); - Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File?.FileSizeLimitBytes); - Assert.AreEqual(updatedFileSizeLimitBytesValue, runtimeConfig.Runtime.Telemetry.File.FileSizeLimitBytes); - } - - /// - /// Tests that validation fails when invalid values are provided for retained file count limit and file size limit - /// - [DataTestMethod] - [DataRow(0, "retained-file-count-limit", DisplayName = "Fail when retained file count limit is 0.")] - [DataRow(-1, "retained-file-count-limit", DisplayName = "Fail when retained file count limit is negative.")] - [DataRow(0, "file-size-limit-bytes", DisplayName = "Fail when file size limit is 0.")] - [DataRow(-1, "file-size-limit-bytes", DisplayName = "Fail when file size limit is negative.")] - public void TestTelemetryFileConfigurationValidationFailures(int invalidValue, string optionType) - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - ConfigureOptions options; - if (optionType == "retained-file-count-limit") - { - options = new ConfigureOptions( - runtimeTelemetryFileRetainedFileCountLimit: invalidValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - } - else - { - options = new ConfigureOptions( - runtimeTelemetryFileFileSizeLimitBytes: invalidValue, - config: TEST_RUNTIME_CONFIG_FILE - ); - } - - // Act: Attempts to update with invalid value - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate that configuration fails - Assert.IsFalse(isSuccess); - } - - /// - /// Tests that multiple file sink telemetry options can be configured in a single command - /// - [TestMethod] - public void TestUpdateMultipleTelemetryFileOptions() - { - // Arrange -> all the setup which includes creating options. - SetupFileSystemWithInitialConfig(INITIAL_CONFIG); - - // Act: Attempts to update multiple file options at once - ConfigureOptions options = new( - runtimeTelemetryFileEnabled: true, - runtimeTelemetryFilePath: "/var/log/custom-dab.log", - runtimeTelemetryFileRollingInterval: RollingIntervalMode.Week, - runtimeTelemetryFileRetainedFileCountLimit: 14, - runtimeTelemetryFileFileSizeLimitBytes: 52428800, - config: TEST_RUNTIME_CONFIG_FILE - ); - bool isSuccess = TryConfigureSettings(options, _runtimeConfigLoader!, _fileSystem!); - - // Assert: Validate all options are updated correctly - Assert.IsTrue(isSuccess); - string updatedConfig = _fileSystem!.File.ReadAllText(TEST_RUNTIME_CONFIG_FILE); - Assert.IsTrue(RuntimeConfigLoader.TryParseConfig(updatedConfig, out RuntimeConfig? runtimeConfig)); - - Assert.IsNotNull(runtimeConfig.Runtime?.Telemetry?.File); - FileSinkOptions fileOptions = runtimeConfig.Runtime.Telemetry.File; - - Assert.AreEqual(true, fileOptions.Enabled); - Assert.AreEqual("/var/log/custom-dab.log", fileOptions.Path); - Assert.AreEqual(RollingIntervalMode.Week, fileOptions.RollingInterval); - Assert.AreEqual(14, fileOptions.RetainedFileCountLimit); - Assert.AreEqual(52428800, fileOptions.FileSizeLimitBytes); - } } } diff --git a/src/Cli/Commands/ConfigureOptions.cs b/src/Cli/Commands/ConfigureOptions.cs index 3ef98c237d..a11d6b65f9 100644 --- a/src/Cli/Commands/ConfigureOptions.cs +++ b/src/Cli/Commands/ConfigureOptions.cs @@ -42,11 +42,6 @@ public ConfigureOptions( string? runtimeHostAuthenticationProvider = null, string? runtimeHostAuthenticationJwtAudience = null, string? runtimeHostAuthenticationJwtIssuer = null, - bool? runtimeTelemetryFileEnabled = null, - string? runtimeTelemetryFilePath = null, - RollingIntervalMode? runtimeTelemetryFileRollingInterval = null, - int? runtimeTelemetryFileRetainedFileCountLimit = null, - int? runtimeTelemetryFileFileSizeLimitBytes = null, string? config = null) : base(config) { From b4b9278753cb2c304aae4ee49fa59793477d636c Mon Sep 17 00:00:00 2001 From: Ruben Cerna Date: Mon, 7 Jul 2025 14:35:18 -0700 Subject: [PATCH 7/9] Restore launchSettings --- src/Config/Properties/launchSettings.json | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/Config/Properties/launchSettings.json diff --git a/src/Config/Properties/launchSettings.json b/src/Config/Properties/launchSettings.json new file mode 100644 index 0000000000..080a69e8fd --- /dev/null +++ b/src/Config/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "Azure.DataApiBuilder.Config": { + "commandName": "Project", + "commandLineArgs": "start" + } + } +} From a7ee4eece1feb56f2c2b94593486fe7feb04ec29 Mon Sep 17 00:00:00 2001 From: Ruben Cerna Date: Mon, 7 Jul 2025 15:06:39 -0700 Subject: [PATCH 8/9] Fix launch settings --- src/Cli/Properties/launchSettings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cli/Properties/launchSettings.json b/src/Cli/Properties/launchSettings.json index 4988682498..43a4439fdb 100644 --- a/src/Cli/Properties/launchSettings.json +++ b/src/Cli/Properties/launchSettings.json @@ -2,8 +2,8 @@ "profiles": { "Cli": { "commandName": "Project", - "commandLineArgs": "add-telemetry --config C:\\Users\\rcernaserna\\DAB\\data-api-builder\\src\\Service\\dab-config.MsSql.json --otel-enabled false --file-sink-enabled false", + "commandLineArgs": "start", "httpPort": 5002 } } -} \ No newline at end of file +} From e25a44606a5186219c698c7165b3d2ad7658ce37 Mon Sep 17 00:00:00 2001 From: Ruben Cerna Date: Mon, 7 Jul 2025 15:10:08 -0700 Subject: [PATCH 9/9] Fix launch settings --- src/Config/Properties/launchSettings.json | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 src/Config/Properties/launchSettings.json diff --git a/src/Config/Properties/launchSettings.json b/src/Config/Properties/launchSettings.json deleted file mode 100644 index 080a69e8fd..0000000000 --- a/src/Config/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "Azure.DataApiBuilder.Config": { - "commandName": "Project", - "commandLineArgs": "start" - } - } -}