Skip to content

Commit cb8e42a

Browse files
authored
Move goflow2 2 (#632)
1 parent 80333c4 commit cb8e42a

File tree

7 files changed

+489
-395
lines changed

7 files changed

+489
-395
lines changed

config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
const (
1010
// FlowFields are fields for the Flow input
11-
FlowFields = "Type,TimeReceived,SequenceNum,SamplingRate,SamplerAddress,TimeFlowStart,TimeFlowEnd,Bytes,Packets,SrcAddr,DstAddr,Etype,Proto,SrcPort,DstPort,InIf,OutIf,SrcMac,DstMac,SrcVlan,DstVlan,VlanId,IngressVrfID,EgressVrfID,IPTos,ForwardingStatus,IPTTL,TCPFlags,IcmpType,IcmpCode,IPv6FlowLabel,FragmentId,FragmentOffset,FlowDirection,BiFlowDirection,SrcAS,DstAS,NextHop,NextHopAS,SrcNet,DstNet,HasMPLS,MPLSCount,MPLS1TTL,MPLS1Label,MPLS2TTL,MPLS2Label,MPLS3TTL,MPLS3Label,MPLSLastTTL,MPLSLastLabel,CustomInteger1,CustomInteger2,CustomInteger3,CustomInteger4,CustomInteger5,CustomBytes1,CustomBytes2,CustomBytes3,CustomBytes4,CustomBytes5,CustomIPv41,CustomIPv42,CustomIP1,CustomIP2"
11+
FlowFields = "Type,TimeReceived,SequenceNum,SamplingRate,FlowDirection,SamplerAddress,TimeFlowStart,TimeFlowEnd,Bytes,Packets,SrcAddr,DstAddr,Etype,Proto,SrcPort,DstPort,InIf,OutIf,SrcMac,DstMac,SrcVlan,DstVlan,VlanId,IPTos,ForwardingStatus,IPTTL,TCPFlags,IcmpType,IcmpCode,IPv6FlowLabel,FragmentId,FragmentOffset,SrcAS,DstAS,NextHop,NextHopAS,SrcNet,DstNet,MPLSCount"
1212
// FlowDefaultFields are the default fields for flow
1313
FlowDefaultFields = "TimeReceived,SamplingRate,Bytes,Packets,SrcAddr,DstAddr,Proto,SrcPort,DstPort,InIf,OutIf,SrcVlan,DstVlan,TCPFlags,SrcAS,DstAS,Type,SamplerAddress,FlowDirection"
1414
// KentikAPITokenEnvVar is the environment variables used to get the Kentik API Token

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ require (
3333
github.com/liamg/furious v0.0.0-20191231090757-c295c872d6c1
3434
github.com/linkedin/goavro/v2 v2.10.1
3535
github.com/montanaflynn/stats v0.7.0
36-
github.com/netsampler/goflow2 v1.1.1-0.20220818030102-fc42020d1b73
37-
github.com/oschwald/geoip2-golang v1.5.0
36+
github.com/netsampler/goflow2/v2 v2.0.0
37+
github.com/oschwald/geoip2-golang v1.8.0
3838
github.com/pkg/errors v0.9.1
3939
github.com/prometheus-community/pro-bing v0.3.0
4040
github.com/prometheus/client_golang v1.16.0
@@ -93,7 +93,7 @@ require (
9393
github.com/josharian/intern v1.0.0 // indirect
9494
github.com/klauspost/compress v1.16.7 // indirect
9595
github.com/kylelemons/godebug v1.1.0 // indirect
96-
github.com/libp2p/go-reuseport v0.1.0 // indirect
96+
github.com/libp2p/go-reuseport v0.2.0 // indirect
9797
github.com/mailru/easyjson v0.7.7 // indirect
9898
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
9999
github.com/mitchellh/mapstructure v1.5.0 // indirect
@@ -104,15 +104,15 @@ require (
104104
github.com/onsi/ginkgo v1.16.2 // indirect
105105
github.com/onsi/gomega v1.13.0 // indirect
106106
github.com/opentracing/opentracing-go v1.2.0 // indirect
107-
github.com/oschwald/maxminddb-golang v1.8.0 // indirect
107+
github.com/oschwald/maxminddb-golang v1.10.0 // indirect
108108
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 // indirect
109109
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
110110
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 // indirect
111111
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
112112
github.com/prometheus/client_model v0.4.0 // indirect
113113
github.com/prometheus/common v0.44.0 // indirect
114114
github.com/prometheus/procfs v0.11.0 // indirect
115-
github.com/sirupsen/logrus v1.8.1 // indirect
115+
github.com/sirupsen/logrus v1.9.0 // indirect
116116
github.com/tinylib/msgp v1.1.6 // indirect
117117
github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect
118118
github.com/vmihailenco/msgpack/v5 v5.3.4 // indirect

go.sum

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/dchest/siphash v1.2.2/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBl
7878
github.com/dgryski/go-bits v0.0.0-20180113010104-bd8a69a71dc2 h1:2+yip7nN/auel0PDwY7SIaTOxQPI2NwdkZkvpgtc3Pk=
7979
github.com/dgryski/go-bits v0.0.0-20180113010104-bd8a69a71dc2/go.mod h1:/9UYwwvZuEgp+mQ4960SHWCU1FS+FgdFX+m5ExFByNs=
8080
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
81-
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8/yCZMuEPMUDHG0CW/brkkEp8mzqk2+ODEitlw=
8281
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
82+
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 h1:8yY/I9ndfrgrXUbOGObLHKBR4Fl3nZXwM2c7OYTT8hM=
8383
github.com/elliotchance/orderedmap v1.4.0 h1:wZtfeEONCbx6in1CZyE6bELEt/vFayMvsxqI5SgsR+A=
8484
github.com/elliotchance/orderedmap v1.4.0/go.mod h1:wsDwEaX5jEoyhbs7x93zk2H/qv0zwuhg4inXhDkYqys=
8585
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
@@ -297,8 +297,8 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
297297
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
298298
github.com/liamg/furious v0.0.0-20191231090757-c295c872d6c1 h1:lUcVBp3HQU0lr5V4RAD+B8WimUE13uYxYfKvqBLHFFo=
299299
github.com/liamg/furious v0.0.0-20191231090757-c295c872d6c1/go.mod h1:C3GdQ5NP2EDGxKNM6+ht7DnpsOu8qTNLGftjp5GOt2o=
300-
github.com/libp2p/go-reuseport v0.1.0 h1:0ooKOx2iwyIkf339WCZ2HN3ujTDbkK0PjC7JVoP1AiM=
301-
github.com/libp2p/go-reuseport v0.1.0/go.mod h1:bQVn9hmfcTaoo0c9v5pBhOarsU1eNOBZdaAd2hzXRKU=
300+
github.com/libp2p/go-reuseport v0.2.0 h1:18PRvIMlpY6ZK85nIAicSBuXXvrYoSw3dsBAR7zc560=
301+
github.com/libp2p/go-reuseport v0.2.0/go.mod h1:bvVho6eLMm6Bz5hmU0LYN3ixd3nPPvtIlaURZZgOY4k=
302302
github.com/linkedin/goavro/v2 v2.10.1 h1:ExVurHDnf0eyUocILs48kiZ4pGvaEbDvBOQcfLruA/0=
303303
github.com/linkedin/goavro/v2 v2.10.1/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
304304
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@@ -327,8 +327,8 @@ github.com/montanaflynn/stats v0.7.0 h1:r3y12KyNxj/Sb/iOE46ws+3mS1+MZca1wlHQFPsY
327327
github.com/montanaflynn/stats v0.7.0/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
328328
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a h1:AfneHvfmYgUIcgdUrrDFklLdEzQAvG9AKRTe1x1mx/0=
329329
github.com/mostlygeek/arp v0.0.0-20170424181311-541a2129847a/go.mod h1:jZxafo9CAqaKFQE4zitrg5QNlA6CXUsjwXPlIppF3tk=
330-
github.com/netsampler/goflow2 v1.1.1-0.20220818030102-fc42020d1b73 h1:nNfG9JFV14VoXxQ48chXoDid6WeCO4k3QESX4FEVsKM=
331-
github.com/netsampler/goflow2 v1.1.1-0.20220818030102-fc42020d1b73/go.mod h1:C9f54WtFVVbGpPWnpLMz+/hS3c7wc4L0g9ZzdIFAcuM=
330+
github.com/netsampler/goflow2/v2 v2.0.0 h1:Eued7ORLFI2q2+b8cMBcNeEkKOXHtly6KNO8L492aoM=
331+
github.com/netsampler/goflow2/v2 v2.0.0/go.mod h1:NsdiueJy8F5PXg0tHVYw9p0rvsryh8TFIxw7IR6Jjys=
332332
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
333333
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
334334
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
@@ -347,10 +347,10 @@ github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
347347
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
348348
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
349349
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
350-
github.com/oschwald/geoip2-golang v1.5.0 h1:igg2yQIrrcRccB1ytFXqBfOHCjXWIoMv85lVJ1ONZzw=
351-
github.com/oschwald/geoip2-golang v1.5.0/go.mod h1:xdvYt5xQzB8ORWFqPnqMwZpCpgNagttWdoZLlJQzg7s=
352-
github.com/oschwald/maxminddb-golang v1.8.0 h1:Uh/DSnGoxsyp/KYbY1AuP0tYEwfs0sCph9p/UMXK/Hk=
353-
github.com/oschwald/maxminddb-golang v1.8.0/go.mod h1:RXZtst0N6+FY/3qCNmZMBApR19cdQj43/NM9VkrNAis=
350+
github.com/oschwald/geoip2-golang v1.8.0 h1:KfjYB8ojCEn/QLqsDU0AzrJ3R5Qa9vFlx3z6SLNcKTs=
351+
github.com/oschwald/geoip2-golang v1.8.0/go.mod h1:R7bRvYjOeaoenAp9sKRS8GX5bJWcZ0laWO5+DauEktw=
352+
github.com/oschwald/maxminddb-golang v1.10.0 h1:Xp1u0ZhqkSuopaKmk1WwHtjF0H9Hd9181uj2MQ5Vndg=
353+
github.com/oschwald/maxminddb-golang v1.10.0/go.mod h1:Y2ELenReaLAZ0b400URyGwvYxHV1dLIxBuyOsyYjHK0=
354354
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
355355
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
356356
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2 h1:JhzVVoYvbOACxoUmOs6V/G4D5nPVUW73rKvXxP4XUJc=
@@ -397,8 +397,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
397397
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
398398
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
399399
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
400-
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
401-
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
400+
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
401+
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
402402
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
403403
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
404404
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
@@ -530,7 +530,6 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h
530530
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
531531
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
532532
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
533-
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
534533
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
535534
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
536535
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -539,9 +538,7 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
539538
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
540539
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
541540
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
542-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
543541
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
544-
golang.org/x/sys v0.0.0-20191224085550-c709ea063b76/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
545542
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
546543
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
547544
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

pkg/inputs/flow/flow.go

Lines changed: 86 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package flow
22

33
import (
44
"context"
5-
"encoding/json"
5+
"errors"
66
"flag"
77
"fmt"
88
"io"
9+
"net"
910
"net/http"
1011
"os"
1112

@@ -17,9 +18,13 @@ import (
1718
"github.com/kentik/ktranslate/pkg/kt"
1819
"github.com/kentik/ktranslate/pkg/util/resolv"
1920

20-
"github.com/netsampler/goflow2/producer"
21-
"github.com/netsampler/goflow2/utils"
21+
"github.com/netsampler/goflow2/v2/decoders/netflow"
22+
"github.com/netsampler/goflow2/v2/format"
23+
"github.com/netsampler/goflow2/v2/metrics"
24+
protoproducer "github.com/netsampler/goflow2/v2/producer/proto"
25+
"github.com/netsampler/goflow2/v2/utils"
2226
"github.com/prometheus/client_golang/prometheus/promhttp"
27+
"gopkg.in/yaml.v2"
2328
)
2429

2530
type FlowSource string
@@ -66,7 +71,7 @@ func NewFlowSource(ctx context.Context, proto FlowSource, maxBatchSize int, log
6671
}()
6772

6873
// Allow processing of custom ipfix templates here.
69-
var config EntConfig
74+
var config *protoproducer.ProducerConfig
7075

7176
// Load a special config if there's a known enriched flow.
7277
switch proto {
@@ -76,6 +81,8 @@ func NewFlowSource(ctx context.Context, proto FlowSource, maxBatchSize int, log
7681
config = loadNBar(cfg)
7782
case PAN:
7883
config = loadPAN(cfg)
84+
default:
85+
config = loadDefault(cfg)
7986
}
8087

8188
kt := NewKentikDriver(ctx, proto, maxBatchSize, log, registry, jchfChan, apic, cfg.MessageFields, resolv, cfg)
@@ -87,108 +94,104 @@ func NewFlowSource(ctx context.Context, proto FlowSource, maxBatchSize int, log
8794
kt.Errorf("Cannot load netflow mapping file: %v", err)
8895
return nil, err
8996
}
90-
config, err = loadMapping(f, proto)
97+
pc, err := loadMapping(f)
9198
f.Close()
9299
if err != nil {
93100
kt.Errorf("Invalid yaml for netflow mapping file: %v", err)
94101
return nil, err
95102
}
103+
config = pc
96104
}
97105

98-
kt.Infof("Netflow listener running on %s:%d for format %s and a batch size of %d", cfg.ListenIP, cfg.ListenPort, proto, maxBatchSize)
99-
kt.Infof("Netflow listener sending fields %s", cfg.MessageFields)
100106
kt.SetConfig(config)
101107

108+
flowProducer, err := protoproducer.CreateProtoProducer(config, protoproducer.CreateSamplingSystem)
109+
if err != nil {
110+
return nil, err
111+
}
112+
113+
flowProducer = metrics.WrapPromProducer(flowProducer)
114+
udpCfg := &utils.UDPReceiverConfig{
115+
Sockets: cfg.Workers,
116+
Workers: cfg.Workers,
117+
}
118+
recv, err := utils.NewUDPReceiver(udpCfg)
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
format.RegisterFormatDriver("chf", kt) // Let goflow know about kt.
124+
formatter, err := format.FindFormat("chf")
125+
if err != nil {
126+
return nil, err
127+
}
128+
129+
cfgPipe := &utils.PipeConfig{
130+
Format: formatter,
131+
Transport: nil,
132+
Producer: flowProducer,
133+
NetFlowTemplater: metrics.NewDefaultPromTemplateSystem, // wrap template system to get Prometheus info
134+
}
135+
136+
var decodeFunc utils.DecoderFunc
137+
102138
switch proto {
103-
case Ipfix, Netflow9, ASA, NBar, PAN:
104-
sNF := &utils.StateNetFlow{
105-
Format: kt,
106-
Logger: &KentikLog{l: kt},
107-
Config: &config.FlowConfig,
108-
}
139+
case Ipfix, Netflow9, ASA, NBar, PAN, Netflow5, JFlow, CFlow:
109140
switch proto {
110141
case Ipfix, ASA, NBar, PAN:
111-
for _, v := range config.FlowConfig.IPFIX.Mapping {
112-
kt.Infof("Custom IPFIX Field Mapping: Field=%v, Pen=%v -> %v", v.Type, v.Pen, config.NameMap[v.Destination])
142+
for _, v := range config.IPFIX.Mapping {
143+
kt.Infof("Custom IPFIX Field Mapping: Field=%v, Pen=%v -> %v", v.Type, v.Pen, v.Destination)
113144
}
114145
case Netflow9:
115-
for _, v := range config.FlowConfig.NetFlowV9.Mapping {
116-
kt.Infof("Custom Netflow9 Field Mapping: Field=%v -> %v", v.Type, config.NameMap[v.Destination])
146+
for _, v := range config.NetFlowV9.Mapping {
147+
kt.Infof("Custom Netflow9 Field Mapping: Field=%v -> %v", v.Type, v.Destination)
117148
}
118149
}
119-
go func() { // Let this run, returning flow into the kentik transport struct
120-
err := sNF.FlowRoutine(cfg.Workers, cfg.ListenIP, cfg.ListenPort, cfg.EnableReusePort)
121-
if err != nil {
122-
sNF.Logger.Fatalf("Fatal error: could not listen to UDP (%v)", err)
123-
}
124-
}()
125-
return kt, nil
150+
kt.pipe = utils.NewNetFlowPipe(cfgPipe)
151+
decodeFunc = metrics.PromDecoderWrapper(kt.pipe.DecodeFlow, string(proto))
126152
case Sflow:
127-
sSF := &utils.StateSFlow{
128-
Format: kt,
129-
Logger: &KentikLog{l: kt},
130-
Config: &config.FlowConfig,
131-
}
132-
for _, v := range config.FlowConfig.SFlow.Mapping {
133-
kt.Infof("Custom SFlow Field Mapping: Layer=%d, Offset=%d, Length=%d -> %v", v.Layer, v.Offset, v.Length, config.NameMap[v.Destination])
134-
}
135-
go func() { // Let this run, returning flow into the kentik transport struct
136-
err := sSF.FlowRoutine(cfg.Workers, cfg.ListenIP, cfg.ListenPort, cfg.EnableReusePort)
137-
if err != nil {
138-
sSF.Logger.Fatalf("Fatal error: could not listen to UDP (%v)", err)
139-
}
140-
}()
141-
return kt, nil
142-
case Netflow5, JFlow, CFlow:
143-
sNFL := &utils.StateNFLegacy{
144-
Format: kt,
145-
Logger: &KentikLog{l: kt},
153+
for _, v := range config.SFlow.Mapping {
154+
kt.Infof("Custom SFlow Field Mapping: Layer=%s, Offset=%d, Length=%d -> %v", v.Layer, v.Offset, v.Length, v.Destination)
146155
}
147-
go func() { // Let this run, returning flow into the kentik transport struct
148-
err := sNFL.FlowRoutine(cfg.Workers, cfg.ListenIP, cfg.ListenPort, cfg.EnableReusePort)
149-
if err != nil {
150-
sNFL.Logger.Fatalf("Fatal error: could not listen to UDP (%v)", err)
156+
kt.pipe = utils.NewSFlowPipe(cfgPipe)
157+
decodeFunc = metrics.PromDecoderWrapper(kt.pipe.DecodeFlow, string(proto))
158+
default:
159+
return nil, fmt.Errorf("Unknown flow format %v", proto)
160+
}
161+
162+
kt.producer = flowProducer
163+
kt.receiver = recv
164+
if err := kt.receiver.Start(cfg.ListenIP, cfg.ListenPort, decodeFunc); err != nil {
165+
return nil, err
166+
} else {
167+
go func() {
168+
for {
169+
select {
170+
case <-ctx.Done():
171+
return
172+
case err := <-recv.Errors():
173+
if errors.Is(err, netflow.ErrorTemplateNotFound) {
174+
kt.Warnf("template error: %v", err)
175+
} else if errors.Is(err, net.ErrClosed) {
176+
kt.Infof("closed receiver")
177+
} else {
178+
kt.Warnf("error: %v", err)
179+
}
180+
181+
}
151182
}
152183
}()
153-
return kt, nil
154184
}
155-
return nil, fmt.Errorf("Unknown flow format %v", proto)
156-
}
157-
158-
type EntConfig struct {
159-
FlowConfig producer.ProducerConfig `json:"flow_config"`
160-
NameMap map[string]string `json:"name_map"`
161-
}
162185

163-
func loadMapping(f io.Reader, proto FlowSource) (EntConfig, error) {
164-
config := EntConfig{}
165-
dec := json.NewDecoder(f)
166-
err := dec.Decode(&config)
186+
kt.Infof("Netflow listener running on %s:%d for format %s and a batch size of %d", cfg.ListenIP, cfg.ListenPort, proto, maxBatchSize)
187+
kt.Infof("Netflow listener sending fields %s", cfg.MessageFields)
167188

168-
// Update any non filled in name maps to the default.
169-
if config.NameMap == nil {
170-
config.NameMap = map[string]string{}
171-
}
172-
switch proto {
173-
case Ipfix, ASA, NBar, PAN:
174-
for _, v := range config.FlowConfig.IPFIX.Mapping {
175-
if _, ok := config.NameMap[v.Destination]; !ok {
176-
config.NameMap[v.Destination] = v.Destination
177-
}
178-
}
179-
case Netflow9:
180-
for _, v := range config.FlowConfig.NetFlowV9.Mapping {
181-
if _, ok := config.NameMap[v.Destination]; !ok {
182-
config.NameMap[v.Destination] = v.Destination
183-
}
184-
}
185-
case Sflow:
186-
for _, v := range config.FlowConfig.SFlow.Mapping {
187-
if _, ok := config.NameMap[v.Destination]; !ok {
188-
config.NameMap[v.Destination] = v.Destination
189-
}
190-
}
191-
}
189+
return kt, nil
190+
}
192191

192+
func loadMapping(f io.Reader) (*protoproducer.ProducerConfig, error) {
193+
config := &protoproducer.ProducerConfig{}
194+
dec := yaml.NewDecoder(f)
195+
err := dec.Decode(config)
193196
return config, err
194197
}

0 commit comments

Comments
 (0)