-
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?
Changes from 11 commits
16b12d1
f33d105
30b6d58
79cd030
f4b2a6b
b98892f
901ac81
a4ae2cd
836243b
ed8d851
78c7134
71644e4
b21f8d5
a33ec5d
8d4ce2d
f6ea39e
f67d1a8
6f7a802
4883f1e
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,103 @@ | ||
| # Conntrack Configuration | ||
|
|
||
| This document describes the configuration options available for the conntrack aggregator. | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| The conntrack aggregator can be configured using environment variables with the `CONNTRACK_` prefix: | ||
|
|
||
| | Variable | Default | Description | | ||
| |----------|---------|-------------| | ||
| | `CONNTRACK_EVENT_CHAN_SIZE` | `524288` | Event channel buffer size (512KB) | | ||
| | `CONNTRACK_EVENT_WORKER_COUNT` | `100` | Number of event worker goroutines | | ||
| | `CONNTRACK_DESTROY_FLUSH_INTERVAL` | `50ms` | Interval for flushing destroy deltas | | ||
| | `CONNTRACK_DESTROY_DELTA_CAP` | `200000` | Maximum destroy delta entries | | ||
| | `CONNTRACK_DROPS_WARN_THRESHOLD` | `10000` | Threshold for missed events warning | | ||
| | `CONNTRACK_READ_BUFFER_SIZE` | `67108864` | Read buffer size (64MB) | | ||
| | `CONNTRACK_WRITE_BUFFER_SIZE` | `67108864` | Write buffer size (64MB) | | ||
| | `CONNTRACK_HEALTH_CHECK_INTERVAL` | `5m` | Health check interval | | ||
| | `CONNTRACK_GRACEFUL_TIMEOUT` | `30s` | Graceful shutdown timeout | | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| ### Basic Configuration | ||
|
|
||
| ```bash | ||
| # Set custom buffer sizes | ||
| export CONNTRACK_EVENT_CHAN_SIZE=1048576 | ||
| export CONNTRACK_EVENT_WORKER_COUNT=200 | ||
|
|
||
| # Run the exporter | ||
| ./openvswitch_exporter | ||
| ``` | ||
|
|
||
| ### High-Throughput Environment | ||
|
|
||
| For environments with high conntrack event rates (>1M events/sec): | ||
|
|
||
| ```bash | ||
| export CONNTRACK_EVENT_CHAN_SIZE=1048576 # 1MB buffer | ||
| export CONNTRACK_EVENT_WORKER_COUNT=200 # More workers | ||
| export CONNTRACK_DESTROY_FLUSH_INTERVAL=25ms # Faster flushing | ||
| export CONNTRACK_DESTROY_DELTA_CAP=500000 # Larger delta cap | ||
| export CONNTRACK_READ_BUFFER_SIZE=134217728 # 128MB read buffer | ||
| export CONNTRACK_WRITE_BUFFER_SIZE=134217728 # 128MB write buffer | ||
| ``` | ||
|
|
||
| ### Low-Resource Environment | ||
|
|
||
| For environments with limited resources: | ||
|
|
||
| ```bash | ||
| export CONNTRACK_EVENT_CHAN_SIZE=65536 # 64KB buffer | ||
| export CONNTRACK_EVENT_WORKER_COUNT=50 # Fewer workers | ||
| export CONNTRACK_DESTROY_FLUSH_INTERVAL=100ms # Slower flushing | ||
| export CONNTRACK_DESTROY_DELTA_CAP=50000 # Smaller delta cap | ||
| export CONNTRACK_READ_BUFFER_SIZE=16777216 # 16MB read buffer | ||
| export CONNTRACK_WRITE_BUFFER_SIZE=16777216 # 16MB write buffer | ||
| ``` | ||
|
|
||
| ### Development/Testing | ||
|
|
||
| For development and testing: | ||
|
|
||
| ```bash | ||
| export CONNTRACK_GRACEFUL_TIMEOUT=5s # Faster shutdown | ||
| export CONNTRACK_HEALTH_CHECK_INTERVAL=1m # More frequent health checks | ||
| ``` | ||
|
|
||
| ## Configuration Validation | ||
|
|
||
| The configuration system includes validation: | ||
|
|
||
| - **Positive values**: All numeric values must be positive | ||
| - **Valid durations**: Time values must be valid Go durations | ||
| - **Range checks**: Values are checked for reasonable ranges | ||
|
|
||
| Invalid values will fall back to defaults with a warning logged. | ||
|
|
||
| ## Migration from Hardcoded Constants | ||
|
|
||
| The following hardcoded constants have been replaced: | ||
|
|
||
| | Old Constant | New Environment Variable | Default Value | | ||
| |--------------|-------------------------|---------------| | ||
| | `eventChanSize = 512 * 1024` | `CONNTRACK_EVENT_CHAN_SIZE` | `524288` | | ||
| | `eventWorkerCount = 100` | `CONNTRACK_EVENT_WORKER_COUNT` | `100` | | ||
| | `destroyFlushIntvl = 50ms` | `CONNTRACK_DESTROY_FLUSH_INTERVAL` | `50ms` | | ||
| | `destroyDeltaCap = 200000` | `CONNTRACK_DESTROY_DELTA_CAP` | `200000` | | ||
| | `dropsWarnThreshold = 10000` | `CONNTRACK_DROPS_WARN_THRESHOLD` | `10000` | | ||
| | Buffer sizes `64MB` | `CONNTRACK_READ_BUFFER_SIZE` / `WRITE_BUFFER_SIZE` | `67108864` | | ||
| | Health check `5m` | `CONNTRACK_HEALTH_CHECK_INTERVAL` | `5m` | | ||
| | Graceful timeout `30s` | `CONNTRACK_GRACEFUL_TIMEOUT` | `30s` | | ||
|
|
||
| ## Performance Impact | ||
|
|
||
| Configuration changes can significantly impact performance: | ||
|
|
||
| - **Larger buffers**: Better for high-throughput, uses more memory | ||
| - **More workers**: Better parallelism, uses more CPU | ||
| - **Faster flushing**: Lower latency, more CPU usage | ||
| - **Larger delta cap**: Handles bursts better, uses more memory | ||
|
|
||
| Choose settings based on your environment's characteristics and requirements. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,14 @@ | |
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "log" | ||
| "net/http" | ||
| "os" | ||
| "os/signal" | ||
| "syscall" | ||
| "time" | ||
|
|
||
| "github.com/digitalocean/go-openvswitch/ovsnl" | ||
| "github.com/digitalocean/openvswitch_exporter/internal/ovsexporter" | ||
|
|
@@ -38,9 +43,59 @@ func main() { | |
| http.Redirect(w, r, *metricsPath, http.StatusMovedPermanently) | ||
| }) | ||
|
|
||
| log.Printf("starting Open vSwitch exporter on %q", *metricsAddr) | ||
| // Create HTTP server | ||
| server := &http.Server{ | ||
| Addr: *metricsAddr, | ||
| Handler: mux, | ||
| } | ||
|
|
||
| // Handle shutdown signals | ||
| sigChan := make(chan os.Signal, 1) | ||
| signal.Notify(sigChan, | ||
| syscall.SIGINT, // Ctrl+C | ||
| syscall.SIGTERM, // Termination request | ||
| syscall.SIGHUP, // Hang up (config reload) | ||
| syscall.SIGQUIT, // Quit signal | ||
| ) | ||
|
|
||
| if err := http.ListenAndServe(*metricsAddr, mux); err != nil { | ||
| log.Fatalf("cannot start Open vSwitch exporter: %v", err) | ||
| // Start server in goroutine | ||
| go func() { | ||
| log.Printf("starting Open vSwitch exporter on %q", *metricsAddr) | ||
| if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { | ||
| log.Fatalf("cannot start Open vSwitch exporter: %v", err) | ||
| } | ||
| }() | ||
|
|
||
| // Wait for shutdown signal | ||
| sig := <-sigChan | ||
|
|
||
| switch sig { | ||
| case syscall.SIGHUP: | ||
| log.Printf("Received SIGHUP, reloading config...") | ||
| // TODO: Add config reload logic here | ||
| log.Printf("Config reloaded") | ||
| return | ||
|
||
| case syscall.SIGQUIT: | ||
|
||
| log.Printf("Received SIGQUIT, shutting down immediately...") | ||
| // Immediate shutdown for SIGQUIT | ||
| default: | ||
| log.Printf("Received signal %v, stopping gracefully...", sig) | ||
| } | ||
|
|
||
| // Graceful shutdown with 15 second timeout | ||
| ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) | ||
| defer cancel() | ||
|
|
||
| if err := server.Shutdown(ctx); err != nil { | ||
| log.Printf("Server shutdown error: %v", err) | ||
| } | ||
|
|
||
| // Close collector if it supports graceful shutdown | ||
| if closeable, ok := collector.(interface{ Close() error }); ok { | ||
| if err := closeable.Close(); err != nil { | ||
| log.Printf("Collector shutdown error: %v", err) | ||
| } | ||
| } | ||
|
|
||
| log.Printf("Exporter stopped") | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,30 @@ | ||
| module github.com/digitalocean/openvswitch_exporter | ||
|
|
||
| go 1.15 | ||
| go 1.25 | ||
|
|
||
| require ( | ||
| github.com/digitalocean/go-openvswitch v0.0.0-20201214180534-ce0f183468d8 | ||
| github.com/google/go-cmp v0.5.4 // indirect | ||
| github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
| github.com/mdlayher/netlink v1.3.2 // indirect | ||
| github.com/prometheus/client_golang v1.9.0 | ||
| github.com/prometheus/common v0.17.0 // indirect | ||
| github.com/prometheus/procfs v0.6.0 // indirect | ||
| github.com/prometheus/prometheus v2.2.1-0.20180315085919-58e2a31db8de+incompatible | ||
| golang.org/x/net v0.0.0-20210222171744-9060382bd457 // indirect | ||
| golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect | ||
| golang.org/x/sys v0.0.0-20210223095934-7937bea0104d // indirect | ||
| google.golang.org/protobuf v1.25.0 // indirect | ||
| github.com/ti-mo/conntrack v0.6.0 | ||
| github.com/ti-mo/netfilter v0.5.3 | ||
| golang.org/x/sync v0.17.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/beorn7/perks v1.0.1 // indirect | ||
| github.com/cespare/xxhash/v2 v2.1.1 // indirect | ||
| github.com/golang/protobuf v1.4.3 // indirect | ||
| github.com/google/go-cmp v0.7.0 // indirect | ||
| github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
| github.com/mdlayher/genetlink v1.3.2 // indirect | ||
| github.com/mdlayher/netlink v1.8.0 // indirect | ||
| github.com/mdlayher/socket v0.5.1 // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/prometheus/client_model v0.2.0 // indirect | ||
| github.com/prometheus/common v0.15.0 // indirect | ||
| github.com/prometheus/procfs v0.2.0 // indirect | ||
| golang.org/x/net v0.46.0 // indirect | ||
| golang.org/x/sys v0.37.0 // indirect | ||
| google.golang.org/protobuf v1.23.0 // indirect | ||
| ) |
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.gomore clear by adding these detailsThere 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