Skip to content

Commit 06ff903

Browse files
Do not try to parse the RavenDB dirty memory value
The unit might change unexpectedly. Instead, treat it as a string.
1 parent f108194 commit 06ff903

File tree

4 files changed

+8
-18
lines changed

4 files changed

+8
-18
lines changed

src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class CheckDirtyMemory(MemoryInformationRetriever memoryInformationRetriever) :
1010
{
1111
public override async Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
1212
{
13-
var (isHighDirty, dirtyMemoryKb) = await memoryInformationRetriever.GetMemoryInformation(cancellationToken);
13+
var (isHighDirty, dirtyMemory) = await memoryInformationRetriever.GetMemoryInformation(cancellationToken);
1414

1515
if (isHighDirty)
1616
{
17-
var message = $"There is a high level of RavenDB dirty memory ({dirtyMemoryKb}kb). See https://docs.particular.net/servicecontrol/troubleshooting#ravendb-dirty-memory for guidance on how to mitigate the issue.";
17+
var message = $"There is a high level of RavenDB dirty memory ({dirtyMemory}). See https://docs.particular.net/servicecontrol/troubleshooting#ravendb-dirty-memory for guidance on how to mitigate the issue.";
1818
Log.Warn(message);
1919
return CheckResult.Failed(message);
2020
}

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ record MemoryInformation
2626
public string DirtyMemory { get; set; }
2727
}
2828

29-
public async Task<(bool IsHighDirty, int DirtyMemoryKb)> GetMemoryInformation(CancellationToken cancellationToken = default)
29+
public async Task<(bool IsHighDirty, string DirtyMemory)> GetMemoryInformation(CancellationToken cancellationToken = default)
3030
{
3131
var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken);
3232
var responseDto = JsonSerializer.Deserialize<ResponseDto>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));
3333

34-
var values = responseDto.MemoryInformation.DirtyMemory.Split(' ');
35-
if (!string.Equals(values[1], "KBytes", StringComparison.OrdinalIgnoreCase))
36-
{
37-
throw new InvalidOperationException($"Unexpected response. Was expecting memory details in KBytes, instead received: {responseDto.MemoryInformation.DirtyMemory}");
38-
}
39-
return (responseDto.MemoryInformation.IsHighDirty, int.Parse(values[0]));
34+
return (responseDto.MemoryInformation.IsHighDirty, responseDto.MemoryInformation.DirtyMemory);
4035
}
4136
}

src/ServiceControl.Persistence.RavenDB/CustomChecks/CheckDirtyMemory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ class CheckDirtyMemory(MemoryInformationRetriever memoryInformationRetriever) :
1010
{
1111
public override async Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
1212
{
13-
var (isHighDirty, dirtyMemoryKb) = await memoryInformationRetriever.GetMemoryInformation(cancellationToken);
13+
var (isHighDirty, dirtyMemory) = await memoryInformationRetriever.GetMemoryInformation(cancellationToken);
1414

1515
if (isHighDirty)
1616
{
17-
var message = $"There is a high level of RavenDB dirty memory ({dirtyMemoryKb}kb). See https://docs.particular.net/servicecontrol/troubleshooting#ravendb-dirty-memory for guidance on how to mitigate the issue.";
17+
var message = $"There is a high level of RavenDB dirty memory ({dirtyMemory}). See https://docs.particular.net/servicecontrol/troubleshooting#ravendb-dirty-memory for guidance on how to mitigate the issue.";
1818
Log.Warn(message);
1919
return CheckResult.Failed(message);
2020
}

src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ record MemoryInformation
2525
public string DirtyMemory { get; set; }
2626
}
2727

28-
public async Task<(bool IsHighDirty, int DirtyMemoryKb)> GetMemoryInformation(CancellationToken cancellationToken = default)
28+
public async Task<(bool IsHighDirty, string DirtyMemory)> GetMemoryInformation(CancellationToken cancellationToken = default)
2929
{
3030
var httpResponse = await client.GetAsync("/admin/debug/memory/stats?includeThreads=false&includeMappings=false", cancellationToken);
3131
var responseDto = JsonSerializer.Deserialize<ResponseDto>(await httpResponse.Content.ReadAsStringAsync(cancellationToken));
3232

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

0 commit comments

Comments
 (0)