Browse Source

add pickle support for graphtie-web 1.0

 * Copy-paste https://github.com/lomik/go-carbon/blob/master/carbonserver/pickle.go
 * Add necessary fields to pickle to support both
   Note: it will add extra overhead to support both, but that should be relatively small
Vladimir Smirnov 1 year ago
parent
commit
c0b37d29e8
4 changed files with 80 additions and 11 deletions
  1. 7
    7
      Gopkg.lock
  2. 3
    3
      Gopkg.toml
  3. 59
    0
      intervalset/intervalset.go
  4. 11
    1
      main.go

+ 7
- 7
Gopkg.lock View File

@@ -1,4 +1,4 @@
1
-memo = "461a0bacca1df6cb0d329ca352973bcc59369258d7fddb948e9f52496ef37f67"
1
+memo = "ada979fc2a716872a286900b97181b8b1265fec0006386a62e773f67ab892312"
2 2
 
3 3
 [[projects]]
4 4
   branch = "master"
@@ -68,12 +68,6 @@ memo = "461a0bacca1df6cb0d329ca352973bcc59369258d7fddb948e9f52496ef37f67"
68 68
 
69 69
 [[projects]]
70 70
   branch = "master"
71
-  name = "github.com/kisielk/og-rek"
72
-  packages = ["."]
73
-  revision = "28bae785206e71d70d9c770903d06abb87547734"
74
-
75
-[[projects]]
76
-  branch = "master"
77 71
   name = "github.com/lestrrat/go-file-rotatelogs"
78 72
   packages = ["."]
79 73
   revision = "505c036604b3326a96097ca91865df30043093a5"
@@ -85,6 +79,12 @@ memo = "461a0bacca1df6cb0d329ca352973bcc59369258d7fddb948e9f52496ef37f67"
85 79
   revision = "04ef93e285313c8978cbc7cad26d2aa7a9927451"
86 80
 
87 81
 [[projects]]
82
+  branch = "master"
83
+  name = "github.com/lomik/og-rek"
84
+  packages = ["."]
85
+  revision = "628eefeb8d8065e3c4300d3556181a255d1ab4ff"
86
+
87
+[[projects]]
88 88
   name = "github.com/lomik/zapwriter"
89 89
   packages = ["."]
90 90
   revision = "d4499a33b5929c4a2e7e169165f594f35b39638c"

+ 3
- 3
Gopkg.toml View File

@@ -29,15 +29,15 @@
29 29
 
30 30
 [[dependencies]]
31 31
   branch = "master"
32
-  name = "github.com/kisielk/og-rek"
32
+  name = "github.com/lestrrat/go-file-rotatelogs"
33 33
 
34 34
 [[dependencies]]
35 35
   branch = "master"
36
-  name = "github.com/lestrrat/go-file-rotatelogs"
36
+  name = "github.com/lestrrat/go-strftime"
37 37
 
38 38
 [[dependencies]]
39 39
   branch = "master"
40
-  name = "github.com/lestrrat/go-strftime"
40
+  name = "github.com/lomik/og-rek"
41 41
 
42 42
 [[dependencies]]
43 43
   name = "github.com/lomik/zapwriter"

+ 59
- 0
intervalset/intervalset.go View File

@@ -0,0 +1,59 @@
1
+package intervalset
2
+
3
+// Copy paste from https://github.com/lomik/go-carbon/blob/master/carbonserver/pickle.go
4
+// Original license: MIT
5
+// Original author: Roman Lomonosov
6
+
7
+import (
8
+	"encoding/binary"
9
+	"math"
10
+)
11
+
12
+// Fake single interval set for graphite
13
+type IntervalSet struct {
14
+	Start int32
15
+	End   int32
16
+}
17
+
18
+func (i *IntervalSet) MarshalPickle() ([]byte, error) {
19
+	//     0: (    MARK
20
+	//     1: c        GLOBAL     'graphite.intervals IntervalSet'
21
+	//    33: o        OBJ        (MARK at 0)
22
+	//    34: }    EMPTY_DICT
23
+	//    35: (    MARK
24
+	//    36: U        SHORT_BINSTRING 'intervals'
25
+	//    47: ]        EMPTY_LIST
26
+	//    48: (        MARK
27
+	//    49: c            GLOBAL     'graphite.intervals Interval'
28
+	//    78: o            OBJ        (MARK at 48)
29
+	//    79: }        EMPTY_DICT
30
+	//    80: (        MARK
31
+	//    81: U            SHORT_BINSTRING 'start'
32
+	//    88: G            BINFLOAT   1322087998.393128
33
+	//    97: U            SHORT_BINSTRING 'size'
34
+	//   103: G            BINFLOAT   157679977.1475761
35
+	//   112: U            SHORT_BINSTRING 'end'
36
+	//   117: G            BINFLOAT   1479767975.540704
37
+	//   126: U            SHORT_BINSTRING 'tuple'
38
+	//   133: G            BINFLOAT   1322087998.393128
39
+	//   142: G            BINFLOAT   1479767975.540704
40
+	//   151: \x86         TUPLE2
41
+	//   152: u            SETITEMS   (MARK at 80)
42
+	//   153: b        BUILD
43
+	//   154: a        APPEND
44
+	//   155: U        SHORT_BINSTRING 'size'
45
+	//   161: G        BINFLOAT   157679977.1475761
46
+	//   170: u        SETITEMS   (MARK at 35)
47
+	//   171: b    BUILD
48
+	//   172: .    STOP
49
+	b := []byte("(cgraphite.intervals\nIntervalSet\no}(U\tintervals](cgraphite.intervals\nInterval\no}(U\x05startGA\xd3\xb3]\x8f\x99)\x02U\x04sizeGA\xa2\xcc\x02\xd2K\x8f\x18U\x03endGA\xd6\x0c\xdd\xe9\xe2\x9a\xe5U\x05tupleGA\xd3\xb3]\x8f\x99)\x02GA\xd6\x0c\xdd\xe9\xe2\x9a\xe5\x86ubaU\x04sizeGA\xa2\xcc\x02\xd2K\x8f\x18ub")
50
+
51
+	binary.BigEndian.PutUint64(b[89:97], uint64(math.Float64bits(float64(i.Start))))
52
+	binary.BigEndian.PutUint64(b[104:112], uint64(math.Float64bits(float64(i.End-i.Start))))
53
+	binary.BigEndian.PutUint64(b[118:126], uint64(math.Float64bits(float64(i.End))))
54
+	binary.BigEndian.PutUint64(b[134:142], uint64(math.Float64bits(float64(i.Start))))
55
+	binary.BigEndian.PutUint64(b[143:151], uint64(math.Float64bits(float64(i.End))))
56
+	binary.BigEndian.PutUint64(b[162:170], uint64(math.Float64bits(float64(i.End-i.Start))))
57
+
58
+	return b, nil
59
+}

+ 11
- 1
main.go View File

@@ -26,7 +26,8 @@ import (
26 26
 	"github.com/go-graphite/carbonzipper/pathcache"
27 27
 	"github.com/go-graphite/carbonzipper/util"
28 28
 	"github.com/go-graphite/carbonzipper/zipper"
29
-	pickle "github.com/kisielk/og-rek"
29
+	"github.com/go-graphite/carbonzipper/intervalset"
30
+	pickle "github.com/lomik/og-rek"
30 31
 	"github.com/peterbourgon/g2g"
31 32
 
32 33
 	"github.com/lomik/zapwriter"
@@ -209,10 +210,19 @@ func encodeFindResponse(format, query string, w http.ResponseWriter, metrics []*
209 210
 
210 211
 		var result []map[string]interface{}
211 212
 
213
+		now := int32(time.Now().Unix() + 60)
212 214
 		for _, metric := range metrics {
215
+			// Tell graphite-web that we have everything
216
+			interval := &intervalset.IntervalSet{Start: 0, End: now}
213 217
 			mm := map[string]interface{}{
218
+				// graphite-web 0.9.x
214 219
 				"metric_path": metric.Path,
215 220
 				"isLeaf":      metric.IsLeaf,
221
+
222
+				// graphite-web 1.0
223
+				"is_leaf":     metric.IsLeaf,
224
+				"path":        metric.Path,
225
+				"intervals":   interval,
216 226
 			}
217 227
 			result = append(result, mm)
218 228
 		}