Skip to content

Commit 2b2806b

Browse files
Refactor the memory information retriever to check the content schema
1 parent 8711436 commit 2b2806b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,16 @@ record MemoryInformation
2222
public string DirtyMemory { get; set; }
2323
}
2424

25-
public async Task<(bool IsHighDirty, int DirtyMemory)> GetMemoryInformation(CancellationToken cancellationToken = default)
25+
public async Task<(bool IsHighDirty, int DirtyMemoryKb)> GetMemoryInformation(CancellationToken cancellationToken = default)
2626
{
2727
var httpResponse = await client.GetAsync("/admin/debug/memory/stats", cancellationToken);
2828
var responseDto = JsonSerializer.Deserialize<ResponseDto>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));
2929

30-
return (responseDto.MemoryInformation.IsHighDirty, int.Parse(responseDto.MemoryInformation.DirtyMemory.Split(' ').First()));
30+
var values = responseDto.MemoryInformation.DirtyMemory.Split(' ');
31+
if (!string.Equals(values[1],"KBytes", StringComparison.OrdinalIgnoreCase))
32+
{
33+
throw new InvalidOperationException($"Unexpected response. Was expecting memory details in KBytes, instead received: {responseDto.MemoryInformation.DirtyMemory}");
34+
}
35+
return (responseDto.MemoryInformation.IsHighDirty, int.Parse(values[0]));
3136
}
3237
}

0 commit comments

Comments
 (0)