From 350bb01c653ab640e586531bba6e4527f4feb622 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Fri, 25 Sep 2015 13:29:47 -0400 Subject: [PATCH 1/2] Fix the GzippedWhisperReader The GzippedWhisperReader would attempt to use a private method in python. Since methods starting with `__` are treated specially in python by prepending `_$class` before attempting to invoke the method, this code didn't work for accessing the private module method `__readHeader` that exists in the whisper module. --- graphite_api/finders/whisper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphite_api/finders/whisper.py b/graphite_api/finders/whisper.py index e643006..e9e9b8f 100644 --- a/graphite_api/finders/whisper.py +++ b/graphite_api/finders/whisper.py @@ -133,7 +133,7 @@ class GzippedWhisperReader(WhisperReader): def get_intervals(self): fh = gzip.GzipFile(self.fs_path, 'rb') try: - info = whisper.__readHeader(fh) # evil, but necessary. + info = getattr(whisper, '__readHeader')(fh) # evil, but necessary. finally: fh.close() From 3a4db59b58523838b72de03d21d45a68557724c0 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Tue, 29 Sep 2015 13:46:24 -0400 Subject: [PATCH 2/2] Limit the results of the carbon query to only the current range The carbon query will return all cached datapoints. This includes values that are outside of your current query. When the carbonlink attempts to put these values in the returned array, an index error gets thrown. This causes a lot of errors that get thrown when datapoints are cached and the requested range does not match the timestamps of the cached datapoints. Teach the carbon query how to limit which metrics get inserted into the cache based on their timestamps. --- graphite_api/finders/whisper.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/graphite_api/finders/whisper.py b/graphite_api/finders/whisper.py index e9e9b8f..feffa21 100644 --- a/graphite_api/finders/whisper.py +++ b/graphite_api/finders/whisper.py @@ -122,6 +122,9 @@ def fetch(self, startTime, endTime): # noqa if isinstance(cached_datapoints, dict): cached_datapoints = cached_datapoints.items() for timestamp, value in sorted(cached_datapoints): + # filter only to cached datapoints within [start, end) + if not (timestamp >= start and timestamp < end): + continue interval = timestamp - (timestamp % step) i = int(interval - start) // step values[i] = value