From e2f776e9206fc9e8d317173d98b38848d640c51b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 24 Aug 2026 12:23:37 +0100 Subject: [PATCH 1/3] feat(http): Add connection metrics Add metrics `net_conntrack_dialer_conn_*_total` for every connection attempted, failed, closed, etc. Signed-off-by: Bryan Boreham --- CHANGELOG.md | 2 +- exthttp/transport.go | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c59f03443..289d9df489 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re - [#155](https://github.com/thanos-io/objstore/pull/155) Add a `Provider` method on `objstore.Client`. - [#163](https://github.com/thanos-io/objstore/pull/145) Add a `NewBucketFromConfig` constructor method for creating a client from an existing `BucketConfig` object. - [#266](https://github.com/thanos-io/objstore/pull/266) *: Add `force_attempt_http2` option to `http_config` to re-enable HTTP/2 for the custom transport. - +- [#271](https://github.com/thanos-io/objstore/pull/271) Add metrics `net_conntrack_dialer_conn_*_total` for every connection attempted, failed, etc. ### Changed - [#38](https://github.com/thanos-io/objstore/pull/38) *: Upgrade minio-go version to `v7.0.45`. diff --git a/exthttp/transport.go b/exthttp/transport.go index f970b7b904..6ab350e65f 100644 --- a/exthttp/transport.go +++ b/exthttp/transport.go @@ -8,6 +8,7 @@ import ( "net/http" "time" + conntrack "github.com/mwitkow/go-conntrack" "github.com/prometheus/common/model" ) @@ -52,14 +53,19 @@ func DefaultTransport(config HTTPConfig) (*http.Transport, error) { } tlsConfig.InsecureSkipVerify = config.InsecureSkipVerify - return &http.Transport{ - Proxy: http.ProxyFromEnvironment, - DialContext: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - DualStack: true, - }).DialContext, + dialFn := (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + DualStack: true, + }).DialContext + // conntrack exports metrics for every connection attempted, failed, etc. + dialFn = conntrack.NewDialContextFunc( + conntrack.DialWithDialContextFunc(dialFn), + ) + return &http.Transport{ + Proxy: http.ProxyFromEnvironment, + DialContext: dialFn, MaxIdleConns: config.MaxIdleConns, MaxIdleConnsPerHost: config.MaxIdleConnsPerHost, IdleConnTimeout: time.Duration(config.IdleConnTimeout), From 55a65a618bf465bcfcc45e67f904d5db43089b48 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 28 Aug 2026 14:10:20 +0100 Subject: [PATCH 2/3] Default the dialer_name label to "objstore". Co-authored-by: Joao Marcal Signed-off-by: Bryan Boreham --- exthttp/transport.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/exthttp/transport.go b/exthttp/transport.go index 6ab350e65f..632567142c 100644 --- a/exthttp/transport.go +++ b/exthttp/transport.go @@ -61,6 +61,8 @@ func DefaultTransport(config HTTPConfig) (*http.Transport, error) { // conntrack exports metrics for every connection attempted, failed, etc. dialFn = conntrack.NewDialContextFunc( conntrack.DialWithDialContextFunc(dialFn), + // Can be overwritten with conntrack.DialNameToContext. + conntrack.DialWithName("objstore"), ) return &http.Transport{ From e5917762ad1e4d0e49d9dd550116308dc3f23ebf Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 28 Aug 2026 14:20:28 +0100 Subject: [PATCH 3/3] Make conntract dependency explicit Ran 'go mod tidy'. Signed-off-by: Bryan Boreham --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index bda71d3d52..7cff387526 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/go-kit/log v0.2.1 github.com/huaweicloud/huaweicloud-sdk-go-obs v3.25.4+incompatible github.com/minio/minio-go/v7 v7.0.95 + github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f github.com/ncw/swift v1.0.53 github.com/opentracing/opentracing-go v1.2.0 github.com/oracle/oci-go-sdk/v65 v65.41.1 @@ -94,7 +95,6 @@ require ( github.com/minio/md5-simd v1.1.2 // indirect github.com/mitchellh/mapstructure v1.4.3 // indirect github.com/mozillazg/go-httpheader v0.2.1 // indirect - github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/philhofer/fwd v1.2.0 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect