Skip to content

Commit 9f461c1

Browse files
committed
fix empty regex
1 parent 9a0f5bd commit 9f461c1

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

carbon/app.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/url"
77
"os"
88
"path/filepath"
9-
"regexp"
109
"runtime"
1110
"strings"
1211
"sync"
@@ -193,8 +192,6 @@ func (app *App) Start() (err error) {
193192

194193
app.writeChan = make(chan *RowBinary.WriteBuffer)
195194

196-
validationRegex := regexp.MustCompile(app.Config.Common.ValidationRegex)
197-
198195
/* WRITER start */
199196
uploaders := make([]string, 0, len(conf.Upload))
200197
for t := range conf.Upload {
@@ -259,7 +256,7 @@ func (app *App) Start() (err error) {
259256
receiver.DropPast(uint32(conf.Tcp.DropPast.Value().Seconds())),
260257
receiver.DropLongerThan(conf.Tcp.DropLongerThan),
261258
receiver.ReadTimeout(uint32(conf.Tcp.ReadTimeout.Value().Seconds())),
262-
receiver.ValidationRegex(validationRegex),
259+
receiver.ValidationRegex(app.Config.Common.ValidationRegex),
263260
)
264261

265262
if err != nil {
@@ -278,7 +275,7 @@ func (app *App) Start() (err error) {
278275
receiver.DropFuture(uint32(conf.Udp.DropFuture.Value().Seconds())),
279276
receiver.DropPast(uint32(conf.Udp.DropPast.Value().Seconds())),
280277
receiver.DropLongerThan(conf.Udp.DropLongerThan),
281-
receiver.ValidationRegex(validationRegex),
278+
receiver.ValidationRegex(app.Config.Common.ValidationRegex),
282279
)
283280

284281
if err != nil {
@@ -297,7 +294,7 @@ func (app *App) Start() (err error) {
297294
receiver.DropFuture(uint32(conf.Pickle.DropFuture.Value().Seconds())),
298295
receiver.DropPast(uint32(conf.Pickle.DropPast.Value().Seconds())),
299296
receiver.DropLongerThan(conf.Pickle.DropLongerThan),
300-
receiver.ValidationRegex(validationRegex),
297+
receiver.ValidationRegex(app.Config.Common.ValidationRegex),
301298
)
302299

303300
if err != nil {
@@ -315,7 +312,7 @@ func (app *App) Start() (err error) {
315312
receiver.DropFuture(uint32(conf.Grpc.DropFuture.Value().Seconds())),
316313
receiver.DropPast(uint32(conf.Grpc.DropPast.Value().Seconds())),
317314
receiver.DropLongerThan(conf.Grpc.DropLongerThan),
318-
receiver.ValidationRegex(validationRegex),
315+
receiver.ValidationRegex(app.Config.Common.ValidationRegex),
319316
)
320317

321318
if err != nil {
@@ -333,7 +330,7 @@ func (app *App) Start() (err error) {
333330
receiver.DropFuture(uint32(conf.Prometheus.DropFuture.Value().Seconds())),
334331
receiver.DropPast(uint32(conf.Prometheus.DropPast.Value().Seconds())),
335332
receiver.DropLongerThan(conf.Prometheus.DropLongerThan),
336-
receiver.ValidationRegex(validationRegex),
333+
receiver.ValidationRegex(app.Config.Common.ValidationRegex),
337334
)
338335

339336
if err != nil {
@@ -352,7 +349,7 @@ func (app *App) Start() (err error) {
352349
receiver.DropPast(uint32(conf.TelegrafHttpJson.DropPast.Value().Seconds())),
353350
receiver.DropLongerThan(conf.TelegrafHttpJson.DropLongerThan),
354351
receiver.ConcatChar(conf.TelegrafHttpJson.Concat),
355-
receiver.ValidationRegex(validationRegex),
352+
receiver.ValidationRegex(app.Config.Common.ValidationRegex),
356353
)
357354

358355
if err != nil {

receiver/receiver.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ func ConcatChar(concat string) Option {
9292
}
9393

9494
// ConcatChar creates option for New constructor
95-
func ValidationRegex(regex *regexp.Regexp) Option {
95+
func ValidationRegex(regex string) Option {
9696
return func(r interface{}) error {
9797
if t, ok := r.(*Base); ok {
98-
t.validationRegex = regex
98+
if regex != "" {
99+
t.validationRegex = regexp.MustCompile(regex)
100+
}
99101
}
100102
return nil
101103
}

0 commit comments

Comments
 (0)