-
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?
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.
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
let's also add what ID means here.
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.
Pull Request Overview
This pull request implements a fallback mechanism for determining the function’s unique identifier by using the host ID when the WEBSITE_SITE_NAME configuration is not set, improving the local development experience. Key changes include:
- Updating various methods and parameter names to reflect the new fallback strategy (e.g. renaming GetPrimaryKeyColumnsAsync to GetPrimaryKeyColumns, GetUserFunctionId to GetWebsiteSiteNameFunctionId, and GetOldUserFunctionIdAsync to GetHostIdFunctionIdAsync).
- Adjusting SQL migration logic in the leases table creation to use the host ID where WEBSITE_SITE_NAME isn’t configured.
- Removing the WEBSITE_SITE_NAME setting from the samples and updating documentation accordingly.
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
test/Integration/SqlTriggerBindingIntegrationTests.cs | Added a new test to verify functionality when WEBSITE_SITE_NAME is defined. |
src/TriggerBinding/SqlTriggerUtils.cs | Renamed the method to better reflect its sync behavior. |
src/TriggerBinding/SqlTriggerMetricsProvider.cs | Updated the method call to use the refactored primary key logic. |
src/TriggerBinding/SqlTriggerListener.cs | Refactored parameter names and added migration logic for lease tables. |
src/TriggerBinding/SqlTriggerBinding.cs | Updated function ID resolution logic to use WEBSITE_SITE_NAME and host ID fallback. |
src/SqlBindingUtilities.cs | Removed the GetWebSiteName method to align with the new fallback approach. |
samples/* | Removed WEBSITE_SITE_NAME from local settings to simplify configuration. |
docs/TriggerBinding.md & docs/BindingsOverview.md | Updated documentation to explain the new fallback behavior. |
Comments suppressed due to low confidence (1)
src/TriggerBinding/SqlTriggerListener.cs:413
- Ensure that the migration logic using _hostIdFunctionId correctly covers all use cases when WEBSITE_SITE_NAME is not set, and verify that the fallback behavior aligns with intended function state management.
SELECT @lastSyncVersion = LastSyncVersion from az_func.GlobalState where UserFunctionID = '{this._hostIdFunctionId}' AND UserTableID = {userTableId}
{ | ||
// 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 comment
The 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.
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 | ||
|
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.
**Note:** While falling back to the host ID (`IHostIdProvider.GetHostIdAsync`) supports local development, it may lead to differences in scaling behavior in a consumption plan compared to when the `WEBSITE_SITE_NAME` setting is used. This is because the host ID is generated differently in local and production environments, which can affect how instances are scaled. |
Copilot uses AI. Check for mistakes.
Closes #1179
We got feedback that requiring WEBSITE_SITE_NAME wasn't very friendly to the local development experience, so instead of throwing an error we'll just fall back to the original
hostIdProvider.GetHostIdAsync
call.This should be fine, since deployed functions should ALWAYS have a site name (set by the host environment) - and for local functions the only thing being lost is consumption scaling which doesn't apply anyways.
I decided to remove the setting from the samples, since generally we shouldn't expect people to need to define it anymore. And then I added a new test that does specifically set it to make sure that things still work as expected.