Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename flow node fields #623

Merged
merged 1 commit into from
May 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions pkg/object/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ type (

// FlowNode describes one node of the pipeline flow.
FlowNode struct {
Filter string `yaml:"filter" jsonschema:"required,format=urlname"`
DefaultRequestID string `yaml:"defaultRequestID" jsonschema:"defaultRequestID,omitempty"`
TargetRequestID string `yaml:"targetRequestID" jsonschema:"targetRequestID,omitempty"`
TargetResponseID string `yaml:"targetResponseID" jsonschema:"targetResponseID,omitempty"`
JumpIf map[string]string `yaml:"jumpIf" jsonschema:"omitempty"`
filter filters.Filter
Filter string `yaml:"filter" jsonschema:"required,format=urlname"`
// Note, the JSON tag of `DefaultRequest` is 'useRequest`, which is
// different from its name, because, from the aspect of code,
// `DefaultRequest` is to set the default request for the filter, but
// from the view of users, `useRequest` is much easier to understand.
DefaultRequest string `yaml:"useRequest" jsonschema:"useRequest,omitempty"`
suchen-sci marked this conversation as resolved.
Show resolved Hide resolved
TargetRequest string `yaml:"targetRequest" jsonschema:"targetRequest,omitempty"`
TargetResponse string `yaml:"targetResponse" jsonschema:"targetResponse,omitempty"`
JumpIf map[string]string `yaml:"jumpIf" jsonschema:"omitempty"`
filter filters.Filter
}

// FilterStat records the statistics of a filter.
Expand Down Expand Up @@ -127,12 +131,12 @@ func (s *Spec) ValidateRequest() {

for i := 0; i < len(s.Flow); i++ {
node := &s.Flow[i]
if node.DefaultRequestID != "" && !validIDs[node.DefaultRequestID] {
panic(fmt.Errorf(errFmt, node.Filter, node.DefaultRequestID))
if node.DefaultRequest != "" && !validIDs[node.DefaultRequest] {
panic(fmt.Errorf(errFmt, node.Filter, node.DefaultRequest))
}

if node.TargetRequestID != "" {
validIDs[node.TargetRequestID] = true
if node.TargetRequest != "" {
validIDs[node.TargetRequest] = true
}
}
}
Expand Down Expand Up @@ -327,8 +331,8 @@ func (p *Pipeline) Handle(ctx *context.Context) string {
}

start := fasttime.Now()
ctx.UseRequest(node.DefaultRequestID, node.TargetRequestID)
ctx.UseResponse(node.TargetResponseID)
ctx.UseRequest(node.DefaultRequest, node.TargetRequest)
ctx.UseResponse(node.TargetResponse)

result = node.filter.Handle(ctx)
stats = append(stats, FilterStat{
Expand Down