app/vmstorage/transport: simplify setupTfss in order to prevent the possibility of nil tfs

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/534
This commit is contained in:
Aliaksandr Valialkin 2020-06-05 13:17:23 +03:00
parent e4cef1b678
commit 01719f4949

View File

@ -874,19 +874,14 @@ var (
func (ctx *vmselectRequestCtx) setupTfss() error {
tfss := ctx.tfss[:0]
for _, tagFilters := range ctx.sq.TagFilterss {
if len(tfss) < cap(tfss) {
tfss = tfss[:len(tfss)+1]
} else {
tfss = append(tfss, &storage.TagFilters{})
}
tfs := tfss[len(tfss)-1]
tfs.Reset(ctx.sq.AccountID, ctx.sq.ProjectID)
tfs := storage.NewTagFilters(ctx.sq.AccountID, ctx.sq.ProjectID)
for i := range tagFilters {
tf := &tagFilters[i]
if err := tfs.Add(tf.Key, tf.Value, tf.IsNegative, tf.IsRegexp); err != nil {
return fmt.Errorf("cannot parse tag filter %s: %s", tf, err)
}
}
tfss = append(tfss, tfs)
tfss = append(tfss, tfs.Finalize()...)
}
ctx.tfss = tfss