← Back to team overview

graphite-dev team mailing list archive

Re: [Question #205774]: exceptions.TypeError: must be encoded string without NULL bytes, not str

 

Seems like the error in the trace is pretty self explanatory. What is the name of the metric you are sending? Some portion of your metric name (dbFilePath) must contain a null which is not allowed by os.path.exists(). Since the metric names are fully controlled by whatever program you are using to ingest metrics the problem is unlikely to be in the carbon-cache code.

It would be possible to do checking in MetricLineReceiver, MetricDatagramReceiver and MetricPickle Receiver; but I think this would incur an unnecessary performance penalty since it would hit once per datapoint received. Alternatively, the approach I think is correct, would be to modify writeCachedDataPoints in writer.py to check the metric name inside the 'if not dbFileExists:' block and raise a log event for invalid metric names AND pop the metrics out of cache at the same time. This would incur the check penalty only on attempted creation of bad metrics.

-Dave

On 08/16/2012 09:21 AM, Mike Wylie wrote:
Question #205774 on Graphite changed:
https://answers.launchpad.net/graphite/+question/205774

Mike Wylie posted a new comment:
I had a look at the code in the exception trace and had a
though....would I be taking my life in my hands if I altered the file
/opt/graphite/lib/carbon/writer.py, to send the metric to the log file,
just before trying to look for its path?  This may give me an idea what
it's failing to work with.

Would I need to restart something for the code to take affect?

I'm not a real python programmer, but I can understand the basics, I was
thinking something along the lines of:

def optimalWriteOrder():
   "Generates metrics with the most cached values first and applies a soft rate limit on new metrics"
   global lastCreateInterval
   global createCount
   metrics = MetricCache.counts()

   t = time.time()
   metrics.sort(key=lambda item: item[1], reverse=True) # by queue size, descending
   log.msg("Sorted %d cache queues in %.6f seconds" % (len(metrics), time.time() - t))

   for metric, queueSize in metrics:
     if state.cacheTooFull and MetricCache.size < CACHE_SIZE_LOW_WATERMARK:
       events.cacheSpaceAvailable()
# ------------------------------------------------
# my new piece of code
#
     log.msg("reviewing metric:"+metric)
# ------------------------------------------------
     dbFilePath = getFilesystemPath(metric)
     dbFileExists = exists(dbFilePath)




References