-
Notifications
You must be signed in to change notification settings - Fork 24
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
WIP NETOBSERV-1471 add tcp write stage #604
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package api | ||
|
||
type WriteTCP struct { | ||
Port string `yaml:"port,omitempty" json:"port,omitempty" doc:"TCP port number"` | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2021 IBM, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package write | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net" | ||
|
||
"github.com/netobserv/flowlogs-pipeline/pkg/config" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
type writeTCP struct { | ||
address string | ||
conn net.Conn | ||
} | ||
|
||
// Write writes a flow to tcp connection | ||
func (t *writeTCP) Write(v config.GenericMap) { | ||
logrus.Tracef("entering writeTCP Write") | ||
b, _ := json.Marshal(v) | ||
// append new line between each record to split on client side | ||
b = append(b, []byte("\n")...) | ||
_, err := t.conn.Write(b) | ||
if err != nil { | ||
log.WithError(err).Warn("can't write tcp") | ||
} | ||
} | ||
|
||
// NewWriteTCP create a new write | ||
func NewWriteTCP(params config.StageParam) (Writer, error) { | ||
logrus.Debugf("entering NewWriteTCP") | ||
writeTCP := &writeTCP{} | ||
if params.Write != nil && params.Write.TCP != nil && params.Write.TCP.Port != "" { | ||
writeTCP.address = ":" + params.Write.TCP.Port | ||
} else { | ||
return nil, fmt.Errorf("Write.TCP.Port must be specified") | ||
} | ||
|
||
logrus.Debugf("NewWriteTCP Listen %s", writeTCP.address) | ||
l, err := net.Listen("tcp", writeTCP.address) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer l.Close() | ||
clientConn, err := l.Accept() | ||
Comment on lines
+57
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like you are expecting some other entity to initiate a TCP connection to FLP to which FLP will write its flow logs. What is the use case you have in mind? What if I have multiple targets to which I want to send my data via TCP? Can I set up multiple writeTCP stages? How will it work? or do we want to put the listen() operation into a separate thread and accumulate the connections that were attempted and send flow logs to all current connections? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a temporary PR used in netobserv CLI: netobserv/network-observability-cli#2 (comment) The CLI deploys eBPF agents using If we keep that TCP implementation, we can indeed improve and makes the wait optionnal + allow multiple targets 👍 |
||
if err != nil { | ||
return nil, err | ||
} | ||
writeTCP.conn = clientConn | ||
|
||
return writeTCP, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix (or remove) Copyright statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is coming from both eBPF packets exporter and flp stdout write stage 😄
I just copied the code from there but I can remove the copyright if you want.