Skip to content

Commit

Permalink
renaming and reordering
Browse files Browse the repository at this point in the history
  • Loading branch information
vivekjilla committed Feb 4, 2025
1 parent bf36c43 commit 3954245
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.Azure.WebJobs.Script.WebHost.Configuration
{
public class AzureMonitorOptions
public class AzureMonitorLoggingOptions
{
public bool IsAzureMonitorTimeIsoFormatEnabled { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

namespace Microsoft.Azure.WebJobs.Script.WebHost.Configuration
{
public class AzureMonitorOptionsSetup : IConfigureOptions<AzureMonitorOptions>
public class AzureMonitorLoggingOptionsSetup : IConfigureOptions<AzureMonitorLoggingOptions>
{
private readonly IEnvironment _env;

public AzureMonitorOptionsSetup(IEnvironment env)
public AzureMonitorLoggingOptionsSetup(IEnvironment env)
{
_env = env;
}

public void Configure(AzureMonitorOptions options)
public void Configure(AzureMonitorLoggingOptions options)
{
options.IsAzureMonitorTimeIsoFormatEnabled = IsAzureMonitorTimeIsoFormatEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class LinuxAppServiceEventGenerator : LinuxEventGenerator
private readonly Action<string> _writeEvent;
private readonly HostNameProvider _hostNameProvider;
private readonly IOptions<FunctionsHostingConfigOptions> _functionsHostingConfigOptions;
private readonly IOptions<Configuration.AzureMonitorOptions> _azureMonitorOptions;
private readonly IOptions<AzureMonitorLoggingOptions> _azureMonitorLoggingOptions;
private ILinuxAppServiceFileLogger _functionsExecutionEventsCategoryLogger;
private ILinuxAppServiceFileLogger _functionsLogsCategoryLogger;
private ILinuxAppServiceFileLogger _functionsMetricsCategoryLogger;
Expand All @@ -25,13 +25,13 @@ public LinuxAppServiceEventGenerator(
ILinuxAppServiceFileLoggerFactory loggerFactory,
HostNameProvider hostNameProvider,
IOptions<FunctionsHostingConfigOptions> functionsHostingConfigOptions,
IOptions<Configuration.AzureMonitorOptions> azureMonitorOptions,
IOptions<AzureMonitorLoggingOptions> azureMonitorLoggingOptions,
Action<string> writeEvent = null)
{
_writeEvent = writeEvent ?? WriteEvent;
_hostNameProvider = hostNameProvider ?? throw new ArgumentNullException(nameof(hostNameProvider));
_functionsHostingConfigOptions = functionsHostingConfigOptions;
_azureMonitorOptions = azureMonitorOptions;
_azureMonitorLoggingOptions = azureMonitorLoggingOptions;
_functionsExecutionEventsCategoryLogger = loggerFactory.Create(FunctionsExecutionEventsCategory, backoffEnabled: !_functionsHostingConfigOptions.Value.DisableLinuxAppServiceLogBackoff);
_functionsLogsCategoryLogger = loggerFactory.Create(FunctionsLogsCategory, backoffEnabled: false);
_functionsMetricsCategoryLogger = loggerFactory.Create(FunctionsMetricsCategory, false);
Expand Down Expand Up @@ -115,7 +115,7 @@ private void WriteEvent(string eventPayload)

public override void LogAzureMonitorDiagnosticLogEvent(LogLevel level, string resourceId, string operationName, string category, string regionName, string properties)
{
var timeStr = _azureMonitorOptions.Value.IsAzureMonitorTimeIsoFormatEnabled ? DateTime.UtcNow.ToString("s") : DateTime.UtcNow.ToString();
var timeStr = _azureMonitorLoggingOptions.Value.IsAzureMonitorTimeIsoFormatEnabled ? DateTime.UtcNow.ToString("s") : DateTime.UtcNow.ToString();
_writeEvent($"{ScriptConstants.LinuxAzureMonitorEventStreamName} {(int)ToEventLevel(level)},{resourceId},{operationName},{category},{regionName},{NormalizeString(properties.Replace("'", string.Empty))},{timeStr}");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
{
var hostNameProvider = p.GetService<HostNameProvider>();
IOptions<FunctionsHostingConfigOptions> functionsHostingConfigOptions = p.GetService<IOptions<FunctionsHostingConfigOptions>>();
IOptions<AzureMonitorOptions> azureMonitorOptions = p.GetService<IOptions<AzureMonitorOptions>>();
IOptions<AzureMonitorLoggingOptions> azureMonitorOptions = p.GetService<IOptions<AzureMonitorLoggingOptions>>();
return new LinuxAppServiceEventGenerator(new LinuxAppServiceFileLoggerFactory(), hostNameProvider, functionsHostingConfigOptions, azureMonitorOptions);
}
else if (environment.IsAnyKubernetesEnvironment())
Expand Down Expand Up @@ -215,6 +215,7 @@ public static void AddWebJobsScriptHost(this IServiceCollection services, IConfi
services.ConfigureOptionsWithChangeTokenSource<HttpBodyControlOptions, HttpBodyControlOptionsSetup, SpecializationChangeTokenSource<HttpBodyControlOptions>>();
services.ConfigureOptions<FlexConsumptionMetricsPublisherOptionsSetup>();
services.ConfigureOptions<ConsoleLoggingOptionsSetup>();
services.ConfigureOptions<AzureMonitorLoggingOptionsSetup>();
services.AddHostingConfigOptions(configuration);
services.ConfigureOptions<ExtensionRequirementOptionsSetup>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public static IHostBuilder AddWebScriptHost(this IHostBuilder builder, IServiceP
services.ConfigureOptions<AppServiceOptionsSetup>();
services.ConfigureOptions<HostEasyAuthOptionsSetup>();
services.ConfigureOptions<PrimaryHostCoordinatorOptionsSetup>();
services.ConfigureOptions<AzureMonitorOptionsSetup>();
})
.AddScriptHost(webHostOptions, configLoggerFactory, metricsLogger, webJobsBuilder =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class LinuxAppServiceEventGeneratorTests
private readonly LinuxAppServiceEventGenerator _generator;
private readonly List<string> _events;
private IOptions<FunctionsHostingConfigOptions> _functionsHostingConfigOptions;
private IOptions<AzureMonitorOptions> _azureMonitorOptions;
private IOptions<AzureMonitorLoggingOptions> _azureMonitorOptions;

public LinuxAppServiceEventGeneratorTests()
{
Expand All @@ -35,7 +35,7 @@ public LinuxAppServiceEventGeneratorTests()
var loggerFactoryMock = new MockLinuxAppServiceFileLoggerFactory();

_functionsHostingConfigOptions = Options.Create(new FunctionsHostingConfigOptions());
_azureMonitorOptions = Options.Create(new AzureMonitorOptions());
_azureMonitorOptions = Options.Create(new AzureMonitorLoggingOptions());

var environmentMock = new Mock<IEnvironment>();
environmentMock.Setup(f => f.GetEnvironmentVariable(It.Is<string>(v => v == "WEBSITE_HOSTNAME")))
Expand Down Expand Up @@ -146,7 +146,7 @@ public void ParseDetailsEvents(string siteName, string functionName, string inpu
}

[Theory]
[MemberData(nameof(LinuxEventGeneratorTestData.GetAzureMonitorEvents), MemberType = typeof(LinuxEventGeneratorTestData))]
[MemberData(nameof(LinuxEventGeneratorTestData.GetAzureMonitorEventsForLinuxAppServiceEventGenerator), MemberType = typeof(LinuxEventGeneratorTestData))]
public void ParseAzureMonitoringEvents(LogLevel level, string resourceId, string operationName, string category, string regionName, string properties, bool isAzureMonitorTimeIsoFormatEnabled)
{
_azureMonitorOptions.Value.IsAzureMonitorTimeIsoFormatEnabled = isAzureMonitorTimeIsoFormatEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ public static IEnumerable<object[]> GetLogEvents()
yield return new object[] { LogLevel.Information, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
}

public static IEnumerable<object[]> GetAzureMonitorEvents()
public static IEnumerable<object[]> GetAzureMonitorEventsForLinuxAppServiceEventGenerator()
{
yield return new object[] { LogLevel.Information, "TestResourceId", "TestOperationName", "TestCategory", "TestRegionName", "TestProperties", true };
yield return new object[] { LogLevel.Information, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, false };
}
public static IEnumerable<object[]> GetAzureMonitorEvents()
{
yield return new object[] { LogLevel.Information, "TestResourceId", "TestOperationName", "TestCategory", "TestRegionName", "TestProperties" };
yield return new object[] { LogLevel.Information, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty };
}

public static IEnumerable<object[]> GetFunctionExecutionEvents()
{
Expand Down

0 comments on commit 3954245

Please # to comment.