-
Notifications
You must be signed in to change notification settings - Fork 64
Fallback to Host ID if WEBSITE_SITE_NAME isn't defined #1178
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: main
Are you sure you want to change the base?
Changes from all commits
245c054
d56f301
f3df6e3
15a9aff
e555897
d303aff
f003dd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,11 +96,12 @@ To find the name of the leases table associated with your function, look in the | |
|
||
This log message is at the `Information` level, so make sure your log level is set correctly. | ||
|
||
NOTE: `FunctionId` is generated from a couple of inputs: | ||
- The [WEBSITE_SITE_NAME](https://github.com/Azure/azure-functions-sql-extension/blob/main/docs/BindingsOverview.md#website_site_name) setting | ||
- The name of the function | ||
NOTE: `FunctionId` is generated from the name of the function and either | ||
|
||
If either of these values are changed then a new FunctionId will be generated and result in the function starting over from the beginning, including creating a new Leases table. | ||
* The [WEBSITE_SITE_NAME](https://github.com/Azure/azure-functions-sql-extension/blob/main/docs/BindingsOverview.md#website_site_name) setting | ||
* [IHostIdProvider.GetHostIdAsync](https://github.com/Azure/azure-webjobs-sdk/blob/dev/src/Microsoft.Azure.WebJobs.Host/Executors/IHostIdProvider.cs#L14) as a fallback if the WEBSITE_SITE_NAME setting doesn't exist | ||
|
||
If either the name of the function or the ID value are changed then a new FunctionId will be generated and result in the function starting over from the beginning, including creating a new Leases table. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also add what ID means here. |
||
|
||
This table is used to ensure that all changes are processed and that no change is processed more than once. This table consists of two groups of columns: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,9 +78,9 @@ public async Task<IListener> CreateListenerAsync(ListenerFactoryContext context) | |
{ | ||
_ = context ?? throw new ArgumentNullException(nameof(context), "Missing listener context"); | ||
|
||
string userFunctionId = this.GetUserFunctionId(); | ||
string oldUserFunctionId = await this.GetOldUserFunctionIdAsync(); | ||
return new SqlTriggerListener<T>(this._connectionString, this._tableName, this._leasesTableName, userFunctionId, oldUserFunctionId, context.Executor, this._sqlOptions, this._logger, this._configuration); | ||
string websiteSiteNameFunctionId = this.GetWebsiteSiteNameFunctionId(); | ||
string hostIdFunctionId = await this.GetHostIdFunctionIdAsync(); | ||
return new SqlTriggerListener<T>(this._connectionString, this._tableName, this._leasesTableName, websiteSiteNameFunctionId, hostIdFunctionId, context.Executor, this._sqlOptions, this._logger, this._configuration); | ||
} | ||
|
||
public ParameterDescriptor ToParameterDescriptor() | ||
|
@@ -94,18 +94,23 @@ public ParameterDescriptor ToParameterDescriptor() | |
} | ||
|
||
/// <summary> | ||
/// Returns an ID that uniquely identifies the user function. | ||
/// Returns an ID that uniquely identifies the user function, based on the WEBSITE_SITE_NAME configuration value. | ||
/// | ||
/// We call the WEBSITE_SITE_NAME from the configuration and use that to create the hash of the | ||
/// user function id. Appending another hash of class+method in here ensures that if there | ||
/// are multiple user functions within the same process and tracking the same SQL table, then each one of them | ||
/// gets a separate view of the table changes. | ||
/// </summary> | ||
private string GetUserFunctionId() | ||
/// <returns>The function ID, or NULL if there isn't a config value for WEBSITE_SITE_NAME</returns> | ||
private string GetWebsiteSiteNameFunctionId() | ||
{ | ||
// Using read-only App name for the hash https://learn.microsoft.com/en-us/azure/app-service/reference-app-settings?tabs=kudu%2Cdotnet#app-environment | ||
string websiteName = SqlBindingUtilities.GetWebSiteName(this._configuration); | ||
|
||
string websiteName = this._configuration.GetConnectionStringOrSetting(SqlBindingConstants.WEBSITENAME); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the XML documentation to explicitly note that this method may return null if WEBSITE_SITE_NAME is not set, so that consumers are aware of the fallback to host ID. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
if (string.IsNullOrEmpty(websiteName)) | ||
{ | ||
this._logger.LogWarning("WEBSITE_SITE_NAME configuration is not set, will fall back to using function ID based on the host ID. This will mean consumption plan scaling will not work as intended."); | ||
return null; | ||
} | ||
var methodInfo = (MethodInfo)this._parameter.Member; | ||
// Get the function name from FunctionName attribute for .NET functions and methodInfo.Name for non .Net | ||
string functionName = ((FunctionNameAttribute)methodInfo.GetCustomAttribute(typeof(FunctionNameAttribute)))?.Name ?? $"{methodInfo.Name}"; | ||
|
@@ -118,7 +123,7 @@ private string GetUserFunctionId() | |
} | ||
|
||
/// <summary> | ||
/// Returns the deprecated ID that was used to identify the user function. | ||
/// Returns an ID that uniquely identifies the user function, based on the host ID. | ||
/// | ||
/// We call the WebJobs SDK library method to generate the host ID. The host ID is essentially a hash of the | ||
/// assembly name containing the user function(s). This ensures that if the user ever updates their application, | ||
|
@@ -127,7 +132,7 @@ private string GetUserFunctionId() | |
/// are multiple user functions within the same process and tracking the same SQL table, then each one of them | ||
/// gets a separate view of the table changes. | ||
/// </summary> | ||
private async Task<string> GetOldUserFunctionIdAsync() | ||
private async Task<string> GetHostIdFunctionIdAsync() | ||
{ | ||
string hostId = await this._hostIdProvider.GetHostIdAsync(CancellationToken.None); | ||
|
||
|
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.
[nitpick] Clarify in the documentation that while falling back to the host ID supports local development, it may lead to differences in consumption plan scaling behavior compared to when WEBSITE_SITE_NAME is used.
Copilot uses AI. Check for mistakes.