Skip to content

Add scaler api for consumption plan support#963

Merged
AmeyaRele merged 12 commits intomainfrom
ameyarele/addscv3support
Jul 3, 2024
Merged

Add scaler api for consumption plan support#963
AmeyaRele merged 12 commits intomainfrom
ameyarele/addscv3support

Conversation

@AmeyaRele
Copy link
Copy Markdown
Contributor

@AmeyaRele AmeyaRele commented Nov 3, 2023

Description
This PR adds scaler apis for supporting SQL extension on Azure Functions Consumption Plan. The TargetScaler and ScaleMonitor would be called from scale controller by including the sql package.

Task List

  • Create SqlScalerProvider class
  • Add extension method 'AddSqlScaleForTrigger'
  • Add e2e test similar to cosmosdb

Reference PRs

@AmeyaRele AmeyaRele requested review from alrod and mathewc November 3, 2023 11:47
@Charles-Gagnon
Copy link
Copy Markdown
Contributor

@AmeyaRele We've already started the release process for our GA Trigger release - is this something that should be included as a part of that? Or is it ok to follow up with later on?

Also, is there any documentation you could link to with more context about what this feature is as well?

@AmeyaRele
Copy link
Copy Markdown
Contributor Author

@Charles-Gagnon we can follow up with this later on. It isn't a criteria for GA of trigger afaik.

I don't believe there is public documentation on this, but essentially the scale component is redesigned to use these methods by including the extension as a package and use reflection to call the method in the scale component. This is required in consumption(scale to zero) plan for azure functions as the scale component is not guaranteed to have a worker running which it can query for the scaling decisions.

Comment thread src/SqlBindingExtension.cs
@chlafreniere
Copy link
Copy Markdown
Contributor

Hi @AmeyaRele, just curious how much more work is needed in this PR. Is it just the tests, or is there other known work that needs to go in product code-wise?

@AmeyaRele
Copy link
Copy Markdown
Contributor Author

It's just the tests, the changes are done. Need a review on this PR from scale controller team

@AmeyaRele AmeyaRele marked this pull request as ready for review December 4, 2023 06:12
Copy link
Copy Markdown
Contributor

@Charles-Gagnon Charles-Gagnon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to be adding tests as well? Especially integration tests, is that something that we're going to be able to do?

Comment thread src/TriggerBinding/SqlScalerProvider.cs Outdated
Comment thread src/TriggerBinding/SqlScalerProvider.cs Outdated
string connectionString = SqlBindingUtilities.GetConnectionString(sqlMetadata.ConnectionStringSetting, config);
int maxChangesPerWorker = config.GetValue(SqlTriggerConstants.ConfigKey_SqlTrigger_MaxChangesPerWorker, SqlOptions.DefaultMaxChangesPerWorker);
string userDefinedLeasesTableName = sqlMetadata.LeasesTableName;
string userFunctionId = (string)triggerMetadata.Properties["userFunctionId"];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we guaranteed that this is going to have a value? Is there a reason you're not able to use the same method we use for getting the function ID elsewhere?

https://github.com/Azure/azure-functions-sql-extension/blob/main/src/TriggerBinding/SqlTriggerBinding.cs#L105

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we use triggerMetadata.FunctionName here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Charles-Gagnon we can't really reuse the function ID from the SqlTriggerBinding, can I replace it with triggerMetadata.FunctionName mentioned above?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't we able to use the same method? Do we not have access to IHostIdProvider ?

If not, then I believe we're still going to need to find another since we still will need to get the function ID somehow in order for the metrics provider to be able to get the list of unprocessed changes : https://github.com/Azure/azure-functions-sql-extension/blob/main/src/TriggerBinding/SqlTriggerMetricsProvider.cs#L103

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the userFunctionId is gotten from HostIdProvider, and it would use this to
https://github.com/Azure/azure-functions-host/blob/47411dfdc56bedd7f7dd20aa487fe69dbc596325/src/WebJobs.Script/Host/ScriptHostIdProvider.cs#L49

I saw that the scalecontroller also had a hostid which I thought I could use, but the values might be different, as it is using a different class namely FixedHostIdProvider please confirm @alrod

We could go ahead and use triggerMetadata.FunctionName but we would have to use the same at places where userFunctionId is used, in order to get unprocessed changes, as Charles has mentioned.

Comment thread src/TriggerBinding/SqlScalerProvider.cs Outdated
@MaddyDev
Copy link
Copy Markdown
Contributor

There are merge conflicts, please merge main. Please confirm with Alexey on using the hostId and we can have a discussion on getting userFunctionId.

@AmeyaRele
Copy link
Copy Markdown
Contributor Author

@Charles-Gagnon please review again

Comment thread test/Microsoft.Azure.WebJobs.Extensions.Sql.Tests.csproj Outdated
@AmeyaRele AmeyaRele merged commit 0effe95 into main Jul 3, 2024
@AmeyaRele AmeyaRele deleted the ameyarele/addscv3support branch July 3, 2024 11:51
PBBlox pushed a commit to PBBlox/azure-functions-sql-extension that referenced this pull request Apr 6, 2025
* Add scaler api for consumption plan support

* Make scale method internal

* Add test, resolve comments

* Add packages for test

* Fix test

* Read from both appsettings and options

* Modify trigger listener params in test

* Fix indent

---------

Co-authored-by: MaddyDev <madhu.koripalli@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants