-
Notifications
You must be signed in to change notification settings - Fork 105
GATEWAYS-4306: exporting metrics for conntrack per zone #137
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
Draft
shrouti1995
wants to merge
1
commit into
master
Choose a base branch
from
contrack.per.zone
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,35 @@ | ||
module github.com/digitalocean/go-openvswitch | ||
|
||
go 1.16 | ||
go 1.23.0 | ||
|
||
toolchain go1.24.2 | ||
|
||
require ( | ||
github.com/google/go-cmp v0.5.6 | ||
github.com/google/go-cmp v0.7.0 | ||
github.com/mdlayher/genetlink v1.0.0 | ||
github.com/mdlayher/netlink v1.4.1 | ||
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf | ||
github.com/mdlayher/netlink v1.7.2 | ||
golang.org/x/sys v0.34.0 | ||
) | ||
|
||
require ( | ||
github.com/cilium/ebpf v0.5.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/frankban/quicktest v1.11.3 // indirect | ||
github.com/josharian/native v1.1.0 // indirect | ||
github.com/jsimonetti/rtnetlink v0.0.0-20210525051524-4cc836578190 // indirect | ||
github.com/kr/pretty v0.2.1 // indirect | ||
github.com/kr/pty v1.1.1 // indirect | ||
github.com/kr/text v0.1.0 // indirect | ||
github.com/mdlayher/ethtool v0.0.0-20210210192532-2b88debcdd43 // indirect | ||
github.com/mdlayher/socket v0.5.1 // indirect | ||
github.com/pkg/errors v0.9.1 // indirect | ||
github.com/ti-mo/conntrack v0.5.2 // indirect | ||
github.com/ti-mo/netfilter v0.5.3 // indirect | ||
golang.org/x/crypto v0.37.0 // indirect | ||
golang.org/x/net v0.39.0 // indirect | ||
golang.org/x/sync v0.14.0 // indirect | ||
golang.org/x/term v0.31.0 // indirect | ||
golang.org/x/text v0.24.0 // indirect | ||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect | ||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect | ||
) |
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 |
---|---|---|
|
@@ -37,20 +37,45 @@ type Client struct { | |
// Datapath provides access to DatapathService methods. | ||
Datapath *DatapathService | ||
|
||
c *genetlink.Conn | ||
c *genetlink.Conn | ||
Conntrack *ConntrackService | ||
} | ||
|
||
// New creates a new Linux Open vSwitch generic netlink client. | ||
// | ||
// If no OvS generic netlink families are available on this system, an | ||
// error will be returned which can be checked using os.IsNotExist. | ||
func New() (*Client, error) { | ||
c, err := genetlink.Dial(nil) | ||
c := &Client{} // Create client instance first | ||
|
||
// Initialize the underlying genetlink connection. | ||
conn, err := genetlink.Dial(nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c.c = conn | ||
|
||
// Initialize services. | ||
families, err := c.c.ListFamilies() | ||
if err != nil { | ||
_ = c.c.Close() | ||
return nil, err | ||
} | ||
|
||
return newClient(c) | ||
if err := c.init(families); err != nil { | ||
_ = c.c.Close() | ||
return nil, err | ||
} | ||
|
||
// Initialize ConntrackService directly, as it manages its own internal conntrack.Conn | ||
conntrackService, err := NewConntrackService() // This will establish ti-mo/conntrack's connection | ||
if err != nil { | ||
_ = c.c.Close() // Ensure main client connection is closed | ||
return nil, fmt.Errorf("failed to create ConntrackService: %w", err) | ||
} | ||
c.Conntrack = conntrackService | ||
|
||
return c, nil | ||
} | ||
|
||
// newClient is the internal Client constructor, used in tests. | ||
|
@@ -75,26 +100,46 @@ func newClient(c *genetlink.Conn) (*Client, error) { | |
|
||
// Close closes the Client's generic netlink connection. | ||
func (c *Client) Close() error { | ||
return c.c.Close() | ||
var errs []error | ||
if c.c != nil { | ||
if err := c.c.Close(); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
if c.Conntrack != nil { | ||
if err := c.Conntrack.Close(); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
if len(errs) > 0 { | ||
return fmt.Errorf("errors closing client: %v", errs) | ||
} | ||
return nil | ||
} | ||
|
||
// init initializes the generic netlink family service of Client. | ||
func (c *Client) init(families []genetlink.Family) error { | ||
var gotf int | ||
|
||
for _, f := range families { | ||
// Ignore any families without the OVS prefix. | ||
if !strings.HasPrefix(f.Name, "ovs_") { | ||
continue | ||
} | ||
// Ignore any families that might be unknown. | ||
if err := c.initFamily(f); err != nil { | ||
// Initialize OVS-specific families | ||
if strings.HasPrefix(f.Name, "ovs_") { | ||
if err := c.initFamily(f); err != nil { | ||
// Log but continue if an OVS family fails to init | ||
fmt.Printf("Warning: failed to initialize OVS family %q: %v\n", f.Name, err) | ||
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. Using fmt.Printf for logging is not ideal in a library. Consider using a proper logging framework or returning these warnings through a different mechanism to allow callers to handle them appropriately. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
continue | ||
} | ||
} else if f.Name == "nf_conntrack" { // Explicitly initialize for Netfilter conntrack family | ||
// The ConntrackService is initialized separately by NewConntrackService(), | ||
// so we just acknowledge this family exists. | ||
// No direct assignment to c.Conntrack here because it manages its own connection. | ||
} else { | ||
// Skip other non-OVS/non-conntrack families | ||
continue | ||
} | ||
gotf++ | ||
} | ||
|
||
// No known families; return error for os.IsNotExist check. | ||
if gotf == 0 { | ||
return os.ErrNotExist | ||
} | ||
|
Oops, something went wrong.
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.
The ti-mo/conntrack dependency is marked as indirect but it's directly imported in ovsnl/conntrack.go. This should be moved to the direct require section.
Copilot uses AI. Check for mistakes.