mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
![Aliaksandr Valialkin](/assets/img/avatar_default.png)
The purpose of extra filters ( https://docs.victoriametrics.com/victorialogs/querying/#extra-filters ) is to limit the subset of logs, which can be queried. For example, it is expected that all the queries with `extra_filters={tenant=123}` can access only logs, which contain `123` value for the `tenant` field. Previously this wasn't the case, since the provided extra filters weren't applied to subqueries. For example, the following query could be used to select all the logs outside `tenant=123`, for any `extra_filters` arg: * | union({tenant!=123}) This commit fixes this by propagating extra filters to all the subqueries. While at it, this commit also properly propagates [start, end] time range filter from HTTP querying APIs into all the subqueries, since this is what most users expect. This behaviour can be overriden on per-subquery basis with the `options(ignore_global_time_filter=true)` option - see https://docs.victoriametrics.com/victorialogs/logsql/#query-options Also properly apply apply optimizations across all the subqueries. Previously the optimizations at Query.optimize() function were applied only to the top-level query.
100 lines
2.1 KiB
Go
100 lines
2.1 KiB
Go
package logstorage
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/logger"
|
|
)
|
|
|
|
// pipeDelete implements '| delete ...' pipe.
|
|
//
|
|
// See https://docs.victoriametrics.com/victorialogs/logsql/#delete-pipe
|
|
type pipeDelete struct {
|
|
// fields contains a list of fields to delete
|
|
fields []string
|
|
}
|
|
|
|
func (pd *pipeDelete) String() string {
|
|
if len(pd.fields) == 0 {
|
|
logger.Panicf("BUG: pipeDelete must contain at least a single field")
|
|
}
|
|
|
|
return "delete " + fieldNamesString(pd.fields)
|
|
}
|
|
|
|
func (pd *pipeDelete) canLiveTail() bool {
|
|
return true
|
|
}
|
|
|
|
func (pd *pipeDelete) updateNeededFields(neededFields, unneededFields fieldsSet) {
|
|
if neededFields.contains("*") {
|
|
unneededFields.addFields(pd.fields)
|
|
} else {
|
|
neededFields.removeFields(pd.fields)
|
|
}
|
|
}
|
|
|
|
func (pd *pipeDelete) hasFilterInWithQuery() bool {
|
|
return false
|
|
}
|
|
|
|
func (pd *pipeDelete) initFilterInValues(_ *inValuesCache, _ getFieldValuesFunc) (pipe, error) {
|
|
return pd, nil
|
|
}
|
|
|
|
func (pd *pipeDelete) visitSubqueries(_ func(q *Query)) {
|
|
// nothing to do
|
|
}
|
|
|
|
func (pd *pipeDelete) newPipeProcessor(_ int, _ <-chan struct{}, _ func(), ppNext pipeProcessor) pipeProcessor {
|
|
return &pipeDeleteProcessor{
|
|
pd: pd,
|
|
ppNext: ppNext,
|
|
}
|
|
}
|
|
|
|
type pipeDeleteProcessor struct {
|
|
pd *pipeDelete
|
|
ppNext pipeProcessor
|
|
}
|
|
|
|
func (pdp *pipeDeleteProcessor) writeBlock(workerID uint, br *blockResult) {
|
|
if br.rowsLen == 0 {
|
|
return
|
|
}
|
|
|
|
br.deleteColumns(pdp.pd.fields)
|
|
pdp.ppNext.writeBlock(workerID, br)
|
|
}
|
|
|
|
func (pdp *pipeDeleteProcessor) flush() error {
|
|
return nil
|
|
}
|
|
|
|
func parsePipeDelete(lex *lexer) (pipe, error) {
|
|
if !lex.isKeyword("delete", "del", "rm", "drop") {
|
|
return nil, fmt.Errorf("expecting 'delete', 'del', 'rm' or 'drop'; got %q", lex.token)
|
|
}
|
|
|
|
var fields []string
|
|
for {
|
|
lex.nextToken()
|
|
field, err := parseFieldName(lex)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot parse field name: %w", err)
|
|
}
|
|
|
|
fields = append(fields, field)
|
|
|
|
switch {
|
|
case lex.isKeyword("|", ")", ""):
|
|
pd := &pipeDelete{
|
|
fields: fields,
|
|
}
|
|
return pd, nil
|
|
case lex.isKeyword(","):
|
|
default:
|
|
return nil, fmt.Errorf("unexpected token: %q; expecting ',', '|' or ')'", lex.token)
|
|
}
|
|
}
|
|
}
|