@@ -39,77 +39,77 @@ func (d *Duration) Value() time.Duration {
3939}
4040
4141type Common struct {
42- Listen string `toml:"listen"`
42+ Listen string `toml:"listen" json:"listen" `
4343 // MetricPrefix string `toml:"metric-prefix"`
4444 // MetricInterval *Duration `toml:"metric-interval"`
4545 // MetricEndpoint string `toml:"metric-endpoint"`
46- MaxCPU int `toml:"max-cpu"`
47- MaxMetricsInFindAnswer int `toml:"max-metrics-in-find-answer"` //zero means infinite
48- TargetBlacklist []string `toml:"target-blacklist"`
49- Blacklist []* regexp.Regexp `toml:"-"` // compiled TargetBlacklist
46+ MaxCPU int `toml:"max-cpu" json:"max-cpu" `
47+ MaxMetricsInFindAnswer int `toml:"max-metrics-in-find-answer" json:"max-metrics-in-find-answer" ` //zero means infinite
48+ TargetBlacklist []string `toml:"target-blacklist" json:"target-blacklist" `
49+ Blacklist []* regexp.Regexp `toml:"-" json:"-" ` // compiled TargetBlacklist
5050}
5151
5252type ClickHouse struct {
53- Url string `toml:"url"`
54- DataTable string `toml:"data-table"`
55- DataTimeout * Duration `toml:"data-timeout"`
56- TreeTable string `toml:"tree-table"`
57- DateTreeTable string `toml:"date-tree-table"`
58- DateTreeTableVersion int `toml:"date-tree-table-version"`
59- IndexTable string `toml:"index-table"`
60- IndexUseDaily bool `toml:"index-use-daily"`
61- IndexTimeout * Duration `toml:"index-timeout"`
62- TaggedTable string `toml:"tagged-table"`
63- TaggedAutocompleDays int `toml:"tagged-autocomplete-days"`
64- ReverseTreeTable string `toml:"reverse-tree-table"`
65- TreeTimeout * Duration `toml:"tree-timeout"`
66- TagTable string `toml:"tag-table"`
67- RollupConf string `toml:"rollup-conf"`
68- ExtraPrefix string `toml:"extra-prefix"`
69- ConnectTimeout * Duration `toml:"connect-timeout"`
53+ Url string `toml:"url" json:"url"`
54+ DataTable string `toml:"data-table" json:"data-table"`
55+ DataTimeout * Duration `toml:"data-timeout" json:"data-timeout"`
56+ TreeTable string `toml:"tree-table" json:"tree-table"`
57+ DateTreeTable string `toml:"date-tree-table" json:"date-tree-table"`
58+ DateTreeTableVersion int `toml:"date-tree-table-version" json:"date-tree-table-version"`
59+ IndexTable string `toml:"index-table" json:"index-table"`
60+ IndexUseDaily bool `toml:"index-use-daily" json:"index-use-daily"`
61+ IndexTimeout * Duration `toml:"index-timeout" json:"index-timeout"`
62+ TaggedTable string `toml:"tagged-table" json:"tagged-table"`
63+ TaggedAutocompleDays int `toml:"tagged-autocomplete-days" json:"tagged-autocomplete-days"`
64+ ReverseTreeTable string `toml:"reverse-tree-table" json:"reverse-tree-table"`
65+ TreeTimeout * Duration `toml:"tree-timeout" json:"tree-timeout"`
66+ TagTable string `toml:"tag-table" json:"tag-table"`
67+ RollupConf string `toml:"rollup-conf" json:"-"`
68+ ExtraPrefix string `toml:"extra-prefix" json:"extra-prefix"`
69+ ConnectTimeout * Duration `toml:"connect-timeout" json:"connect-timeout"`
70+ Rollup * rollup.Rollup `toml:"-" json:"rollup-conf"`
7071}
7172
7273type Tags struct {
73- Rules string `toml:"rules"`
74- Date string `toml:"date"`
75- ExtraWhere string `toml:"extra-where"`
76- InputFile string `toml:"input-file"`
77- OutputFile string `toml:"output-file"`
74+ Rules string `toml:"rules" json:"rules" `
75+ Date string `toml:"date" json:"date" `
76+ ExtraWhere string `toml:"extra-where" json:"extra-where" `
77+ InputFile string `toml:"input-file" json:"input-file" `
78+ OutputFile string `toml:"output-file" json:"output-file" `
7879}
7980
8081type Carbonlink struct {
81- Server string `toml:"server"`
82- Threads int `toml:"threads-per-request"`
83- Retries int `toml:"-"`
84- ConnectTimeout * Duration `toml:"connect-timeout"`
85- QueryTimeout * Duration `toml:"query-timeout"`
86- TotalTimeout * Duration `toml:"total-timeout"`
82+ Server string `toml:"server" json:"server" `
83+ Threads int `toml:"threads-per-request" json:"threads-per-request" `
84+ Retries int `toml:"-" json:"-" `
85+ ConnectTimeout * Duration `toml:"connect-timeout" json:"connect-timeout" `
86+ QueryTimeout * Duration `toml:"query-timeout" json:"query-timeout" `
87+ TotalTimeout * Duration `toml:"total-timeout" json:"total-timeout" `
8788}
8889
8990type DataTable struct {
90- Table string `toml:"table"`
91- Reverse bool `toml:"reverse"`
92- MaxAge * Duration `toml:"max-age"`
93- MinAge * Duration `toml:"min-age"`
94- MaxInterval * Duration `toml:"max-interval"`
95- MinInterval * Duration `toml:"min-interval"`
96- TargetMatchAny string `toml:"target-match-any"`
97- TargetMatchAll string `toml:"target-match-all"`
98- TargetMatchAnyRegexp * regexp.Regexp `toml:"-"`
99- TargetMatchAllRegexp * regexp.Regexp `toml:"-"`
100- RollupConf string `toml:"rollup-conf"`
101- Rollup * rollup.Rollup `toml:"-"`
91+ Table string `toml:"table" json:"table" `
92+ Reverse bool `toml:"reverse" json:"reverse" `
93+ MaxAge * Duration `toml:"max-age" json:"max-age" `
94+ MinAge * Duration `toml:"min-age" json:"min-age" `
95+ MaxInterval * Duration `toml:"max-interval" json:"max-interval" `
96+ MinInterval * Duration `toml:"min-interval" json:"min-interval" `
97+ TargetMatchAny string `toml:"target-match-any" json:"target-match-any" `
98+ TargetMatchAll string `toml:"target-match-all" json:"target-match-all" `
99+ TargetMatchAnyRegexp * regexp.Regexp `toml:"-" json:"-" `
100+ TargetMatchAllRegexp * regexp.Regexp `toml:"-" json:"-" `
101+ RollupConf string `toml:"rollup-conf" json:"-" `
102+ Rollup * rollup.Rollup `toml:"-" json:"rollup-conf" `
102103}
103104
104105// Config ...
105106type Config struct {
106- Common Common `toml:"common"`
107- ClickHouse ClickHouse `toml:"clickhouse"`
108- DataTable []DataTable `toml:"data-table"`
109- Tags Tags `toml:"tags"`
110- Carbonlink Carbonlink `toml:"carbonlink"`
111- Logging []zapwriter.Config `toml:"logging"`
112- Rollup * rollup.Rollup `toml:"-"`
107+ Common Common `toml:"common" json:"common"`
108+ ClickHouse ClickHouse `toml:"clickhouse" json:"clickhouse"`
109+ DataTable []DataTable `toml:"data-table" json:"data-table"`
110+ Tags Tags `toml:"tags" json:"tags"`
111+ Carbonlink Carbonlink `toml:"carbonlink" json:"carbonlink"`
112+ Logging []zapwriter.Config `toml:"logging" json:"logging"`
113113}
114114
115115// NewConfig ...
@@ -225,18 +225,15 @@ func ReadConfig(filename string) (*Config, error) {
225225 return nil , err
226226 }
227227
228- rollupConfBody , err := ioutil .ReadFile (cfg .ClickHouse .RollupConf )
229- if err != nil {
230- return nil , err
228+ if cfg .ClickHouse .RollupConf == "auto" {
229+ cfg .ClickHouse .Rollup , err = rollup .Auto (cfg .ClickHouse .Url , cfg .ClickHouse .DataTable , time .Minute )
230+ } else {
231+ cfg .ClickHouse .Rollup , err = rollup .ReadFromXMLFile (cfg .ClickHouse .RollupConf )
231232 }
232-
233- r , err := rollup .ParseXML (rollupConfBody )
234233 if err != nil {
235234 return nil , err
236235 }
237236
238- cfg .Rollup = r
239-
240237 l := len (cfg .Common .TargetBlacklist )
241238 if l > 0 {
242239 cfg .Common .Blacklist = make ([]* regexp.Regexp , l )
@@ -266,17 +263,14 @@ func ReadConfig(filename string) (*Config, error) {
266263 }
267264
268265 if cfg .DataTable [i ].RollupConf != "" {
269- rollupConfBody , err := ioutil .ReadFile (cfg .DataTable [i ].RollupConf )
270- if err != nil {
271- return nil , err
266+ if cfg .DataTable [i ].RollupConf == "auto" {
267+ cfg .DataTable [i ].Rollup , err = rollup .Auto (cfg .ClickHouse .Url , cfg .DataTable [i ].Table , time .Minute )
268+ } else {
269+ cfg .DataTable [i ].Rollup , err = rollup .ReadFromXMLFile (cfg .DataTable [i ].RollupConf )
272270 }
273-
274- r , err := rollup .ParseXML (rollupConfBody )
275271 if err != nil {
276272 return nil , err
277273 }
278-
279- cfg .DataTable [i ].Rollup = r
280274 }
281275 }
282276
0 commit comments