github.com/cilium/cilium@v1.16.2/pkg/hubble/filters/uuid.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 filterByUUID(uuids []string) FilterFunc {
    14  	return func(ev *v1.Event) bool {
    15  		flow := ev.GetFlow()
    16  		if flow == nil {
    17  			return false
    18  		}
    19  		eid := flow.GetUuid()
    20  		for _, id := range uuids {
    21  			if id == eid {
    22  				return true
    23  			}
    24  		}
    25  		return false
    26  	}
    27  }
    28  
    29  // UUIDFilter implements filtering based on flow identifiers.
    30  type UUIDFilter struct{}
    31  
    32  // OnBuildFilter builds a a flow identifier filter.
    33  func (e *UUIDFilter) OnBuildFilter(ctx context.Context, ff *flowpb.FlowFilter) ([]FilterFunc, error) {
    34  	var fs []FilterFunc
    35  
    36  	if ids := ff.GetUuid(); len(ids) > 0 {
    37  		fs = append(fs, filterByUUID(ids))
    38  	}
    39  
    40  	return fs, nil
    41  }