-
Notifications
You must be signed in to change notification settings - Fork 107
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
base: master
Are you sure you want to change the base?
Changes from all commits
e306589
80916dc
8b03af1
e8eeddb
dc73f17
7b31316
02ce3ca
15e3b1a
b1b102c
9796da5
df047c7
51dbc5b
0f97bc6
578db7f
33d1c71
3d1d088
68f438c
4809d11
ff11970
5ac45d4
64416ca
457550e
6b139de
3f97fdb
6b5e843
70905a1
1a1e9d1
4c0669e
96ff4a1
5125d48
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 | ||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -37,64 +37,82 @@ type Client struct { | |||||||||||||||||||||||||||||||||||||||||||||||
// Datapath provides access to DatapathService methods. | ||||||||||||||||||||||||||||||||||||||||||||||||
Datapath *DatapathService | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
c *genetlink.Conn | ||||||||||||||||||||||||||||||||||||||||||||||||
c *genetlink.Conn | ||||||||||||||||||||||||||||||||||||||||||||||||
Agg *ZoneMarkAggregator | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// 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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
return newClient(c) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// newClient is the internal Client constructor, used in tests. | ||||||||||||||||||||||||||||||||||||||||||||||||
func newClient(c *genetlink.Conn) (*Client, error) { | ||||||||||||||||||||||||||||||||||||||||||||||||
// Must ensure that the generic netlink connection is closed on any errors | ||||||||||||||||||||||||||||||||||||||||||||||||
// that occur before it is returned to the caller. | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
families, err := c.ListFamilies() | ||||||||||||||||||||||||||||||||||||||||||||||||
// Initialize services. | ||||||||||||||||||||||||||||||||||||||||||||||||
families, err := c.c.ListFamilies() | ||||||||||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||
_ = c.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||
_ = c.c.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
client := &Client{c: c} | ||||||||||||||||||||||||||||||||||||||||||||||||
if err := client.init(families); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||
_ = c.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||
if err := c.init(families); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||
_ = c.c.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||
return nil, err | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
return client, nil | ||||||||||||||||||||||||||||||||||||||||||||||||
// Initialize aggregator as nil - will be created when needed | ||||||||||||||||||||||||||||||||||||||||||||||||
c.Agg = nil | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+70
to
+71
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.
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
return c, nil | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// Close closes the Client's generic netlink connection. | ||||||||||||||||||||||||||||||||||||||||||||||||
func (c *Client) Close() error { | ||||||||||||||||||||||||||||||||||||||||||||||||
return c.c.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||
var errs []error | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
if c.Agg != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||
c.Agg.Stop() | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
if c.c != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||
if err := c.c.Close(); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||
errs = append(errs, err) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
if len(errs) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||
return fmt.Errorf("errors closing client: %v", errs) | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+89
to
+91
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. [nitpick] The error handling could be improved by using a more structured approach. Consider using errors.Join (Go 1.20+) or a similar pattern to properly combine multiple errors instead of formatting them into a single string. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||||||||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+78
to
+92
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
// 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) | ||||||||||||||||||||||||||||||||||||||||||||||||
shrouti1995 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
} else if f.Name == "nf_conntrack" { // Explicitly initialize for Netfilter conntrack family | ||||||||||||||||||||||||||||||||||||||||||||||||
// Acknowledge that conntrack family exists - aggregator will handle conntrack operations | ||||||||||||||||||||||||||||||||||||||||||||||||
} 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 | ||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2017 DigitalOcean. | ||
// | ||
// 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 ovsnl | ||
|
||
import ( | ||
"net" | ||
) | ||
|
||
// ConntrackEntry represents a single connection tracking entry from the kernel. | ||
type ConntrackEntry struct { | ||
Protocol string // "tcp", "udp", "icmp" etc. | ||
OrigSrc net.IP | ||
OrigDst net.IP | ||
OrigSPort uint16 | ||
OrigDPort uint16 | ||
ReplySrc net.IP | ||
ReplyDst net.IP | ||
ReplySPort uint16 | ||
ReplyDPort uint16 | ||
Zone uint16 | ||
Mark uint32 | ||
State string | ||
} | ||
|
||
// ZoneStats holds statistics for a zone | ||
type ZoneStats struct { | ||
TotalCount int | ||
Entries []ConntrackEntry // Only populated if TotalCount > threshold | ||
} | ||
|
||
// ConntrackPerformanceStats represents aggregated performance counters from all CPUs | ||
type ConntrackPerformanceStats struct { | ||
TotalFound uint32 | ||
TotalInvalid uint32 | ||
TotalIgnore uint32 | ||
TotalInsert uint32 | ||
TotalInsertFailed uint32 | ||
TotalDrop uint32 | ||
TotalEarlyDrop uint32 | ||
TotalError uint32 | ||
TotalSearchRestart uint32 | ||
CPUs int | ||
} | ||
|
||
// ZmKey is a compact key for (zone,mark) | ||
type ZmKey struct { | ||
Zone uint16 | ||
Mark uint32 | ||
} |
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.