Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NETOBSERV-962 - ADD write ipfix stage to pipeline builder #414

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/config/pipeline_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ func (b *PipelineBuilderStage) WriteLoki(name string, loki api.WriteLoki) Pipeli
return b.next(name, NewWriteLokiParams(name, loki))
}

// WriteIpfix chains the current stage with a WriteIpfix stage and returns that new stage
func (b *PipelineBuilderStage) WriteIpfix(name string, ipfix api.WriteIpfix) PipelineBuilderStage {
return b.next(name, NewWriteIpfixParams(name, ipfix))
}

// GetStages returns the current pipeline stages. It can be called from any of the stages, they share the same pipeline reference.
func (b *PipelineBuilderStage) GetStages() []Stage {
return b.pipeline.stages
Expand Down
40 changes: 40 additions & 0 deletions pkg/config/pipeline_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,43 @@ func TestForkPipeline(t *testing.T) {
require.NoError(t, err)
require.JSONEq(t, `{"name":"stdout","write":{"type":"stdout","stdout":{}}}`, string(b))
}

func TestIPFIXPipeline(t *testing.T) {
pl := NewCollectorPipeline("ingest", api.IngestCollector{HostName: "127.0.0.1", Port: 9999})
pl = pl.TransformNetwork("enrich", api.TransformNetwork{Rules: api.NetworkTransformRules{{
Type: api.AddKubernetesRuleType,
Input: "SrcAddr",
Output: "SrcK8S",
}, {
Type: api.AddKubernetesRuleType,
Input: "DstAddr",
Output: "DstK8S",
}}})
pl = pl.WriteIpfix("ipfix", api.WriteIpfix{
TargetHost: "ipfix-receiver-test",
TargetPort: 5999,
Transport: "tcp",
EnterpriseID: 1,
})
stages := pl.GetStages()
require.Len(t, stages, 3)

b, err := json.Marshal(stages)
require.NoError(t, err)
require.JSONEq(t, `[{"name":"ingest"},{"name":"enrich","follows":"ingest"},{"name":"ipfix","follows":"enrich"}]`, string(b))

params := pl.GetStageParams()
require.Len(t, params, 3)

b, err = json.Marshal(params[0])
require.NoError(t, err)
require.Equal(t, `{"name":"ingest","ingest":{"type":"collector","collector":{"hostName":"127.0.0.1","port":9999}}}`, string(b))

b, err = json.Marshal(params[1])
require.NoError(t, err)
require.JSONEq(t, `{"name":"enrich","transform":{"type":"network","network":{"directionInfo":{},"rules":[{"input":"SrcAddr","output":"SrcK8S","type":"add_kubernetes"},{"input":"DstAddr","output":"DstK8S","type":"add_kubernetes"}]}}}`, string(b))

b, err = json.Marshal(params[2])
require.NoError(t, err)
require.JSONEq(t, `{"name":"ipfix","write":{"type":"ipfix","ipfix":{"targetHost":"ipfix-receiver-test","targetPort":5999,"transport":"tcp","EnterpriseId":1}}}`, string(b))
}
4 changes: 4 additions & 0 deletions pkg/config/stage_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ func NewWriteStdoutParams(name string, stdout api.WriteStdout) StageParam {
func NewWriteLokiParams(name string, loki api.WriteLoki) StageParam {
return StageParam{Name: name, Write: &Write{Type: api.LokiType, Loki: &loki}}
}

func NewWriteIpfixParams(name string, ipfix api.WriteIpfix) StageParam {
return StageParam{Name: name, Write: &Write{Type: api.IpfixType, Ipfix: &ipfix}}
}