github.com/cilium/cilium@v1.16.2/pkg/hubble/exporter/api.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package exporter 5 6 import ( 7 "reflect" 8 "sort" 9 10 flowpb "github.com/cilium/cilium/api/v1/flow" 11 "github.com/cilium/cilium/pkg/hubble/observer/observeroption" 12 "github.com/cilium/cilium/pkg/time" 13 ) 14 15 // FlowLogExporter exports hubble events to configured target file. 16 type FlowLogExporter interface { 17 observeroption.OnDecodedEvent 18 // Stop stops this exporter instance from further events processing. 19 Stop() error 20 } 21 22 // FlowFilters is a slice of filters to include or exclude flows. 23 type FlowFilters []*flowpb.FlowFilter 24 25 // FieldMask is a slice of fields that are included in output. 26 type FieldMask []string 27 28 // FlowLogConfig represents configuration of single dynamic exporter. 29 type FlowLogConfig struct { 30 Name string `json:"name,omitempty" yaml:"name,omitempty"` 31 FilePath string `json:"filePath,omitempty" yaml:"filePath,omitempty"` 32 FieldMask FieldMask `json:"fieldMask,omitempty" yaml:"fieldMask,omitempty"` 33 IncludeFilters FlowFilters `json:"includeFilters,omitempty" yaml:"includeFilters,omitempty"` 34 ExcludeFilters FlowFilters `json:"excludeFilters,omitempty" yaml:"excludeFilters,omitempty"` 35 End *time.Time `json:"end,omitempty" yaml:"end,omitempty"` 36 } 37 38 func (f *FlowLogConfig) equals(other *FlowLogConfig) bool { 39 if f == nil && other == nil { 40 return true 41 } 42 if f == nil || other == nil { 43 return false 44 } 45 46 if f.FilePath != other.FilePath { 47 return false 48 } 49 50 if !f.FieldMask.equals(other.FieldMask) { 51 return false 52 } 53 54 if !f.IncludeFilters.equals(other.IncludeFilters) { 55 return false 56 } 57 58 if !f.ExcludeFilters.equals(other.ExcludeFilters) { 59 return false 60 } 61 62 if f.End == nil && other.End != nil || 63 f.End != nil && other.End == nil || 64 f.End != nil && other.End != nil && !f.End.Equal(*other.End) { 65 return false 66 } 67 68 return true 69 } 70 71 func (f FlowFilters) equals(other FlowFilters) bool { 72 aFiltersSet, bFiltersSet := make(map[string]bool), make(map[string]bool) 73 74 for _, filter := range f { 75 aFiltersSet[filter.String()] = true 76 } 77 for _, filter := range other { 78 bFiltersSet[filter.String()] = true 79 } 80 return reflect.DeepEqual(aFiltersSet, bFiltersSet) 81 } 82 83 func (f FieldMask) equals(other FieldMask) bool { 84 sort.Strings(f) 85 sort.Strings(other) 86 return reflect.DeepEqual(f, other) 87 } 88 89 // DynamicExportersConfig represents structure of dynamic hubble exporters 90 // configuration file. 91 type DynamicExportersConfig struct { 92 FlowLogs []*FlowLogConfig `json:"flowLogs,omitempty" yaml:"flowLogs,omitempty"` 93 }