github.com/cilium/cilium@v1.16.2/pkg/hubble/filters/verdict.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Hubble
     3  
     4  package filters
     5  
     6  import (
     7  	"context"
     8  
     9  	flowpb "github.com/cilium/cilium/api/v1/flow"
    10  	v1 "github.com/cilium/cilium/pkg/hubble/api/v1"
    11  )
    12  
    13  func filterByVerdicts(vs []flowpb.Verdict) FilterFunc {
    14  	return func(ev *v1.Event) bool {
    15  		flow := ev.GetFlow()
    16  		if flow == nil {
    17  			return false
    18  		}
    19  		for _, verdict := range vs {
    20  			if verdict == flow.GetVerdict() {
    21  				return true
    22  			}
    23  		}
    24  
    25  		return false
    26  	}
    27  }
    28  
    29  // VerdictFilter implements filtering based on forwarding verdict
    30  type VerdictFilter struct{}
    31  
    32  // OnBuildFilter builds a forwarding verdict filter
    33  func (v *VerdictFilter) OnBuildFilter(ctx context.Context, ff *flowpb.FlowFilter) ([]FilterFunc, error) {
    34  	var fs []FilterFunc
    35  
    36  	if ff.GetVerdict() != nil {
    37  		fs = append(fs, filterByVerdicts(ff.GetVerdict()))
    38  	}
    39  
    40  	return fs, nil
    41  }