Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Fix bug for scale-in protection (#3144)
Browse files Browse the repository at this point in the history
* Fix bug for scale-in protection

* Update metric name
  • Loading branch information
tevoinea authored May 31, 2023
1 parent 98007be commit 0f6073b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/ApiService/ApiService/Functions/AgentCanSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
}
_ = scp.OkV; // node could be updated but we don't use it after this
allowed = scp.IsOk;

if (allowed) {
_log.Metric($"TaskAllowedToSchedule", 1, new Dictionary<string, string> {
{"MachineId", node.MachineId.ToString()},
{"TaskId", task is not null ? task.TaskId.ToString() : string.Empty}
});
}

return await RequestHandling.Ok(req, new CanSchedule(Allowed: allowed, WorkStopped: workStopped, Reason: reason));
}
}
17 changes: 16 additions & 1 deletion src/ApiService/ApiService/onefuzzlib/NodeOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public async Task<OneFuzzResult<Node>> AcquireScaleInProtection(Node node) {
if (node.ScalesetId is ScalesetId scalesetId &&
await TryGetNodeInfo(node) is NodeInfo nodeInfo) {

var metricDimensions = new Dictionary<string, string> {
{"MachineId", node.MachineId.ToString()}
};
_logTracer.Info($"Setting scale-in protection on node {node.MachineId:Tag:MachineId}");

var instanceId = node.InstanceId;
Expand All @@ -110,17 +113,25 @@ await TryGetNodeInfo(node) is NodeInfo nodeInfo) {
var r = await _context.VmssOperations.UpdateScaleInProtection(nodeInfo.Scaleset, instanceId, protectFromScaleIn: true);
if (!r.IsOk) {
_logTracer.Error(r.ErrorV);
_logTracer.Metric($"FailedAcquiringScaleInProtection", 1, metricDimensions);
return r.ErrorV;
}

_logTracer.Metric($"AcquiredScaleInProtection", 1, metricDimensions);
return OneFuzzResult.Ok(node);
}

return OneFuzzResult.Ok(node);
return Error.Create(ErrorCode.INVALID_NODE, "Failed getting NodeInfo. Cannot acquire scale-in protection");
}

public async Task<OneFuzzResultVoid> ReleaseScaleInProtection(Node node) {
if (!node.DebugKeepNode &&
node.ScalesetId is ScalesetId scalesetId &&
await TryGetNodeInfo(node) is NodeInfo nodeInfo) {

var metricDimensions = new Dictionary<string, string> {
{"MachineId", node.MachineId.ToString()}
};
_logTracer.Info($"Removing scale-in protection on node {node.MachineId:Tag:MachineId}");

var instanceId = node.InstanceId;
Expand All @@ -136,7 +147,11 @@ await TryGetNodeInfo(node) is NodeInfo nodeInfo) {
var r = await _context.VmssOperations.UpdateScaleInProtection(nodeInfo.Scaleset, instanceId, protectFromScaleIn: false);
if (!r.IsOk) {
_logTracer.Error(r.ErrorV);
_logTracer.Metric($"FailedReleasingScaleInProtection", 1, metricDimensions);
return r;
}

_logTracer.Metric($"ReleasedScaleInProection", 1, metricDimensions);
return r;
}

Expand Down

0 comments on commit 0f6073b

Please sign in to comment.