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

Target scaler is not working (.NET) #458

Open
pierre-sk opened this issue Sep 27, 2023 · 1 comment
Open

Target scaler is not working (.NET) #458

pierre-sk opened this issue Sep 27, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@pierre-sk
Copy link
Contributor

pierre-sk commented Sep 27, 2023

Hello everyone,

I create this issue to link to this fix proposal: #451

The KafkaTargetScaler is using the obsolete ScaleMonitorDescriptor constructor without the functionId parameter.

[Obsolete("This constructor is obsolete. Use the version that takes function id instead.")]
public ScaleMonitorDescriptor(string id)
{
	Id = id;
}

public ScaleMonitorDescriptor(string id, string functionId) : this(id)
{
	FunctionId = functionId;
}

When target scaling is enabled (by default) the ScaleManager compares the FunctionId to evaluate if a ScaleMonitor is used in case a TargetScaler already exists. But for the same function, the FunctionId of the TargetScaler and ScaleMonitor are not equal.

// Check if TBS enabled on app level
if (scaleOptions.Value.IsTargetScalingEnabled)
{
	HashSet<string> targetScalerFunctions = new HashSet<string>();
	foreach (var scaler in targetScalers)
	{
		string scalerUniqueId = GetTargetScalerFunctionUniqueId(scaler);
		if (!_targetScalersInError.Contains(scalerUniqueId))
		{
			string assemblyName = GetAssemblyName(scaler.GetType());
			bool featureDisabled = configuration.GetValue<string>(assemblyName) == "0";
			if (!featureDisabled)
			{
				targetScalersToSample.Add(scaler);
				targetScalerFunctions.Add(scalerUniqueId);
			}
		}
	}

	foreach (var monitor in scaleMonitors)
	{
		string monitorUniqueId = GetScaleMonitorFunctionUniqueId(monitor);
		// Check if target based scaler exists for the function
		if (!targetScalerFunctions.Contains(monitorUniqueId))
		{
			scaleMonitorsToSample.Add(monitor);
		}
	}
}

Both ScaleMonitor and TargetScaler are retrieved for sampling. It leads to a bad behavior as the ScaleManager doesn't use the TargetScaler to override the vote result when there is any ScaleMonitor status.

// Set correct vote if all the triggers are target
if (!scaleStatuses.Any() && aggregateScaleStatus.TargetWorkerCount.HasValue)
{
    aggregateScaleStatus.Vote = (ScaleVote)aggregateScaleStatus.TargetWorkerCount.Value.CompareTo(context.WorkerCount);
}

Example of a bad result on /admin/host/scale/status function runtime endpoint:

{
    "vote": 0,
    "targetWorkerCount": 4,
    "functionScaleStatuses": {
        "my.functions.myfirstfunction.runasync-kafkatrigger-topic.myconsumer": {
            "vote": 0
        },
        "my.functions.mysecondfunction.runasync-kafkatrigger-topic.myconsumer": {
            "vote": 0
        }
    },
    "functionTargetScalerResults": {
        "My.Functions.MyFirstFunction.RunAsync": {
            "targetWorkerCount": 4
        },
        "My.Functions.MySecondFunction.RunAsync": {
            "targetWorkerCount": 1
        }
    }
}
@pierre-sk pierre-sk changed the title Target scaler is not working Target scaler is not working (.NET) Sep 27, 2023
@jainharsh98 jainharsh98 added the bug Something isn't working label Sep 27, 2023
@pierre-sk
Copy link
Contributor Author

Hello @jainharsh98,

Any chance to take a look to #451?

Thanks

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants