Skip to content

Commit f4f5c8e

Browse files
committed
adjust auto rollup for CH 25.8 (int64 no longer is a string in json)
1 parent 80e2a49 commit f4f5c8e

File tree

2 files changed

+33
-44
lines changed

2 files changed

+33
-44
lines changed

helper/rollup/remote.go

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"crypto/tls"
66
"encoding/json"
7-
"strconv"
87
"strings"
98
"time"
109

@@ -18,8 +17,8 @@ type rollupRulesResponseRecord struct {
1817
RuleType RuleType `json:"rule_type"`
1918
Regexp string `json:"regexp"`
2019
Function string `json:"function"`
21-
Age string `json:"age"`
22-
Precision string `json:"precision"`
20+
Age uint64 `json:"age"`
21+
Precision uint64 `json:"precision"`
2322
IsDefault int `json:"is_default"`
2423
}
2524
type rollupRulesResponse struct {
@@ -38,17 +37,7 @@ func parseJson(body []byte) (*Rules, error) {
3837
}
3938

4039
makeRetention := func(d *rollupRulesResponseRecord) (Retention, error) {
41-
age, err := strconv.ParseInt(d.Age, 10, 32)
42-
if err != nil {
43-
return Retention{}, err
44-
}
45-
46-
prec, err := strconv.ParseInt(d.Precision, 10, 32)
47-
if err != nil {
48-
return Retention{}, err
49-
}
50-
51-
return Retention{Age: uint32(age), Precision: uint32(prec)}, nil
40+
return Retention{Age: uint32(d.Age), Precision: uint32(d.Precision)}, nil
5241
}
5342

5443
last := func() *Pattern {
@@ -67,7 +56,7 @@ func parseJson(body []byte) (*Rules, error) {
6756
if d.Function != "" {
6857
defaultFunction = d.Function
6958
}
70-
if d.Age != "" && d.Precision != "" && d.Precision != "0" {
59+
if d.Precision != 0 {
7160
rt, err := makeRetention(&d)
7261
if err != nil {
7362
return nil, err
@@ -83,7 +72,7 @@ func parseJson(body []byte) (*Rules, error) {
8372
Function: d.Function,
8473
})
8574
}
86-
if d.Age != "" && d.Precision != "" && d.Precision != "0" {
75+
if d.Precision != 0 {
8776
rt, err := makeRetention(&d)
8877
if err != nil {
8978
return nil, err

helper/rollup/remote_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,50 +49,50 @@ func TestParseJson(t *testing.T) {
4949
{
5050
"regexp": "^hourly",
5151
"function": "",
52-
"age": "0",
53-
"precision": "3600",
52+
"age": 0,
53+
"precision": 3600,
5454
"is_default": 0
5555
},
5656
{
5757
"regexp": "^hourly",
5858
"function": "",
59-
"age": "3600",
60-
"precision": "13600",
59+
"age": 3600,
60+
"precision": 13600,
6161
"is_default": 0
6262
},
6363
{
6464
"regexp": "^live",
6565
"function": "",
66-
"age": "0",
67-
"precision": "1",
66+
"age": 0,
67+
"precision": 1,
6868
"is_default": 0
6969
},
7070
{
7171
"regexp": "total$",
7272
"function": "sum",
73-
"age": "0",
74-
"precision": "0",
73+
"age": 0,
74+
"precision": 0,
7575
"is_default": 0
7676
},
7777
{
7878
"regexp": "min$",
7979
"function": "min",
80-
"age": "0",
81-
"precision": "0",
80+
"age": 0,
81+
"precision": 0,
8282
"is_default": 0
8383
},
8484
{
8585
"regexp": "max$",
8686
"function": "max",
87-
"age": "0",
88-
"precision": "0",
87+
"age": 0,
88+
"precision": 0,
8989
"is_default": 0
9090
},
9191
{
9292
"regexp": "",
9393
"function": "max",
94-
"age": "0",
95-
"precision": "60",
94+
"age": 0,
95+
"precision": 60,
9696
"is_default": 1
9797
}
9898
],
@@ -162,48 +162,48 @@ func TestParseJsonTyped(t *testing.T) {
162162
"rule_type": "all",
163163
"regexp": "^hourly",
164164
"function": "",
165-
"age": "0",
166-
"precision": "3600",
165+
"age": 0,
166+
"precision": 3600,
167167
"is_default": 0
168168
},
169169
{
170170
"rule_type": "all",
171171
"regexp": "^hourly",
172172
"function": "",
173-
"age": "3600",
174-
"precision": "13600",
173+
"age": 3600,
174+
"precision": 13600,
175175
"is_default": 0
176176
},
177177
{
178178
"rule_type": "all",
179179
"regexp": "^live",
180180
"function": "",
181-
"age": "0",
182-
"precision": "1",
181+
"age": 0,
182+
"precision": 1,
183183
"is_default": 0
184184
},
185185
{
186186
"rule_type": "plain",
187187
"regexp": "total$",
188188
"function": "sum",
189-
"age": "0",
190-
"precision": "0",
189+
"age": 0,
190+
"precision": 0,
191191
"is_default": 0
192192
},
193193
{
194194
"rule_type": "plain",
195195
"regexp": "min$",
196196
"function": "min",
197-
"age": "0",
198-
"precision": "0",
197+
"age": 0,
198+
"precision": 0,
199199
"is_default": 0
200200
},
201201
{
202202
"rule_type": "plain",
203203
"regexp": "max$",
204204
"function": "max",
205-
"age": "0",
206-
"precision": "0",
205+
"age": 0,
206+
"precision": 0,
207207
"is_default": 0
208208
},
209209
{
@@ -220,8 +220,8 @@ func TestParseJsonTyped(t *testing.T) {
220220
"rule_type": "all",
221221
"regexp": "",
222222
"function": "max",
223-
"age": "0",
224-
"precision": "60",
223+
"age": 0,
224+
"precision": 60,
225225
"is_default": 1
226226
}
227227
],

0 commit comments

Comments
 (0)