serilog-contrib / serilog-sinks-grafana-loki

A Serilog sink sending log events to Grafana Loki
MIT License
201 stars 30 forks source link

Potential Memory Leak #167

Closed garethparris closed 1 year ago

garethparris commented 1 year ago

Which version of Serilog.Sinks.Grafana.Loki are you using?

v8.1.0

Which version of .NET are you using?

net6.0

Describe the bug

I've created a simple Prometheus .NET Exporter using Serilog and the Serilog Grafana Loki library.

On start-up of the application I can see it uses approximately 30,000 k active private working set. If I leave it running and do nothing, no requests, the private working set memory increases slowly over time. I have seen this in the GBs on my production servers.

On searching and profiling the code I commented out the loggerConfiguration.WriteTo.GrafanaLoki(lokiUrl, labels) section and I observed that memory no longer increases over time.

To Reproduce

Create a simple ASP .NET 6 Application with a basic page. Leave it running and see memory increase over time.

Expected behavior

I expect the application to start up and when it is doing no work for its memory use to be stable and not increase over time.

Log/SelfLog output or exception with stacktrace

No response

Application or code sample, which could be used to reproduce a bug

No response

Additional context

Whilst I am using Prometheus .NET I am not calling any of the methods after the initial request.

I have read the documentation

mishamyte commented 1 year ago

Hi @prime23-gareth,

Feels like your logs not being delivered to Loki and they are keeping storing in memory.

To investigate this problem I suggest using Serilog's SelfLog and check stdout for diagnostic info of this Sink as described in Common problems section.

Also it is reasonable to restrict queue limit with queueLimit parameter. Available parameters are described here.

But I suggest that SelfLog will give you useful info. So, please, if you would have a time, try out with this parameter and tell me would be there any additional info.

Thanks!

garethparris commented 1 year ago

Thank you for your quick response. I've added SelfLog but its showing no errors. I also tried adding queueLimit:1 as a test and that does seem to dramatically decrease the memory increment but it does not stop it.

mishamyte commented 1 year ago

@prime23-gareth, OK, got it.

Could you please share the test app with your configuration and give me some details about your environment? Because we running sink for 2+ years and seems like all works like a charm. Plus hadn't heard about problems like that from Sink users.

So I wondering where is the problem.

And also could you confirm pls that Loki receiving logs correctly?

garethparris commented 1 year ago

I'll need to remove some private code but ill rewrite when i get a chance.

mishamyte commented 1 year ago

Yes, sure. I will keep my eye on it

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.