-
Notifications
You must be signed in to change notification settings - Fork 10
GATEWAYS-4306: exporting metrics for conntrack per zone #21
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?
Conversation
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.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
internal/ovsexporter/conntrack.go
Outdated
| // ConntrackCollectorWithAggAccessor wraps the existing collector with access to the aggregator snapshot | ||
| type ConntrackCollectorWithAggAccessor struct { | ||
| *conntrackCollector | ||
| SnapshotFunc func() map[uint16]map[uint32]int |
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.
Is this used anywhere?
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.
removed
* trying to fix the static check issue * trying to fix the static check issue
* adding test cases * adding mock tests * Context-Based Cancellation Refactoring * add centralised error propagation * solve lint error
* adding test cases * adding mock tests * Context-Based Cancellation Refactoring * add centralised error propagation * solve lint error * modelling test cases in table format * graceful shut down * centralised config * solve lint error
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.
@anitgandhi @jcooperdo when you get time
internal/conntrack/mock.go
Outdated
| } | ||
|
|
||
| // NewZoneMarkAggregator creates a mock aggregator for testing | ||
| func NewZoneMarkAggregator() (*MockZoneMarkAggregator, error) { |
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 should be named NewMockZoneMarkAggregator()
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.
done
internal/conntrack/config.go
Outdated
| } | ||
|
|
||
| // LoadConfig loads conntrack configuration from environment variables | ||
| func LoadConfig() *Config { |
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.
it's confusing to use env vars directly for config here, when the top-level exporter config is driven by CLI flags
we should be consistent and use CLI flags for everything.
this package (internal/conntrack) shouldn't really care about flags vs env vars actually, it should only care about its own Config type/struct and associated defaults
it should be left up to the caller to define how to change the config (env vars, flags, whatever)
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.
applied
| // Test concurrent snapshot access | ||
| done := make(chan bool, 10) | ||
| for i := 0; i < 10; i++ { | ||
| go func() { | ||
| snapshot := agg.Snapshot() | ||
| if snapshot == nil { | ||
| t.Error("Concurrent snapshot returned nil") | ||
| } | ||
| done <- true | ||
| }() | ||
| } | ||
|
|
||
| // Wait for all goroutines | ||
| for i := 0; i < 10; i++ { | ||
| <-done | ||
| } |
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.
could simplify this with a waitgroup
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.
applied
internal/ovsexporter/ovsexporter.go
Outdated
| cs []prometheus.Collector | ||
| mu sync.Mutex | ||
| cs []prometheus.Collector | ||
| conntrackEnabled bool |
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.
is there ever a situation where this is false but aggregator is non-nil?
i don't believe there would be , in which case this extra bool doesn't provide any value
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.
removed
Co-authored-by: Anit Gandhi <anitgandhi@gmail.com>
internal/conntrack/config.go
Outdated
| } | ||
| } | ||
|
|
||
| // LoadConfig loads conntrack configuration from environment variables |
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.
remove this
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.
removed
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.
aggregator.go would be a better 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
CONNTRACK_CONFIG.md
Outdated
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 feels out-dated at this point seeing as we don't have env vars anymore and also in this PR we didn't have the hardcoded consts either
i'd recommend getting rid of this doc and instead making the godoc in internal/conntrack/config.go more clear by adding these details
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.
updated
internal/ovsexporter/ovsexporter.go
Outdated
| newDatapathCollector(c.Datapath.List), | ||
| } | ||
|
|
||
| // Create the aggregator |
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 don't see why we should put this in internal/ovsexporter at all
we should instead put the conntrack prometheus logic in internal/conntrack/exporter.go , and then just import it from main.go (if the additional exporter is enabled, which should be behind a new config flag bool in main.go)
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.
my bad. added it in this way.
| } | ||
|
|
||
| // StopWithTimeout cancels listening and closes the connection with a configurable timeout. | ||
| func (a *ZoneMarkAggregator) StopWithTimeout(timeout time.Duration) error { |
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.
does this need to be exported?
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
| func (a *ZoneMarkAggregator) GetError() error { | ||
| // This is a non-blocking way to check if there are any errors | ||
| // The actual error handling happens in Stop() | ||
| return 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.
looks like a no-op, remove if it's not going to be useful
internal/ovsexporter/ovsexporter.go
Outdated
| // Additional generic netlink family collectors can be added here. | ||
| newDatapathCollector(c.Datapath.List), | ||
| }, | ||
| collectors := []prometheus.Collector{ |
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.
can revert this
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.
done
internal/ovsexporter/test_helpers.go
Outdated
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 file should be in internal/conntrack right?
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.
cleaned it up.
cmd/openvswitch_exporter/main.go
Outdated
| case syscall.SIGHUP: | ||
| log.Printf("Received SIGHUP, reloading config...") | ||
| // TODO: Add config reload logic here | ||
| log.Printf("Config reloaded") | ||
| return |
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.
if we're not going to support this now (which i don't think we really need to), let's just not handle SIGHUP
cmd/openvswitch_exporter/main.go
Outdated
| // TODO: Add config reload logic here | ||
| log.Printf("Config reloaded") | ||
| return | ||
| case syscall.SIGQUIT: |
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.
doesn't seem like we're actually treating SIGQUIT any differently than the other signals in practice
also, generally handling SIQQUIT gracefully is a bit weird. The Go runtime already does the "correct" thing , which is to dump a stack trace and exit.
let's remove handling for this, and just leave the standard SIGINT and SIGTERM for graceful termination
Co-authored-by: Anit Gandhi <anitgandhi@gmail.com>
Adding support to export conntrack metrics per zone.
Details: