Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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