Skip to content

cmd/swarm-bench: replace go-metrics with local statistics - #3281

Open
thaJeztah wants to merge 1 commit into
moby:masterfrom
thaJeztah:remove_go_metrics
Open

cmd/swarm-bench: replace go-metrics with local statistics#3281
thaJeztah wants to merge 1 commit into
moby:masterfrom
thaJeztah:remove_go_metrics

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Aug 1, 2026

Copy link
Copy Markdown
Member

The go-metrics repository is archived, and swarm-bench only uses a small part of its timer implementation.

Replace it with a local collector that records task startup durations and calculates count, min, max, mean, standard deviation, and percentiles using the standard library. Preserve the percentile interpolation used by go-metrics, and replace its EWMA rates with the overall task completion rate.

Protect collection and snapshots with a mutex so that periodic statistics can still be reported safely while tasks are connecting.

Also make Collector's zero value usable and keep it local to Benchmark.Run, removing the now-unnecessary constructor and Benchmark field.

- What I did

- How I did it

- How to test it

- Description for the changelog

Comment on lines -62 to -64
fmt.Fprintf(w, " 1-min rate: %12.2f\n", t.Rate1())
fmt.Fprintf(w, " 5-min rate: %12.2f\n", t.Rate5())
fmt.Fprintf(w, " 15-min rate: %12.2f\n", t.Rate15())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can add these back if we care deeply (not sure if this utility is even used by anyone though, so kept it minimal).

@thaJeztah
thaJeztah marked this pull request as ready for review August 1, 2026 18:23
@thaJeztah
thaJeztah requested a review from Copilot August 1, 2026 18:24

Copilot AI left a comment

Copy link
Copy Markdown

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 removes the archived github.com/rcrowley/go-metrics dependency from cmd/swarm-bench and replaces it with a local, mutex-protected statistics collector that computes basic distribution stats and percentiles using the standard library.

Changes:

  • Drop go-metrics from go.mod/go.sum and remove its vendored sources.
  • Rework swarm-bench’s Collector to record per-task connection latencies and compute min/max/mean/stddev/percentiles and an overall completion rate.
  • Simplify Benchmark by making Collector a local variable in Benchmark.Run and removing the constructor/field.

Reviewed changes

Copilot reviewed 3 out of 34 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vendor/modules.txt Remove go-metrics from vendored module list
vendor/github.com/rcrowley/go-metrics/writer.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/validate.sh Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/timer.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/syslog.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/sample.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/runtime.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/runtime_no_gccpufraction.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/runtime_no_cgo.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/runtime_gccpufraction.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/runtime_cgo.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/registry.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/README.md Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/opentsdb.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/metrics.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/meter.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/memory.md Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/log.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/LICENSE Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/json.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/histogram.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/healthcheck.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/graphite.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/gauge.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/gauge_float64.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/ewma.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/debug.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/counter.go Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/.travis.yml Remove vendored go-metrics file
vendor/github.com/rcrowley/go-metrics/.gitignore Remove vendored go-metrics file
go.sum Remove go-metrics checksums
go.mod Remove go-metrics dependency
cmd/swarm-bench/collector.go Add local statistics collector implementation
cmd/swarm-bench/benchmark.go Use local collector; remove Benchmark field/ctor usage
Suppressed comments (1)

cmd/swarm-bench/benchmark.go:66

  • Benchmark.Run hard-codes the final stats display unit to time.Second, ignoring Config.Unit. Use b.cfg.Unit here as well for consistency with periodic reports.
	fmt.Printf("\n%s: Benchmark completed\n", time.Now())
	collector.Stats(os.Stdout, time.Second)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/swarm-bench/collector.go Outdated
Comment thread cmd/swarm-bench/benchmark.go
@codecov-commenter

codecov-commenter commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 58 lines in your changes missing coverage. Please review.
✅ Project coverage is 14.68%. Comparing base (6e9e7b8) to head (40c4014).
⚠️ Report is 60 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3281      +/-   ##
==========================================
- Coverage   14.73%   14.68%   -0.05%     
==========================================
  Files         200      200              
  Lines       93077    93055      -22     
==========================================
- Hits        13712    13667      -45     
- Misses      78019    78047      +28     
+ Partials     1346     1341       -5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 34 changed files in this pull request and generated 1 comment.

Comment thread cmd/swarm-bench/collector.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 34 changed files in this pull request and generated 1 comment.

Comment thread cmd/swarm-bench/collector.go
The go-metrics repository is archived, and swarm-bench only uses a small
part of its timer implementation.

Replace it with a local collector that records task startup durations and
calculates count, min, max, mean, standard deviation, and percentiles using
the standard library. Preserve the percentile interpolation used by
go-metrics, and replace its EWMA rates with the overall task completion
rate.

Protect collection and snapshots with a mutex so that periodic statistics
can still be reported safely while tasks are connecting.

Also make Collector's zero value usable and keep it local to Benchmark.Run,
removing the now-unnecessary constructor and Benchmark field.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 34 changed files in this pull request and generated 1 comment.

Suppressed comments (1)

cmd/swarm-bench/collector.go:51

  • Collect can spin indefinitely if Accept() starts returning a persistent error (e.g., listener closed) because it logs and continues without an exit path, and it also doesn't honor ctx cancellation to stop collection. Consider unblocking Accept() on ctx.Done() and returning on net.ErrClosed to avoid a tight error loop during shutdown/cancellation.
		conn, err := c.ln.Accept()
		if err != nil {
			log.G(ctx).WithError(err).Error("failure accepting connection")
			continue
		}

Comment on lines 3 to +7
import (
"context"
"fmt"
"io"
"math"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

you're dreaming?

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.

3 participants