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

Use Singleton Metrics Provider for Listener #285

Merged
merged 12 commits into from
Feb 12, 2025
Merged

Use Singleton Metrics Provider for Listener #285

merged 12 commits into from
Feb 12, 2025

Conversation

nytian
Copy link
Contributor

@nytian nytian commented Feb 10, 2025

@nytian nytian requested a review from cgillum February 11, 2025 00:24
Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

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

I think we need a couple more changes.

{
this.sqlMetricsProvider = sqlMetricsProvider;

// Scalers in Durable Functions are shared for all functions in the same task hub.
// So instead of using a function ID, we use the task hub name as the basis for the descriptor ID.
string id = $"DurableTask-SqlServer:{taskHubName ?? "default"}";
Copy link
Contributor Author

@nytian nytian Feb 11, 2025

Choose a reason for hiding this comment

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

Seems like we don't need the hub name and id , but only the function id to create the target scaler descriptor. Reference about how we defined this constructor at AzureStorage (here ) and how we passed parameters (here)

@nytian nytian requested a review from cgillum February 11, 2025 01:59
{
// Scalers in Durable Functions are shared for all functions in the same task hub.
// So instead of using a function ID, we use the task hub name as the basis for the descriptor ID.
// Scalers in Durable Functions is per function ids. And scalers share the same sqlMetricsProvider in the same taskhub.
string id = $"DurableTask-SqlServer:{taskHubName ?? "default"}";
Copy link
Member

@alrod alrod Feb 11, 2025

Choose a reason for hiding this comment

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

Azure/azure-functions-durable-extension@c5d8e04#diff-4a2696ad951862e955c23e5fcd0393d9b22851c084d8fcdcda6e782f947a5cfaR34

Suggested change
string id = $"DurableTask-SqlServer:{taskHubName ?? "default"}";
string id = $"{functionId}-DurableTask-SqlServer:{taskHubName ?? "default"}";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! does this string id needs to add ToLower(CultureInfo.InvariantCulture) to be lower case?

@nytian nytian requested a review from alrod February 11, 2025 20:24
{
var sqlMetricsProvider = new SqlMetricsProvider(this.service);
this.scaleMonitor = new SqlScaleMonitor(hubName, sqlMetricsProvider);
this.singletonSqlMetricsProvider = new SqlMetricsProvider(this.service);
Copy link
Member

Choose a reason for hiding this comment

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

One last thing. I recall the final fix that Alexey made to the Azure Storage metrics provider was to throttle it so that we only fetch metrics once every few seconds or so. This is how we ensured that we don't have too many storage transactions, even if the app has a lot of triggers. I think it will be important to do that for the SqlMetricsProvider too so that we don't overwhelm the customer's database with expensive SQL queries.

using System.Threading;
using System.Threading.Tasks;

public class SqlMetricsProvider
{
readonly SqlOrchestrationService service;
DateTime metricsTimeStamp = DateTime.MinValue;
SqlScaleMetric? metrics;
Copy link
Contributor Author

@nytian nytian Feb 11, 2025

Choose a reason for hiding this comment

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

Added this cache. If the target scaler calls GetMetricsAsync within 5 seconds, return the last result to make sure the target scaler remains the same decision as last time.

@nytian nytian requested a review from cgillum February 11, 2025 22:52
Copy link
Member

@cgillum cgillum left a comment

Choose a reason for hiding this comment

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

Looks good!

@nytian nytian merged commit 7843abe into main Feb 12, 2025
2 checks passed
@nytian nytian deleted the nytian/metrics branch February 12, 2025 01:31
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.

3 participants