carbon icon indicating copy to clipboard operation
carbon copied to clipboard

Exception in cacheFull event handler: args=() kwargs={} Traceback (most recent call last):

Open DannyXuEverbridge opened this issue 10 years ago • 17 comments

On version 0.9.15 for carbon, there still exist the problem:

13/01/2016 10:20:15 :: MetricCache is full: self.size=1000000 13/01/2016 10:20:15 :: Exception in cacheFull event handler: args=() kwargs={} Traceback (most recent call last): File "/opt/graphite/lib/carbon/protocols.py", line 78, in lineReceived self.metricReceived(metric, datapoint) File "/opt/graphite/lib/carbon/protocols.py", line 64, in metricReceived events.metricReceived(metric, datapoint) File "/opt/graphite/lib/carbon/events.py", line 20, in call handler(_args, *_kwargs) File "/opt/graphite/lib/carbon/cache.py", line 48, in store events.cacheFull() --- --- File "/opt/graphite/lib/carbon/events.py", line 20, in call handler(_args, *_kwargs) File "/opt/graphite/lib/carbon/events.py", line 32, in cacheFull.addHandler(lambda: state.instrumentation.increment('cache.overflow')) exceptions.AttributeError: 'module' object has no attribute 'instrumentation'

DannyXuEverbridge avatar Jan 13 '16 10:01 DannyXuEverbridge

same same here, carbon-0.9.15:

17/02/2016 15:05:49 :: Exception in cacheFull event handler: args=() kwargs={}Traceback (most recent call last):  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 393, in callback    self._startRunCallbacks(result)  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 501, in _startRunCallbacks    self._runCallbacks()  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 588, in _runCallbacks    current.result = callback(current.result, *args, **kw)  File "/opt/graphite/lib/carbon/client.py", line 114, in queueFullCallback    --- <exception caught here> ---  File "/opt/graphite/lib/carbon/events.py", line 20, in __call__      File "/opt/graphite/lib/carbon/events.py", line 32, in <lambda>

gretel avatar Feb 17 '16 16:02 gretel

I encountered this as well when playing with MAX_CACHE_SIZE and MAX_UPDATES_PER_SECOND. I deliberately set the the latter one to 1 and the former one to a small number and let the queues pile up. The moment the cache is full, I get the Traceback:

