Skip to content

Commit 646a7e9

Browse files
committed
make validationRegex public
1 parent c18bdb0 commit 646a7e9

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

helper/tags/graphite.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ type TemplateDesc struct {
190190
}
191191

192192
type TagConfig struct {
193-
Enabled bool `toml:"enabled"`
194-
Separator string `toml:"separator"`
195-
validationRegex string `toml:"validation-regex"`
196-
ValidationRegex *regexp.Regexp `toml:"-"`
197-
Tags []string `toml:"tags"`
198-
TagMap map[string]string `toml:"-"`
199-
Templates []string `toml:"templates"`
200-
TemplateDescs []TemplateDesc `toml:"-"`
193+
Enabled bool `toml:"enabled"`
194+
Separator string `toml:"separator"`
195+
ValidationRegex string `toml:"validation-regex"`
196+
ValidationRegexCompiled *regexp.Regexp `toml:"-"`
197+
Tags []string `toml:"tags"`
198+
TagMap map[string]string `toml:"-"`
199+
Templates []string `toml:"templates"`
200+
TemplateDescs []TemplateDesc `toml:"-"`
201201
}
202202

203203
func DisabledTagConfig() TagConfig {
@@ -227,7 +227,7 @@ func (cfg *TagConfig) Configure() error {
227227
makeTagMap(cfg.TagMap, cfg.Tags)
228228

229229
var err error
230-
cfg.ValidationRegex, err = regexp.Compile(cfg.validationRegex)
230+
cfg.ValidationRegexCompiled, err = regexp.Compile(cfg.ValidationRegex)
231231
if err != nil {
232232
return err
233233
}

receiver/plain.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (base *Base) PlainParseLine(p []byte, now uint32, buf *tags.GraphiteBuf) ([
7575
value float64
7676
)
7777

78-
if base.Tags.ValidationRegex != nil && base.Tags.ValidationRegex.Match(p[:i1]) {
78+
if base.Tags.ValidationRegexCompiled != nil && base.Tags.ValidationRegexCompiled.Match(p[:i1]) {
7979
return nil, 0, 0, errors.New("message contains invalid characters: '" + unsafeString(p) + "'")
8080
}
8181

receiver/plain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func TestPlainParseLine(t *testing.T) {
309309
{"app:service:metric;env=prod:primary 42.15 1422642189\n", "app:service:metric?env=prod%3Aprimary", 42.15, 1422642189},
310310
}
311311

312-
baseWithValidation := &Base{Tags: tags.TagConfig{ValidationRegex: regexp.MustCompile(`[^a-zA-Z0-9.;\-_:=]{1}`)}}
312+
baseWithValidation := &Base{Tags: tags.TagConfig{ValidationRegexCompiled: regexp.MustCompile(`[^a-zA-Z0-9.;\-_:=]{1}`)}}
313313
for _, p := range tableWithValidation {
314314
name, value, timestamp, err := baseWithValidation.PlainParseLine([]byte(p.b), now, &tagBuf)
315315
if p.name == "" {

0 commit comments

Comments
 (0)