Skip to content

naming consistency, and add test#107

Open
thomasjib wants to merge 1 commit intomainfrom
metrics-names
Open

naming consistency, and add test#107
thomasjib wants to merge 1 commit intomainfrom
metrics-names

Conversation

@thomasjib
Copy link
Contributor

makes metric names more consistent, so proxy.connections reflects the actual number of connections, and adds a missing test so the packet conn tracker is also covered

Copilot AI review requested due to automatic review settings February 6, 2026 17:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. Capture otel.GetMeterProvider() before setting and restore it in t.Cleanup (or defer) 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.

Comment on lines +113 to +117
buffer := buf.New()
_, err = serverTracked.ReadPacket(buffer)
assert.NoError(t, err)
serverReceive = buffer.Len()
t.Logf("Server received '%v'\n", string(buffer.Bytes()))
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
func SetupMetricsManager(geolite2CityURL, cityDBFile string) {
meter := otel.GetMeterProvider().Meter("lantern-box")

// Track the number of bytes sent and recieved.
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment has a spelling typo: "recieved" should be "received".

Suggested change
// Track the number of bytes sent and recieved.
// Track the number of bytes sent and received.

Copilot uses AI. Check for mistakes.
Comment on lines +111 to +118
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()))
}()
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +25 to 28
func TestConnTracker(t *testing.T) {
var wg sync.WaitGroup
reader := metric.NewManualReader()
provider := metric.NewMeterProvider(metric.WithReader(reader))
Copy link

Copilot AI Feb 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants