-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[prometheusremotewriteexporter] memory leak when downstream prometheus endpoint is slow/non-responsive leads to GC and "out of order" errors #33324
Comments
Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
Oh there is a secondary question here - why does the |
This issue has been inactive for 60 days. It will be closed in 60 days if there is no activity. To ping code owners by adding a component label, see Adding Labels via Comments, or if you are unsure of which component this issue relates to, please ping Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
I believe I have encountered a similar thing. When throttling the output bandwidth of opentelemetry-collector using nftables, I accidentally also applied this to packets being written into a local Prometheus instance. The otelcontribcol process would rapidly increase in memory usage (before taking down the whole system). It did not happen any more when I disabled the prometheusremotewrite exporter or disabled the firewall rule. |
We continue to see this... we're experimenting with a different Prometheus backend, and any time that backend has its push-latency increase into the 100's of ms, the memory footprint on our otel collector pods triples and then they start having to retry and finally start throwing out-of-order write issues (because our primary backed is Amazon AMP). |
It isn't clear to me if this is a memory leak, or if you are simply getting extremely close to your memory limit and constantly GC'ing. I suspect the memory_limiter's additional triggering of GCs is similar to the thrashing behavior described in https://tip.golang.org/doc/gc-guide#Memory_limit. For a memory leak, I would expect to see memory growth over long periods of time, ending with an inevitable OOM even when you have very little throughput. |
Component(s)
exporter/prometheusremotewrite
What happened?
Description
I'm reporting what I think is a memory leak in the
prometheusremotewriteexporter
that is triggered when the downstream prometheus endpoint is either slow to respond or failing entirely. This leak ultimately puts the collector into a GC loop that never recovers, causing impact to all the work that the collector is doing, not just the pipeline with the downstream problems. I've spent the last ~2 days troubleshooting this with AWS and talking through it with @Aneurysm9.Steps to Reproduce
In my test case - we have a set of OTEL Collectors called
metric-aggregators
which accept inbound OTLP Metric data (generally sourced from Prometheus Receivers) and write the data into two different pipelines - call it aproduction
and adebug
pipeline. The data going into these pipelines can be the same, or it can be totally unique. In this case, the data is unique... I havedata=foo -> production
anddata=bar -> debug
essentially.Once the pipeline is humming along, introduce intentional throttling to the Prometheus endpoint on the
debug
pipeline - I did this by settingresources.requests.cpu=1
andresources.limits.cpu=1
... and we're writing ~50-80k datapoints/sec, so that was enough to introduce throttling.Expected Result
My expectation is that the
debug
pipeline will start failing requests (_I'd expect to seecontext deadline exceeded
messages) - and data would ultimately be refused by thebatch
processor, which would in turn refuse data upstream. I expect theproduction
pipeline to continue to operate just fine because there's no impact to its downstream targets.Actual Result
Interestingly, we see impact that starts with the
debug
pipeline, but then spreads to all of the pipelines in the collector. After a period of time (~20-40m), the collectors are completely stuck and are in a GC loop triggered by thememory_limiter
. Data then fails to write to theproduction
pipeline. Additionally, when we un-clog the prometheus debug endpoint, the collector doesn't self recover ... it is stuck in this GC loop essentially indefinitely until we restart the pods.Collector version
0.101.0
Environment information
Environment
OS: BottleRocket 1.19.4
OpenTelemetry Collector configuration
Additional context
Setting the Scene
I think the only way to explain the flow here is to start with a picture, and then talk through the timeline. In this picture, we have 5 graphs that are important to see at the same time.
Metric Datapoints Exported
: This is the graph of successful exported metrics per exporter. The blue and yellow lines are two exporters connected to themetrics/prometheus_prod
pipeline. They are sending "production" data that we've validated. The orange line is themetrics/prometheus_beta
pipeline that is sending data we haven't yet validated - but a high volume of it. The green line is a debug output, it can be ignored.Percentage of Metrics Exported
: This is the success-rate graph for each of the exporters described above.HTTP Response Times - ...amazonaws.com
: This is the response time graph for theprometheusremotewrite/amp
exporter (a local AMP endpoint in the same region/account)HTTP Response Times - ...com
: This is the exporterprometheusremotewrite/centralProd
which happens to be an AMP endpoint, but is cross-account and region (going through a proxy).HTTP Response Times - prometheus-operated
: This is the internalprometheusremotewrite/debug
endpoint which is a single internal prometheus pod attached to theprometheus_beta
pipeline that I used to introduce throttling.Timeline
9:40:00
: Everything is roughly humming along just fine....9:44:00
: Throttling is introduced to theprometheusremotewrite/debug
exporter by reducing the CPU limits on the Prometheus pod. Latency starts to creep up.10:07:00
: We finally start to see the success-rate for theprometheusremotewrite/debug
exporter tank. Note at this point the other two exporters are still operating just fine.10:33:00
: We see a dip in the success-rate for theprometheusremotewrite/centralProd
andprometheusremotewrite/amp
endpoints now.10:37:00
: Success rate tanks on all exporters now other than thedebug
exporter.11:12:00
: I un-cork the Prometheus Pod by unlimiting its CPU and letting it restart. We see immediate response to the latencies for theprometheusremotewrite/debug
exporter (though, it does not drop enough, and starts climbing again)Logs
Obviously we have lots of logs ... but here are two graphs that are interesting. First, just the high level graph of
error
log lines:Rather than looking at the logs individually, I started looking at them in terms of two key messages...
Forcing a GC
andout of order
errors:We can see that roughly at
10:03
we start seeing theForcing a GC
message rates start climbing, and at10:07
and10:36
respectively we see corresponding jumps in theout of order
error messages from the upstream Prometheus endpoints. We never see an active recovery of these metrics, even after we un-corked the downstreamprometheusremotewrite/debug
endpoint.Finally - PPROF...
At @Aneurysm9's suggestion, I grabbed a
profile
and a fewheap
dumps from one pod during this time frame:11:04:00
11:11:00
11:14:00
11:26:00
We can see in the CPU profile that most of the time is spent in GC:
When we look at the heap we can see an interesting memory usage in the
prometheusremotewrite
code:Final thoughts
In this scenario, I expect the
batch
processor to prevent data from getting into the pipeline after the initial ~8-16k datapoints are collected and are failing to send. Once they fail to send, I expect that pressure to push upstream all the way to the receiver. I then expect to not really see any memory problems during this outage, just a blockage of the data going to theprometheusremotewrite/debug
endpoint.Instead I believe we see a memory leak in the
prometheusremotewrite
code. When that leak happens, it has the downstream impact of eventually tripping thememory_limiter
circuit breaker which then starts forcing GCs ... but these GCs can't recover the data, so it just happens over and over and over again. This cycle then causes impact to the rest of the data pipeline flowing through the collector.Lastly, I think this memory leak has some critical impact to the data payloads themselves sent to Prometheus which then causes duplicate or out-of-order samples to be sent that normally would not be, and this further exasterbates the problem.
The text was updated successfully, but these errors were encountered: