Skip to content
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

Add scaler api for consumption plan support #963

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

AmeyaRele
Copy link
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

@Charles-Gagnon
Copy link
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
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.

@chlafreniere
Copy link
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
Contributor Author

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

Copy link
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?

src/TriggerBinding/SqlScalerProvider.cs Outdated Show resolved Hide resolved
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
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
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
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
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
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.

src/TriggerBinding/SqlScalerProvider.cs Outdated Show resolved Hide resolved
@MaddyDev
Copy link
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.

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.

None yet

6 participants