Conversation
There was a problem hiding this comment.
Pull request overview
This PR aligns OpenTelemetry metric instrument naming with proxy semantics (notably making proxy.connections represent the current active connection count) and adds coverage for the packet-connection tracking path.
Changes:
- Rename/standardize metric instruments (e.g.,
proxy.connections,proxy.connection.duration) and consolidate internal metric fields. - Update connection and packet-connection wrappers to record to the renamed instruments.
- Extend metrics tests with a new packet-connection tracker test and rename the existing connection tracker test.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tracker/metrics/metrics.go | Renames instruments and makes metric fields unexported; updates connection/duration metric names. |
| tracker/metrics/conn.go | Switches byte/connection tracking to the renamed internal instruments. |
| tracker/metrics/packet_conn.go | Switches packet byte/connection tracking to the renamed internal instruments. |
| tracker/metrics/tracker_test.go | Renames conn tracker test and adds packet-conn tracker test + a mock packet pipe. |
Comments suppressed due to low confidence (1)
tracker/metrics/tracker_test.go:32
- Both tests set the global OpenTelemetry meter provider via
sdkotel.SetMeterProvider(provider)but never restore the previous provider. Since this is global process state, it can leak into other package tests and cause ordering-dependent failures. Captureotel.GetMeterProvider()before setting and restore it int.Cleanup(ordefer) per test.
reader := metric.NewManualReader()
provider := metric.NewMeterProvider(metric.WithReader(reader))
sdkotel.SetMeterProvider(provider)
SetupMetricsManager("", "")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| buffer := buf.New() | ||
| _, err = serverTracked.ReadPacket(buffer) | ||
| assert.NoError(t, err) | ||
| serverReceive = buffer.Len() | ||
| t.Logf("Server received '%v'\n", string(buffer.Bytes())) |
There was a problem hiding this comment.
The receive buffer allocated with buf.New() is never released. Since buf.Buffer is pooled, this can leak pooled memory across tests. Add a defer buffer.Release() (after ensuring you no longer need its bytes) in this goroutine, and similarly for the client receive goroutine below.
| func SetupMetricsManager(geolite2CityURL, cityDBFile string) { | ||
| meter := otel.GetMeterProvider().Meter("lantern-box") | ||
|
|
||
| // Track the number of bytes sent and recieved. |
There was a problem hiding this comment.
The comment has a spelling typo: "recieved" should be "received".
| // Track the number of bytes sent and recieved. | |
| // Track the number of bytes sent and received. |
| go func() { | ||
| defer wg.Done() | ||
| buffer := buf.New() | ||
| _, err = serverTracked.ReadPacket(buffer) | ||
| assert.NoError(t, err) | ||
| serverReceive = buffer.Len() | ||
| t.Logf("Server received '%v'\n", string(buffer.Bytes())) | ||
| }() |
There was a problem hiding this comment.
The packet-conn test assigns to the shared outer err variable inside goroutines (_, err = serverTracked.ReadPacket(...) / _, err = client.ReadPacket(...)), which is a data race under -race. Use goroutine-local variables and report errors back to the main goroutine (e.g., error channels), or avoid goroutines when possible.
| func TestConnTracker(t *testing.T) { | ||
| var wg sync.WaitGroup | ||
| reader := metric.NewManualReader() | ||
| provider := metric.NewMeterProvider(metric.WithReader(reader)) |
There was a problem hiding this comment.
Inside TestConnTracker, goroutines assign to the outer err variable (and other shared vars). That will trip the race detector and can make the test flaky. Use goroutine-local errors and pass them back to the main goroutine (channels), or restructure the test to avoid concurrent writes to shared variables.
makes metric names more consistent, so
proxy.connectionsreflects the actual number of connections, and adds a missing test so the packet conn tracker is also covered