-
Notifications
You must be signed in to change notification settings - Fork 458
Filter Azure monitor logs when customer does not subscribe for the categories #10982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example of these categories? Are they regular ILogger categories?
If so, we should use built in filtering with Microsoft.Extensions.Logging. We can either transform configuration, or we can simply call:
Part 1: log level filter
// condition on if this is the right sku
services.AddOptions<LoggerFilterOptions>()
.Configure<IConfiguration>((options, config) =>
{
string setting = config[EnvironmentSettingNames.AzureMonitorCategories];
options.AddFilter<AzureMonitorDiagnosticLoggerProvider>((category, level) =>
{
// return false when AzureMonitorCategories does not contain FunctionAppLogs
});
});
Part 2: IsEnabled update
// AzureMonitorDiagnosticLogger.cs
// Update the below method to return false when AzureMonitorCategories does not contain FunctionAppLogs
public bool IsEnabled(LogLevel logLevel)
{
// We want to instantiate this Logger in placeholder mode to warm it up, but do not want to log anything.
return !string.IsNullOrEmpty(_hostNameProvider.Value) && !_environment.IsPlaceholderModeEnabled();
}
Although I have to ask - who sets EnvironmentSettingNames.AzureMonitorCategories
? Is it from the platform, or does the user explicitly set it?
I agree with @jviau that providing more context about the scenario would be beneficial. |
369f120
to
396bf40
Compare
I have removed all the changes. We already have category filter in the host code. I just had to called it in isenabled class |
@manikantanallagatla I believe you will need to also add the filter callback I suggested. It may seem redundant but they have different purposes:
I also am wondering about the Also this change will affect all skus - is the behavior of that env variable consistent across all skus? |
6f22843
to
14d46af
Compare
14d46af
to
e8a0b4c
Compare
Addressed it |
Addressed it. Made changes to happen only for legion based SKUs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple suggestions to embrace the options pattern a bit more.
Addressed all comments and updates unit tests as well |
@@ -91,6 +93,18 @@ public static IHostBuilder AddWebScriptHost(this IHostBuilder builder, IServiceP | |||
loggingBuilder.AddWebJobsSystem<SystemLoggerProvider>(); | |||
if (environment.IsAzureMonitorEnabled()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this is awkward. Going back and forth on this PR and it looks like it is completely unnecessary. We already completely disable AzureMonitor / shoebox by simply not registering the AzureMonitorDiagnosticLoggerProvider
- and this is applicable to all skus.
Which means, is this PR even necessary anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I looked at this code and tested the flow. Without the PR, the logs are not getting disabled. I think what was happening is that:
- Legion pods start in placeholder mode and this code is executed at that time. That time, we enable azure monitor.
- When legion pods are specialized, the env variable is set(lets say to None when categories are not subscribed) and we never disable the Azure monitor as we are not doing any options monitor or env variable monitor without the PR.
- Thats why I started with checking for this env variable in is_enabled flow in aAzureMonitorDiagnosticLogger.cs in the PR initially
- Then we went through this options monitor flow which is more efficient.
In summary, specialization is updating the env variable and we need options monitor on that env variable in order to enable/ disable azure monitor logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying AzureMonitor env variable is set during placeholder mode? I would expect it to be the opposite: no env variable set, logger not registered, specialization brings in the azure monitor variable, but it has no effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean:
During placeholder mode, WEBSITE_FUNCTIONS_AZUREMONITOR_CATEGORIES env is set to null. it is not set to anything. So, logger is initialized as we are returning true here for null case:
return true; |
It is also mentioned here that the logger is initialized but the logs are filtered out in placeholder mode:
https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script.WebHost/Diagnostics/AzureMonitorDiagnosticLogger.cs#L58
So, specialization updates the env variable but it has no effect of disabling the logs.
I think we both are saying samething.
As env variable update is not taking effect, we need this PR so we can disable logging when that env variable is set to None.
Issue describing the changes in this PR
For a few SKUs in functions, we want to filter azure monitor logs based on the categories subscribed by the user. This PR checks for the env variable for the categories and skips logging.
Pull request checklist
IMPORTANT: Currently, changes must be backported to the
in-proc
branch to be included in Core Tools and non-Flex deployments.in-proc
branch is not requiredrelease_notes.md
Additional information
Additional PR information