github.com/cilium/cilium@v1.16.2/pkg/hubble/exporter/exporteroption/option.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package exporteroption 5 6 import ( 7 "context" 8 9 "github.com/sirupsen/logrus" 10 "google.golang.org/protobuf/types/known/fieldmaskpb" 11 12 flowpb "github.com/cilium/cilium/api/v1/flow" 13 "github.com/cilium/cilium/pkg/hubble/filters" 14 "github.com/cilium/cilium/pkg/hubble/parser/fieldmask" 15 ) 16 17 // Options stores all the configurations values for Hubble exporter. 18 type Options struct { 19 Path string 20 MaxSizeMB int 21 MaxBackups int 22 Compress bool 23 24 AllowList, DenyList filters.FilterFuncs 25 FieldMask fieldmask.FieldMask 26 } 27 28 // Option customizes the configuration of the hubble server. 29 type Option func(o *Options) error 30 31 // WithPath sets the Hubble export filepath. It's set to an empty string by default, 32 // which disables Hubble export. 33 func WithPath(path string) Option { 34 return func(o *Options) error { 35 o.Path = path 36 return nil 37 } 38 } 39 40 // WithMaxSizeMB sets the size in MB at which to rotate the Hubble export file. 41 func WithMaxSizeMB(size int) Option { 42 return func(o *Options) error { 43 o.MaxSizeMB = size 44 return nil 45 } 46 } 47 48 // WithMaxSizeMB sets the number of rotated Hubble export files to keep. 49 func WithMaxBackups(backups int) Option { 50 return func(o *Options) error { 51 o.MaxBackups = backups 52 return nil 53 } 54 } 55 56 // WithCompress specifies whether rotated files are compressed. 57 func WithCompress() Option { 58 return func(o *Options) error { 59 o.Compress = true 60 return nil 61 } 62 } 63 64 // WithAllowListFilter sets allowlist filter for the exporter. 65 func WithAllowList(log logrus.FieldLogger, f []*flowpb.FlowFilter) Option { 66 return func(o *Options) error { 67 filterList, err := filters.BuildFilterList(context.Background(), f, filters.DefaultFilters(log)) 68 if err != nil { 69 return err 70 } 71 o.AllowList = filterList 72 return nil 73 } 74 } 75 76 // WithDenyListFilter sets denylist filter for the exporter. 77 func WithDenyList(log logrus.FieldLogger, f []*flowpb.FlowFilter) Option { 78 return func(o *Options) error { 79 filterList, err := filters.BuildFilterList(context.Background(), f, filters.DefaultFilters(log)) 80 if err != nil { 81 return err 82 } 83 o.DenyList = filterList 84 return nil 85 } 86 } 87 88 // WithFieldMask sets fieldmask for the exporter. 89 func WithFieldMask(paths []string) Option { 90 return func(o *Options) error { 91 fm, err := fieldmaskpb.New(&flowpb.Flow{}, paths...) 92 if err != nil { 93 return err 94 } 95 fieldMask, err := fieldmask.New(fm) 96 if err != nil { 97 return err 98 } 99 o.FieldMask = fieldMask 100 return nil 101 } 102 }