Skip to content

Commit

Permalink
Merge pull request #9801 from influxdata/bj-validate-write
Browse files Browse the repository at this point in the history
Add option for unicode validation.
  • Loading branch information
benbjohnson committed Aug 20, 2018
2 parents 5536493 + 58aed93 commit 2d266ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions etc/config.sample.toml
Expand Up @@ -67,6 +67,10 @@
# log any sensitive data contained within a query.
# query-log-enabled = true

# Validates incoming writes to ensure keys only have valid unicode characters.
# This setting will incur a small overhead because every key must be checked.
# validate-keys = false

# Settings for the TSM engine

# CacheMaxMemorySize is the maximum size a shard's cache can
Expand Down
3 changes: 3 additions & 0 deletions tsdb/config.go
Expand Up @@ -82,6 +82,9 @@ type Config struct {
// disks or when WAL write contention is seen. A value of 0 fsyncs every write to the WAL.
WALFsyncDelay toml.Duration `toml:"wal-fsync-delay"`

// Enables unicode validation on series keys on write.
ValidateKeys bool `toml:"validate-keys"`

// Query logging
QueryLogEnabled bool `toml:"query-log-enabled"`

Expand Down
12 changes: 12 additions & 0 deletions tsdb/shard.go
Expand Up @@ -538,6 +538,9 @@ func (s *Shard) validateSeriesAndFields(points []models.Point) ([]models.Point,
names := make([][]byte, len(points))
tagsSlice := make([]models.Tags, len(points))

// Check if keys should be unicode validated.
validateKeys := s.options.Config.ValidateKeys

var j int
for i, p := range points {
tags := p.Tags()
Expand All @@ -553,6 +556,15 @@ func (s *Shard) validateSeriesAndFields(points []models.Point) ([]models.Point,
continue
}

// Drop any series with invalid unicode characters in the key.
if validateKeys && !models.ValidKeyTokens(string(p.Name()), tags) {
dropped++
if reason == "" {
reason = fmt.Sprintf("key contains invalid unicode: \"%s\"", string(p.Key()))
}
continue
}

keys[j] = p.Key()
names[j] = p.Name()
tagsSlice[j] = tags
Expand Down

0 comments on commit 2d266ca

Please sign in to comment.