18/03/2016 09:41:32 :: [console] MetricCache is full: self.size=20009
18/03/2016 09:41:32 :: [console] Exception in cacheFull event handler: args=() kwargs={}
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/carbon/protocols.py", line 78, in lineReceived
    self.metricReceived(metric, datapoint)
  File "/usr/lib/python2.7/site-packages/carbon/protocols.py", line 64, in metricReceived
    events.metricReceived(metric, datapoint)
  File "/usr/lib/python2.7/site-packages/carbon/events.py", line 20, in __call__
    handler(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/carbon/cache.py", line 48, in store
    events.cacheFull()
--- <exception caught here> ---
  File "/usr/lib/python2.7/site-packages/carbon/events.py", line 20, in __call__
    handler(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/carbon/events.py", line 32, in <lambda>
    cacheFull.addHandler(lambda: carbon.instrumentation.increment('cache.overflow'))
exceptions.NameError: global name 'carbon' is not defined

A simple search indicates that this is fixed in post-0.9.15 versions: https://github.com/graphite-project/carbon/pull/486

Haven't tested it yet.

wzyboy avatar Mar 18 '16 01:03 wzyboy

Well, the patch in #486 does not work for me. This may be a new issue.

wzyboy avatar Mar 18 '16 02:03 wzyboy

Can you check if #534 fixes the issue for you ?

iksaif avatar Mar 18 '16 10:03 iksaif

It just occurred to me that the version I use and the version @DannyXuEverbridge use may not be the same version. I am using 0.9.15 version installed from PyPI, and I confirm that the 32rd line of my events.py uses carbon.instrumentation: https://github.com/graphite-project/carbon/blob/0.9.15/lib/carbon/events.py#L32 . Object carbon is nevered imported in events.py so that's why I got NameError.

However, in the Traceback of @DannyXuEverbridge , I could see the 32rd line of events.py uses state.instrumentation. Though @DannyXuEverbridge says he is using 0.9.15, I recommend him double checking.

wzyboy avatar Mar 18 '16 16:03 wzyboy

I'm talking about 0.9.15 tag from this repo.

That has been changed between 7617bc5 and 4c8d035.

Trying to fix the problem (I'm not a python guy) I've tried to change https://github.com/graphite-project/carbon/blob/0.9.15/lib/carbon/events.py#L32 in many different ways:

cacheFull.addHandler(lambda: carbon.instrumentation.increment('cache.overflow')) cacheFull.addHandler(lambda: instrumentation.increment('cache.overflow'))

But neither of then have worked, my next try was to import instrumentation module and even only the increment function of that same module. When I try to do that the carbon doesn't even start because a circular dependency between events -> instrumentation -> events -> cache -> events

biancalana avatar Apr 01 '16 15:04 biancalana

+1 still a problem

frlinux avatar Apr 05 '16 23:04 frlinux

@wzyboy @biancalana and @frlinux : did you try #534 ?

iksaif avatar Apr 06 '16 07:04 iksaif

@iksaif Great ! #534 fix for me !

biancalana avatar Apr 06 '16 18:04 biancalana

@obfuscurity can #534 be merged ?

biancalana avatar Jun 10 '16 13:06 biancalana

@biancalana: will it fix this issue?

deniszh avatar Jun 10 '16 13:06 deniszh

According to @frlinux it doesn't fix the issue.

obfuscurity avatar Jun 10 '16 13:06 obfuscurity

@obfuscurity @deniszh it fix for me, actually I'm running this on production.... Anyway, It was always easy to reproduce, I will install a test env a try again...

biancalana avatar Jun 10 '16 13:06 biancalana

I think that @frlinux tried to apply the patch on the wrong branch.

iksaif avatar Jun 10 '16 13:06 iksaif

@obfuscurity @deniszh @iksaif

I can confirm that it fixes the problem.

I did a fresh install using 0.9.x branch, changed MAX_CACHE_SIZE and MAX_UPDATES_PER_SECOND to very small values (100 and 5 respectively) and generate some metrics using:

#!/bin/bash
while [ 1 ]; do

        a=$(date '+%s')
        let x=0

        while [[ $x -lt 1000 ]];
        do
                echo "prod.bla.$x 10 $a"
                x=$((x+1))
        done
done | nc 127.0.0.1 2003

Without the patch I see a lot of exceptions like:

10/06/2016 14:20:41 :: [console] MetricCache is full: self.size=1000
10/06/2016 14:20:41 :: [console] Exception in cacheFull event handler: args=() kwargs={}
Traceback (most recent call last):
  File "/opt/graphite/lib/carbon/protocols.py", line 78, in lineReceived
    self.metricReceived(metric, datapoint)
  File "/opt/graphite/lib/carbon/protocols.py", line 64, in metricReceived
    events.metricReceived(metric, datapoint)
  File "/opt/graphite/lib/carbon/events.py", line 20, in __call__
    handler(*args, **kwargs)
  File "/opt/graphite/lib/carbon/cache.py", line 48, in store
    events.cacheFull()
--- <exception caught here> ---
  File "/opt/graphite/lib/carbon/events.py", line 20, in __call__
    handler(*args, **kwargs)
  File "/opt/graphite/lib/carbon/events.py", line 32, in <lambda>
    cacheFull.addHandler(lambda: state.instrumentation.increment('cache.overflow'))
exceptions.AttributeError: 'module' object has no attribute 'instrumentation'

After the patch, there is no exceptions anymore:

10/06/2016 14:22:09 :: [console] MetricCache is full: self.size=995
10/06/2016 14:22:09 :: [console] MetricCache is full: self.size=996
10/06/2016 14:22:09 :: [console] MetricCache is full: self.size=997
10/06/2016 14:22:09 :: [console] MetricCache is full: self.size=998
10/06/2016 14:22:09 :: [console] MetricCache is full: self.size=999
10/06/2016 14:22:09 :: [console] MetricCache is full: self.size=1000
10/06/2016 14:22:10 :: [console] Sorted 1000 cache queues in 0.000469 seconds
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=719
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=720
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=721
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=722
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=723
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=724
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=725
10/06/2016 14:23:06 :: [console] MetricCache is full: self.size=726

biancalana avatar Jun 10 '16 14:06 biancalana

I can confirm I applied to the wrong branch, please disregard my comments. I meant to respond to this but forgot :(

frlinux avatar Jun 10 '16 15:06 frlinux

Merged #534, closing this.

obfuscurity avatar Jun 10 '16 16:06 obfuscurity