mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-18 12:48:07 +00:00
Don't log an error if we delete a Repro and it is already missing (#2563)
This commit is contained in:
@ -114,7 +114,7 @@ public class ReproVmss {
|
||||
var updatedRepro = vm with { State = VmState.Stopping };
|
||||
var r = await _context.ReproOperations.Replace(updatedRepro);
|
||||
if (!r.IsOk) {
|
||||
_log.WithHttpStatus(r.ErrorV!).Error($"Failed to replace repro {updatedRepro.VmId:Tag:VmId}");
|
||||
_log.WithHttpStatus(r.ErrorV).Error($"Failed to replace repro {updatedRepro.VmId:Tag:VmId}");
|
||||
}
|
||||
|
||||
var response = req.CreateResponse(HttpStatusCode.OK);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using Microsoft.ApplicationInsights;
|
||||
@ -188,7 +189,7 @@ public interface ILogTracer {
|
||||
|
||||
ILogTracer WithTag(string k, string v);
|
||||
ILogTracer WithTags(IEnumerable<(string, string)>? tags);
|
||||
ILogTracer WithHttpStatus((int, string) status);
|
||||
ILogTracer WithHttpStatus((HttpStatusCode Status, string Reason) result);
|
||||
}
|
||||
|
||||
internal interface ILogTracerInternal : ILogTracer {
|
||||
@ -252,8 +253,12 @@ public class LogTracer : ILogTracerInternal {
|
||||
return WithTags(new[] { (k, v) });
|
||||
}
|
||||
|
||||
public ILogTracer WithHttpStatus((int, string) status) {
|
||||
(string, string)[] tags = { ("StatusCode", status.Item1.ToString()), ("ReasonPhrase", status.Item2) };
|
||||
public ILogTracer WithHttpStatus((HttpStatusCode Status, string Reason) result) {
|
||||
(string, string)[] tags = {
|
||||
("StatusCode", ((int)result.Status).ToString()),
|
||||
("ReasonPhrase", result.Reason),
|
||||
};
|
||||
|
||||
return WithTags(tags);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Text.Json;
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using ApiService.OneFuzzLib.Orm;
|
||||
using Azure;
|
||||
@ -10,7 +11,7 @@ namespace Microsoft.OneFuzz.Service;
|
||||
|
||||
public interface IAutoScaleOperations {
|
||||
|
||||
public Async.Task<ResultVoid<(int, string)>> Insert(AutoScale autoScale);
|
||||
public Async.Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Insert(AutoScale autoScale);
|
||||
|
||||
public Async.Task<AutoScale?> GetSettingsForScaleset(Guid scalesetId);
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using ApiService.OneFuzzLib.Orm;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
|
||||
@ -32,7 +33,7 @@ public class ConfigOperations : Orm<InstanceConfig>, IConfigOperations {
|
||||
|
||||
public async Async.Task Save(InstanceConfig config, bool isNew = false, bool requireEtag = false) {
|
||||
var newConfig = config with { InstanceName = _context.ServiceConfiguration.OneFuzzInstanceName ?? throw new Exception("Environment variable ONEFUZZ_INSTANCE_NAME is not set") };
|
||||
ResultVoid<(int, string)> r;
|
||||
ResultVoid<(HttpStatusCode Status, string Reason)> r;
|
||||
if (isNew) {
|
||||
r = await Insert(newConfig);
|
||||
if (!r.IsOk) {
|
||||
|
@ -385,7 +385,7 @@ public class NodeOperations : StatefulOrm<Node, NodeState, NodeOperations>, INod
|
||||
|
||||
var node = new Node(poolName, machineId, poolId, version, ScalesetId: scaleSetId);
|
||||
|
||||
ResultVoid<(int, string)> r;
|
||||
ResultVoid<(HttpStatusCode Status, string Reason)> r;
|
||||
if (isNew) {
|
||||
try {
|
||||
r = await Insert(node);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using ApiService.OneFuzzLib.Orm;
|
||||
using Azure.ResourceManager.Compute.Models;
|
||||
@ -111,9 +112,10 @@ public class ReproOperations : StatefulOrm<Repro, VmState, ReproOperations>, IRe
|
||||
// BUG?: why are we updating repro and then deleting it and returning a new value
|
||||
repro = repro with { State = VmState.Stopped };
|
||||
var r = await Delete(repro);
|
||||
if (!r.IsOk) {
|
||||
if (!r.IsOk && r.ErrorV.Status != HttpStatusCode.NotFound) {
|
||||
_logTracer.WithHttpStatus(r.ErrorV).Error($"failed to delete repro {repro.VmId:Tag:VmId} marked as stopped");
|
||||
}
|
||||
|
||||
return repro;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Azure;
|
||||
using Azure.Core;
|
||||
using Azure.Data.Tables;
|
||||
@ -69,7 +70,7 @@ public class VmssOperations : IVmssOperations {
|
||||
var result = await r.DeleteAsync(WaitUntil.Started, forceDeletion: forceDeletion);
|
||||
var raw = result.GetRawResponse();
|
||||
if (raw.IsError) {
|
||||
_log.WithHttpStatus((raw.Status, raw.ReasonPhrase)).Error($"Failed to delete vmss: {name:Tag:VmssName}");
|
||||
_log.WithHttpStatus(((HttpStatusCode)raw.Status, raw.ReasonPhrase)).Error($"Failed to delete vmss: {name:Tag:VmssName}");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Azure;
|
||||
@ -14,10 +15,10 @@ namespace ApiService.OneFuzzLib.Orm {
|
||||
IAsyncEnumerable<T> QueryAsync(string? filter = null);
|
||||
|
||||
Task<T> GetEntityAsync(string partitionKey, string rowKey);
|
||||
Task<ResultVoid<(int, string)>> Insert(T entity);
|
||||
Task<ResultVoid<(int, string)>> Replace(T entity);
|
||||
Task<ResultVoid<(int, string)>> Update(T entity);
|
||||
Task<ResultVoid<(int, string)>> Delete(T entity);
|
||||
Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Insert(T entity);
|
||||
Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Replace(T entity);
|
||||
Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Update(T entity);
|
||||
Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Delete(T entity);
|
||||
|
||||
Task<DeleteAllResult> DeleteAll(IEnumerable<(string?, string?)> keys);
|
||||
|
||||
@ -62,34 +63,34 @@ namespace ApiService.OneFuzzLib.Orm {
|
||||
|
||||
/// Inserts the entity into table storage.
|
||||
/// If successful, updates the ETag of the passed-in entity.
|
||||
public async Task<ResultVoid<(int, string)>> Insert(T entity) {
|
||||
public async Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Insert(T entity) {
|
||||
var tableClient = await GetTableClient(typeof(T).Name);
|
||||
var tableEntity = _entityConverter.ToTableEntity(entity);
|
||||
var response = await tableClient.AddEntityAsync(tableEntity);
|
||||
|
||||
|
||||
if (response.IsError) {
|
||||
return ResultVoid<(int, string)>.Error((response.Status, response.ReasonPhrase));
|
||||
return ResultVoid<(HttpStatusCode, string)>.Error(((HttpStatusCode)response.Status, response.ReasonPhrase));
|
||||
} else {
|
||||
// update ETag
|
||||
entity.ETag = response.Headers.ETag;
|
||||
|
||||
return ResultVoid<(int, string)>.Ok();
|
||||
return ResultVoid<(HttpStatusCode, string)>.Ok();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultVoid<(int, string)>> Replace(T entity) {
|
||||
public async Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Replace(T entity) {
|
||||
var tableClient = await GetTableClient(typeof(T).Name);
|
||||
var tableEntity = _entityConverter.ToTableEntity(entity);
|
||||
var response = await tableClient.UpsertEntityAsync(tableEntity, TableUpdateMode.Replace);
|
||||
if (response.IsError) {
|
||||
return ResultVoid<(int, string)>.Error((response.Status, response.ReasonPhrase));
|
||||
return ResultVoid<(HttpStatusCode, string)>.Error(((HttpStatusCode)response.Status, response.ReasonPhrase));
|
||||
} else {
|
||||
return ResultVoid<(int, string)>.Ok();
|
||||
return ResultVoid<(HttpStatusCode, string)>.Ok();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ResultVoid<(int, string)>> Update(T entity) {
|
||||
public async Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Update(T entity) {
|
||||
if (entity.ETag is null) {
|
||||
throw new ArgumentException("ETag must be set when updating an entity", nameof(entity));
|
||||
}
|
||||
@ -99,9 +100,9 @@ namespace ApiService.OneFuzzLib.Orm {
|
||||
|
||||
var response = await tableClient.UpdateEntityAsync(tableEntity, entity.ETag.Value);
|
||||
if (response.IsError) {
|
||||
return ResultVoid<(int, string)>.Error((response.Status, response.ReasonPhrase));
|
||||
return ResultVoid<(HttpStatusCode, string)>.Error(((HttpStatusCode)response.Status, response.ReasonPhrase));
|
||||
} else {
|
||||
return ResultVoid<(int, string)>.Ok();
|
||||
return ResultVoid<(HttpStatusCode, string)>.Ok();
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,14 +119,14 @@ namespace ApiService.OneFuzzLib.Orm {
|
||||
return tableClient.GetTableClient(tableName);
|
||||
}
|
||||
|
||||
public async Task<ResultVoid<(int, string)>> Delete(T entity) {
|
||||
public async Task<ResultVoid<(HttpStatusCode Status, string Reason)>> Delete(T entity) {
|
||||
var tableClient = await GetTableClient(typeof(T).Name);
|
||||
var tableEntity = _entityConverter.ToTableEntity(entity);
|
||||
var response = await tableClient.DeleteEntityAsync(tableEntity.PartitionKey, tableEntity.RowKey);
|
||||
if (response.IsError) {
|
||||
return ResultVoid<(int, string)>.Error((response.Status, response.ReasonPhrase));
|
||||
return ResultVoid<(HttpStatusCode, string)>.Error(((HttpStatusCode)response.Status, response.ReasonPhrase));
|
||||
} else {
|
||||
return ResultVoid<(int, string)>.Ok();
|
||||
return ResultVoid<(HttpStatusCode, string)>.Ok();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
@ -48,7 +49,7 @@ sealed class TestLogTracer : ILogTracer {
|
||||
_output.WriteLine($"[Warning] {message.ToString()}");
|
||||
}
|
||||
|
||||
public ILogTracer WithHttpStatus((int, string) status) {
|
||||
public ILogTracer WithHttpStatus((HttpStatusCode Status, string Reason) result) {
|
||||
return this; // TODO?
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user