-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Flowlogs: make calico-node to fetch flow logs from a node #10144
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
Merged
Merged
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
d98f9ed
first commit
mazdakn 914c030
first prototype
mazdakn f6675fa
udapte
mazdakn 813a16d
Add more
mazdakn 1b4462b
update
mazdakn 0a91e70
more
mazdakn 71437b5
Cleanup
mazdakn 71e3bd2
Fix linter
mazdakn c20ee50
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn 57cae89
remove goldmane server mock
mazdakn 2013ced
Fix FVs
mazdakn 7c21315
clean up
mazdakn 8524f88
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn 744bc25
some more change
mazdakn fd1c83d
more
mazdakn e6e3ebf
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn d6d9c71
Add FV
mazdakn f4931da
Final cleanup
mazdakn 5b8fc24
Update Fv
mazdakn 95af41d
update comment
mazdakn f931e41
Fix FVs
mazdakn c479545
improve FV
mazdakn dfbd71c
Update node/cmd/calico-node/main.go
mazdakn a2c0168
Update felix/collector/goldmane/node_server.go
mazdakn 37b3f55
markup
mazdakn a4967ae
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn fe90de6
Fix node
mazdakn fc08717
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn 4b71e40
use a felixconfig
mazdakn 2ae5a5e
few changes
mazdakn 37376a6
update
mazdakn f5cb375
update
mazdakn 0cc4e5a
change config option
mazdakn a87bd9a
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn 9f3e845
change names
mazdakn 0ce48d9
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn d361089
rename to local socket
mazdakn 19c43e1
Merge remote-tracking branch 'open-source/master' into tool-flowlog
mazdakn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright (c) 2025 Tigera, Inc. All rights reserved. | ||
// | ||
// 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 goldmane | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"sync" | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
"github.com/projectcalico/calico/felix/collector/flowlog" | ||
"github.com/projectcalico/calico/goldmane/pkg/client" | ||
) | ||
|
||
const ( | ||
checkNodeSocketTimer = time.Second * 10 | ||
) | ||
|
||
type NodeSocketReporter struct { | ||
mazdakn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
client *client.FlowClient | ||
clientLock sync.RWMutex | ||
clientCancel context.CancelFunc | ||
once sync.Once | ||
} | ||
|
||
func NewNodeSocketReporter() *NodeSocketReporter { | ||
return &NodeSocketReporter{} | ||
} | ||
|
||
func (n *NodeSocketReporter) Start() error { | ||
var err error | ||
n.once.Do(func() { | ||
go n.nodeSocketReporter() | ||
}) | ||
return err | ||
} | ||
|
||
func (n *NodeSocketReporter) nodeSocketReporter() { | ||
for { | ||
if _, err := os.Stat(NodeSocketPath); err == nil { | ||
n.mayStartNodeSocketReporter() | ||
} else { | ||
n.mayStopNodeSocketReporter() | ||
} | ||
time.Sleep(checkNodeSocketTimer) | ||
} | ||
} | ||
|
||
func (n *NodeSocketReporter) nodeClientIsNil() bool { | ||
n.clientLock.RLock() | ||
defer n.clientLock.RUnlock() | ||
return n.client == nil | ||
} | ||
|
||
func (n *NodeSocketReporter) mayStartNodeSocketReporter() { | ||
// If node socket is already setup, do not try to set it up again. | ||
if !n.nodeClientIsNil() { | ||
return | ||
} | ||
|
||
var err error | ||
n.clientLock.Lock() | ||
defer n.clientLock.Unlock() | ||
n.client, err = client.NewFlowClient(NodeSocketAddress, "", "", "") | ||
if err != nil { | ||
logrus.WithError(err).Warn("Failed to create goldmane node socket client") | ||
return | ||
} | ||
logrus.Info("Created node socket client") | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
n.clientCancel = cancel | ||
n.client.Connect(ctx) | ||
} | ||
|
||
func (n *NodeSocketReporter) mayStopNodeSocketReporter() { | ||
// If node socket is already closed, do not try to close it again. | ||
if n.nodeClientIsNil() { | ||
return | ||
} | ||
|
||
n.clientLock.Lock() | ||
defer n.clientLock.Unlock() | ||
n.clientCancel() | ||
n.client = nil | ||
logrus.Info("Destroyed node socket client") | ||
} | ||
|
||
func (n *NodeSocketReporter) Report(logSlice any) error { | ||
switch logs := logSlice.(type) { | ||
case []*flowlog.FlowLog: | ||
if logrus.IsLevelEnabled(logrus.DebugLevel) { | ||
logrus.WithField("num", len(logs)).Debug("Dispatching flow logs to node socket") | ||
} | ||
for _, l := range logs { | ||
n.clientLock.RLock() | ||
if n.client != nil { | ||
n.client.Push(convertFlowlogToGoldmane(l)) | ||
} | ||
n.clientLock.RUnlock() | ||
} | ||
default: | ||
logrus.Panic("Unexpected kind of log dispatcher") | ||
} | ||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I still find this a bit confusing - this reporter isn't really for goldmane, rather it's for the node socket, right? Is this just a case of an awkward function name?
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.
changed it to
defaultFlowAggregator