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

Commit 0f6073b

Browse files
authored
Fix bug for scale-in protection (#3144)
* Fix bug for scale-in protection * Update metric name
1 parent 98007be commit 0f6073b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/ApiService/ApiService/Functions/AgentCanSchedule.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ private async Async.Task<HttpResponseData> Post(HttpRequestData req) {
6262
}
6363
_ = scp.OkV; // node could be updated but we don't use it after this
6464
allowed = scp.IsOk;
65+
66+
if (allowed) {
67+
_log.Metric($"TaskAllowedToSchedule", 1, new Dictionary<string, string> {
68+
{"MachineId", node.MachineId.ToString()},
69+
{"TaskId", task is not null ? task.TaskId.ToString() : string.Empty}
70+
});
71+
}
72+
6573
return await RequestHandling.Ok(req, new CanSchedule(Allowed: allowed, WorkStopped: workStopped, Reason: reason));
6674
}
6775
}

src/ApiService/ApiService/onefuzzlib/NodeOperations.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ public async Task<OneFuzzResult<Node>> AcquireScaleInProtection(Node node) {
9191
if (node.ScalesetId is ScalesetId scalesetId &&
9292
await TryGetNodeInfo(node) is NodeInfo nodeInfo) {
9393

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

9699
var instanceId = node.InstanceId;
@@ -110,17 +113,25 @@ await TryGetNodeInfo(node) is NodeInfo nodeInfo) {
110113
var r = await _context.VmssOperations.UpdateScaleInProtection(nodeInfo.Scaleset, instanceId, protectFromScaleIn: true);
111114
if (!r.IsOk) {
112115
_logTracer.Error(r.ErrorV);
116+
_logTracer.Metric($"FailedAcquiringScaleInProtection", 1, metricDimensions);
117+
return r.ErrorV;
113118
}
119+
120+
_logTracer.Metric($"AcquiredScaleInProtection", 1, metricDimensions);
121+
return OneFuzzResult.Ok(node);
114122
}
115123

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

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

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

126137
var instanceId = node.InstanceId;
@@ -136,7 +147,11 @@ await TryGetNodeInfo(node) is NodeInfo nodeInfo) {
136147
var r = await _context.VmssOperations.UpdateScaleInProtection(nodeInfo.Scaleset, instanceId, protectFromScaleIn: false);
137148
if (!r.IsOk) {
138149
_logTracer.Error(r.ErrorV);
150+
_logTracer.Metric($"FailedReleasingScaleInProtection", 1, metricDimensions);
151+
return r;
139152
}
153+
154+
_logTracer.Metric($"ReleasedScaleInProection", 1, metricDimensions);
140155
return r;
141156
}
142157

0 commit comments

Comments
 (0)