Skip to content

Commit

Permalink
fix(chstorage): validate table name before creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Nov 21, 2023
1 parent 829f20b commit 0805d5d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions internal/chstorage/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ type Tables struct {
Labels string
}

// Validate checks table names
func (t Tables) Validate() error {
validateTableName := func(name string) error {
if name == "" {
return errors.New("table name must be non-empty")
}
return nil
}

for _, table := range []struct {
name string
fieldName string
}{
{t.Spans, "Spans"},
{t.Tags, "Tags"},

{t.Points, "Points"},
{t.Labels, "Labels"},
} {
if err := validateTableName(table.name); err != nil {
return errors.Wrapf(err, "table %s", table.fieldName)
}
}
return nil
}

var defaultTables = Tables{
Spans: "traces_spans",
Tags: "traces_tags",
Expand All @@ -31,6 +57,10 @@ type chClient interface {

// Create creates tables.
func (t Tables) Create(ctx context.Context, c chClient) error {
if err := t.Validate(); err != nil {
return errors.Wrap(err, "validate")
}

type schema struct {
name string
query string
Expand Down

0 comments on commit 0805d5d

Please sign in to comment.