Skip to content

Commit 72a2edf

Browse files
Do not try to parse the RavenDB dirty memory value (#4881)
* Do not try to parse the RavenDB dirty memory value The unit might change unexpectedly. Instead, treat it as a string. * Always debug log the dirty memory value
1 parent f108194 commit 72a2edf

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ 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);
14+
15+
Log.Debug($"RavenDB dirty memory value: {dirtyMemory}.");
1416

1517
if (isHighDirty)
1618
{
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.";
19+
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.";
1820
Log.Warn(message);
1921
return CheckResult.Failed(message);
2022
}

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ 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);
14+
15+
Log.Debug($"RavenDB dirty memory value: {dirtyMemory}.");
1416

1517
if (isHighDirty)
1618
{
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.";
19+
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.";
1820
Log.Warn(message);
1921
return CheckResult.Failed(message);
2022
}

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)