Nityananda Gohain 1a3e46cecd
feat: integrate pipelines API (#2457)
* chore: integrate pipelines API

* fix: limit support integrated in pipelines

* fix: interface to string

* fix: json parser and allow deleting all pipelines

* fix: output modified if operators are disabled

* fix: validation updated for operators

* fix: expression check added

* fix: regex expression check added

* fix: remove operator validation updated

* fix: tests updated for pipeline builder

* fix: fix error messages in http handler

* fix: dont return payload if there is an error

* fix: extracting userId from context moved to auth package

* fix: api errors moved to http handler

* fix: get version logic updated

* fix: deployment result message updated

* fix: pipeline builder edgecase fixed and tests updated

* fix: get failing postablePipeline tests to pass

---------

Co-authored-by: Vishal Sharma <makeavish786@gmail.com>
Co-authored-by: Raj <rkssisodiya@gmail.com>
2023-07-31 21:34:42 +05:30

78 lines
1.6 KiB
Go

package logparsingpipeline
import (
"encoding/json"
"fmt"
"go.signoz.io/signoz/pkg/query-service/constants"
"go.signoz.io/signoz/pkg/query-service/model"
)
const (
NOOP = "noop"
)
func PreparePipelineProcessor(pipelines []model.Pipeline) (map[string]interface{}, []string, error) {
processors := map[string]interface{}{}
names := []string{}
for _, v := range pipelines {
if !v.Enabled {
continue
}
operators := getOperators(v.Config)
if len(operators) == 0 {
continue
}
router := []model.PipelineOperator{
{
ID: "router_signoz",
Type: "router",
Routes: &[]model.Route{
{
Output: v.Config[0].ID,
Expr: v.Filter,
},
},
Default: NOOP,
},
}
v.Config = append(router, operators...)
// noop operator is needed as the default operator so that logs are not dropped
noop := model.PipelineOperator{
ID: NOOP,
Type: NOOP,
}
v.Config = append(v.Config, noop)
processor := model.Processor{
Operators: v.Config,
}
name := constants.LogsPPLPfx + v.Alias
processors[name] = processor
names = append(names, name)
}
return processors, names, nil
}
func getOperators(ops []model.PipelineOperator) []model.PipelineOperator {
filteredOp := []model.PipelineOperator{}
for i, operator := range ops {
if operator.Enabled {
if i > 0 {
filteredOp[len(filteredOp)-1].Output = operator.ID
}
filteredOp = append(filteredOp, operator)
} else if i == len(ops)-1 && len(filteredOp) != 0 {
filteredOp[len(filteredOp)-1].Output = ""
}
}
for _, v := range filteredOp {
x, _ := json.Marshal(v)
fmt.Println(string(x))
}
return filteredOp
}