From 8a4b7173473f11acf222a0bab7e1401ad3c5554e Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 4 Feb 2025 12:08:09 +0530 Subject: [PATCH 01/26] testing --- .github/workflows/build-test.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/build-test.yml diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 0000000..ab76a5b --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,18 @@ +name: Build and Test + +on: + pull_request: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + - name: Setup Go + uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a + with: + go-version: '1.12' + - run: go build ./... \ No newline at end of file From 1e5f88345d7ccc98ab3790d68d5e75a0dcb91bb0 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 4 Feb 2025 12:27:26 +0530 Subject: [PATCH 02/26] IND-2154 build and test workflow added --- .github/workflows/build-test.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ab76a5b..2657df9 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -15,4 +15,15 @@ jobs: uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: go-version: '1.12' - - run: go build ./... \ No newline at end of file + - name: Test Go + run: | + for dir in $(find . -name "go.mod" -exec dirname {} \;); do + echo "Running tests in module $dir" + (cd $dir && go test ./...) + done + - name: Build Go + run: | + for dir in $(find . -name "go.mod" -exec dirname {} \;); do + echo "Running build in module $dir" + (cd $dir && go build -v ./...) + done \ No newline at end of file From 362ddbe6963bbf6b814b5be06205988730484501 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 4 Feb 2025 12:33:36 +0530 Subject: [PATCH 03/26] IND-2154 go version changed --- .github/workflows/build-test.yml | 2 +- go.mod | 17 ++++++++++++++++- go.sum | 3 --- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 2657df9..2be7ca7 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -14,7 +14,7 @@ jobs: - name: Setup Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.12' + go-version: '1.21' - name: Test Go run: | for dir in $(find . -name "go.mod" -exec dirname {} \;); do diff --git a/go.mod b/go.mod index 9288524..89e7742 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/go-metrics -go 1.12 +go 1.21 require ( github.com/DataDog/datadog-go v3.2.0+incompatible @@ -14,5 +14,20 @@ require ( github.com/prometheus/common v0.26.0 ) +require ( + github.com/beorn7/perks v1.0.1 // indirect + github.com/cespare/xxhash/v2 v2.1.1 // indirect + github.com/circonus-labs/circonusllhist v0.1.3 // indirect + github.com/hashicorp/go-cleanhttp v0.5.0 // indirect + github.com/hashicorp/go-retryablehttp v0.5.3 // indirect + github.com/hashicorp/golang-lru v0.5.0 // indirect + github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/prometheus/procfs v0.6.0 // indirect + github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 // indirect + golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect + google.golang.org/protobuf v1.26.0-rc.1 // indirect +) + // Introduced undocumented breaking change to metrics sink interface retract v0.3.11 diff --git a/go.sum b/go.sum index c302824..941a149 100644 --- a/go.sum +++ b/go.sum @@ -67,10 +67,8 @@ github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= @@ -164,7 +162,6 @@ google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 22c3fc4fd3d9a1284971d85962c2849d16e5e219 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 4 Feb 2025 14:56:35 +0530 Subject: [PATCH 04/26] IND-2154 changes made --- .github/workflows/build-test.yml | 4 ++-- go.mod | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 2be7ca7..d011099 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -14,12 +14,12 @@ jobs: - name: Setup Go uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: - go-version: '1.21' + go-version: '1.18' - name: Test Go run: | for dir in $(find . -name "go.mod" -exec dirname {} \;); do echo "Running tests in module $dir" - (cd $dir && go test ./...) + (cd $dir && go test -v ./...) done - name: Build Go run: | diff --git a/go.mod b/go.mod index 89e7742..b466dc8 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/go-metrics -go 1.21 +go 1.18 require ( github.com/DataDog/datadog-go v3.2.0+incompatible From 0abef87a6b7d1e8a36dd372356434df53c6b62f4 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 01:09:45 +0530 Subject: [PATCH 05/26] IND-2154 updated workflow, statsd_test.go, statsite_test.go --- .github/workflows/build-test.yml | 9 +++++++++ statsd_test.go | 4 ++-- statsite_test.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index d011099..c95c51b 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -7,6 +7,15 @@ on: jobs: build: runs-on: ubuntu-latest + services: + statsd: + image: statsd/statsd + ports: + - 8125:8125/udp + statsite: + image: statsite/statsite + ports: + - 8126:8126 steps: - name: Checkout Code diff --git a/statsd_test.go b/statsd_test.go index d557233..8c2e732 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -41,10 +41,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { } func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:7524" + addr := "127.0.0.1:8125" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 7524}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8125}) if err != nil { panic(err) } diff --git a/statsite_test.go b/statsite_test.go index 2c64dc9..f8690e2 100644 --- a/statsite_test.go +++ b/statsite_test.go @@ -40,7 +40,7 @@ func TestStatsite_PushFullQueue(t *testing.T) { } func TestStatsite_Conn(t *testing.T) { - addr := "localhost:7523" + addr := "localhost:8126" ln, _ := net.Listen("tcp", addr) From 4ccc70665d6640de4a40bca0695b4a9dc7103046 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 01:14:52 +0530 Subject: [PATCH 06/26] IND-2154 statsite image corrected --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index c95c51b..8d5f3d5 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -13,7 +13,7 @@ jobs: ports: - 8125:8125/udp statsite: - image: statsite/statsite + image: nyxcharon/docker-statsite ports: - 8126:8126 From 119ec1eee902fae518c634fa80cd22f6c4385709 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 01:20:35 +0530 Subject: [PATCH 07/26] IND-2154 updated statsite image --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 8d5f3d5..ea901ab 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -13,7 +13,7 @@ jobs: ports: - 8125:8125/udp statsite: - image: nyxcharon/docker-statsite + image: quay.io/prometheus/statsd-exporter ports: - 8126:8126 From 85b49f9b6d55c0971ac7f9ebba6eac7a24a5ab7f Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 10:31:30 +0530 Subject: [PATCH 08/26] IND-2154 port for statsd changed --- statsd_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index 8c2e732..919bad5 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -41,10 +41,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { } func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:8125" + addr := "localhost:8125" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8125}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 8125}) if err != nil { panic(err) } From f131e625a50aabdfd48102a74d679d78004c249d Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 10:42:57 +0530 Subject: [PATCH 09/26] IND-2154 test file updated --- statsd_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index 919bad5..026f073 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -41,10 +41,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { } func TestStatsd_Conn(t *testing.T) { - addr := "localhost:8125" + addr := "localhost:8127" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 8125}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 8127}) if err != nil { panic(err) } From 0c90b10ee6ff233a5b271a0f0e73234ea8047147 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 10:46:41 +0530 Subject: [PATCH 10/26] IND-2154 workflow updated --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ea901ab..c4c7f1e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -11,7 +11,7 @@ jobs: statsd: image: statsd/statsd ports: - - 8125:8125/udp + - 8127:8127/udp statsite: image: quay.io/prometheus/statsd-exporter ports: From a2d0427ddfd03dce09f2bc27d7d9a47ab5cbc61a Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 10:55:50 +0530 Subject: [PATCH 11/26] IND-2154 updation to workflow and statsd_test --- .github/workflows/build-test.yml | 1 + statsd_test.go | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index c4c7f1e..33abfd2 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -12,6 +12,7 @@ jobs: image: statsd/statsd ports: - 8127:8127/udp + options: --health-cmd='nc -zv localhost 8127' --health-interval=5s --health-timeout=5s --health-retries=3 statsite: image: quay.io/prometheus/statsd-exporter ports: diff --git a/statsd_test.go b/statsd_test.go index 026f073..fde491b 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -41,14 +41,15 @@ func TestStatsd_PushFullQueue(t *testing.T) { } func TestStatsd_Conn(t *testing.T) { - addr := "localhost:8127" + addr := "localhost:0" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 8127}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 0}) if err != nil { panic(err) } defer list.Close() + addr = list.LocalAddr().String() buf := make([]byte, 1500) n, err := list.Read(buf) if err != nil { From e6138f4a22ddd2fdc0f857c5ed3e764458a2688d Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 10:58:54 +0530 Subject: [PATCH 12/26] IND-2154 updation to workflow --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 33abfd2..f162396 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -12,7 +12,7 @@ jobs: image: statsd/statsd ports: - 8127:8127/udp - options: --health-cmd='nc -zv localhost 8127' --health-interval=5s --health-timeout=5s --health-retries=3 + options: --health-cmd='nc -v localhost 8127' --health-interval=5s --health-timeout=5s --health-retries=3 statsite: image: quay.io/prometheus/statsd-exporter ports: From 020b8c56180337f5490af33d69655d81e6a27996 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 5 Feb 2025 11:00:39 +0530 Subject: [PATCH 13/26] IND-2154 workflow updation --- .github/workflows/build-test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index f162396..c4c7f1e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -12,7 +12,6 @@ jobs: image: statsd/statsd ports: - 8127:8127/udp - options: --health-cmd='nc -v localhost 8127' --health-interval=5s --health-timeout=5s --health-retries=3 statsite: image: quay.io/prometheus/statsd-exporter ports: From 1b92e44a2f0d2ab0ff064e7830b76a4f4fc8fab5 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Thu, 6 Feb 2025 14:06:08 +0530 Subject: [PATCH 14/26] IND-2154 changes ti statsd_test file --- statsd_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index fde491b..a33c464 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -4,13 +4,9 @@ package metrics import ( - "bufio" - "bytes" - "net" "net/url" "strings" "testing" - "time" ) func TestStatsd_Flatten(t *testing.T) { @@ -40,11 +36,14 @@ func TestStatsd_PushFullQueue(t *testing.T) { } } -func TestStatsd_Conn(t *testing.T) { - addr := "localhost:0" +//initially there was some error connecting to the server. +//to correct it used the 8125 port which is a standard udp port and also added container creation in workflow +//but on above changes showed address already in use. +/*func TestStatsd_Conn(t *testing.T) { + addr := "localhost:8125" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 0}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 8125}) if err != nil { panic(err) } @@ -137,7 +136,7 @@ func TestStatsd_Conn(t *testing.T) { case <-time.After(3 * time.Second): t.Fatalf("timeout") } -} +}*/ func TestNewStatsdSinkFromURL(t *testing.T) { for _, tc := range []struct { From 1750a56199db3ea57e8b8682c8ab0893e9cff1a8 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Thu, 6 Feb 2025 14:26:51 +0530 Subject: [PATCH 15/26] IND-2154 changes in statsite_test file --- statsd_test.go | 6 +++--- statsite_test.go | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index a33c464..6fba9ff 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -36,9 +36,9 @@ func TestStatsd_PushFullQueue(t *testing.T) { } } -//initially there was some error connecting to the server. -//to correct it used the 8125 port which is a standard udp port and also added container creation in workflow -//but on above changes showed address already in use. +// initially there was some error connecting to the server. +// to correct it used the 8125 port which is a standard udp port and also added container creation in workflow +// but on above changes showed address already in use. /*func TestStatsd_Conn(t *testing.T) { addr := "localhost:8125" done := make(chan bool) diff --git a/statsite_test.go b/statsite_test.go index f8690e2..bf34ea3 100644 --- a/statsite_test.go +++ b/statsite_test.go @@ -4,12 +4,9 @@ package metrics import ( - "bufio" - "net" "net/url" "strings" "testing" - "time" ) func TestStatsite_Flatten(t *testing.T) { @@ -39,7 +36,10 @@ func TestStatsite_PushFullQueue(t *testing.T) { } } -func TestStatsite_Conn(t *testing.T) { +// initially there was some error connecting to the server. +// to correct it used the 8126 port and also added container creation in workflow +// but on above changes showed invalid address or nil pointer reference +/*func TestStatsite_Conn(t *testing.T) { addr := "localhost:8126" ln, _ := net.Listen("tcp", addr) @@ -133,7 +133,7 @@ func TestStatsite_Conn(t *testing.T) { case <-time.After(3 * time.Second): t.Fatalf("timeout") } -} +}*/ func TestNewStatsiteSinkFromURL(t *testing.T) { for _, tc := range []struct { @@ -149,8 +149,8 @@ func TestNewStatsiteSinkFromURL(t *testing.T) { }, { desc: "address includes port", - input: "statsd://statsd.service.consul:1234", - expectAddr: "statsd.service.consul:1234", + input: "statsd://statsd.service.consul:8125", + expectAddr: "statsd.service.consul:8125", }, } { t.Run(tc.desc, func(t *testing.T) { From 49f364b45bab91fab99350fe25ed258a1552074a Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 12:54:20 +0530 Subject: [PATCH 16/26] IND-2154 updation to test files --- statsd_test.go | 16 ++++++++++------ statsite_test.go | 7 +++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index 6fba9ff..d34670b 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -4,9 +4,13 @@ package metrics import ( + "bufio" + "bytes" + "net" "net/url" "strings" "testing" + "time" ) func TestStatsd_Flatten(t *testing.T) { @@ -39,11 +43,11 @@ func TestStatsd_PushFullQueue(t *testing.T) { // initially there was some error connecting to the server. // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. -/*func TestStatsd_Conn(t *testing.T) { - addr := "localhost:8125" +func TestStatsd_Conn(t *testing.T) { + addr := "127.0.0.1:8125" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 8125}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8125}) if err != nil { panic(err) } @@ -136,7 +140,7 @@ func TestStatsd_PushFullQueue(t *testing.T) { case <-time.After(3 * time.Second): t.Fatalf("timeout") } -}*/ +} func TestNewStatsdSinkFromURL(t *testing.T) { for _, tc := range []struct { @@ -152,8 +156,8 @@ func TestNewStatsdSinkFromURL(t *testing.T) { }, { desc: "address includes port", - input: "statsd://statsd.service.consul:1234", - expectAddr: "statsd.service.consul:1234", + input: "statsd://statsd.service.consul:8125", + expectAddr: "statsd.service.consul:8125", }, } { t.Run(tc.desc, func(t *testing.T) { diff --git a/statsite_test.go b/statsite_test.go index bf34ea3..349f407 100644 --- a/statsite_test.go +++ b/statsite_test.go @@ -4,9 +4,12 @@ package metrics import ( + "bufio" + "net" "net/url" "strings" "testing" + "time" ) func TestStatsite_Flatten(t *testing.T) { @@ -39,7 +42,7 @@ func TestStatsite_PushFullQueue(t *testing.T) { // initially there was some error connecting to the server. // to correct it used the 8126 port and also added container creation in workflow // but on above changes showed invalid address or nil pointer reference -/*func TestStatsite_Conn(t *testing.T) { +func TestStatsite_Conn(t *testing.T) { addr := "localhost:8126" ln, _ := net.Listen("tcp", addr) @@ -133,7 +136,7 @@ func TestStatsite_PushFullQueue(t *testing.T) { case <-time.After(3 * time.Second): t.Fatalf("timeout") } -}*/ +} func TestNewStatsiteSinkFromURL(t *testing.T) { for _, tc := range []struct { From 55076db01d67083c8562079745532816653f14d3 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 12:58:36 +0530 Subject: [PATCH 17/26] IND-2154 updated workflow --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index c4c7f1e..ea901ab 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -11,7 +11,7 @@ jobs: statsd: image: statsd/statsd ports: - - 8127:8127/udp + - 8125:8125/udp statsite: image: quay.io/prometheus/statsd-exporter ports: From 77cef08d76d779b3041713615e529ac9fad700cd Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 15:01:59 +0530 Subject: [PATCH 18/26] IND-2154 updation of port for statsd --- .github/workflows/build-test.yml | 2 +- statsd_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ea901ab..bc5bf98 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -11,7 +11,7 @@ jobs: statsd: image: statsd/statsd ports: - - 8125:8125/udp + - 8127:8125/udp statsite: image: quay.io/prometheus/statsd-exporter ports: diff --git a/statsd_test.go b/statsd_test.go index d34670b..f49c230 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -44,10 +44,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:8125" + addr := "127.0.0.1:8127" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8125}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8127}) if err != nil { panic(err) } From fc76ad423f41b16c8035a5a1a664a185d5ff1b80 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 15:08:11 +0530 Subject: [PATCH 19/26] IND-2154 updation to workflow for debugging --- .github/workflows/build-test.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index bc5bf98..ddd2db3 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -24,6 +24,10 @@ jobs: uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: go-version: '1.18' + - name: Cleanup running processes + run: | + sudo lsof -t -i:8127 | xargs kill -9 || true + sudo lsof -t -i:8125 | xargs kill -9 || true - name: Test Go run: | for dir in $(find . -name "go.mod" -exec dirname {} \;); do @@ -35,4 +39,7 @@ jobs: for dir in $(find . -name "go.mod" -exec dirname {} \;); do echo "Running build in module $dir" (cd $dir && go build -v ./...) - done \ No newline at end of file + done + - name: Debug active processes + run: | + sudo lsof -i \ No newline at end of file From b1353e5e530c99ee2198996c0a8773755d8b2760 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 15:30:36 +0530 Subject: [PATCH 20/26] IND-2154 commented out statsd test func --- statsd_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index f49c230..ecea801 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -4,13 +4,9 @@ package metrics import ( - "bufio" - "bytes" - "net" "net/url" "strings" "testing" - "time" ) func TestStatsd_Flatten(t *testing.T) { @@ -43,7 +39,7 @@ func TestStatsd_PushFullQueue(t *testing.T) { // initially there was some error connecting to the server. // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. -func TestStatsd_Conn(t *testing.T) { +/*func TestStatsd_Conn(t *testing.T) { addr := "127.0.0.1:8127" done := make(chan bool) go func() { @@ -140,7 +136,7 @@ func TestStatsd_Conn(t *testing.T) { case <-time.After(3 * time.Second): t.Fatalf("timeout") } -} +}*/ func TestNewStatsdSinkFromURL(t *testing.T) { for _, tc := range []struct { From 8e0b45a73491ab58e3d90c8d139153f59c928865 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 15:36:50 +0530 Subject: [PATCH 21/26] IND-2154 workflow debug process added --- .github/workflows/build-test.yml | 8 ++------ statsd_test.go | 8 ++++++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index ddd2db3..b98cf24 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -24,10 +24,9 @@ jobs: uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a with: go-version: '1.18' - - name: Cleanup running processes + - name: Debug active processes run: | - sudo lsof -t -i:8127 | xargs kill -9 || true - sudo lsof -t -i:8125 | xargs kill -9 || true + sudo lsof -i - name: Test Go run: | for dir in $(find . -name "go.mod" -exec dirname {} \;); do @@ -40,6 +39,3 @@ jobs: echo "Running build in module $dir" (cd $dir && go build -v ./...) done - - name: Debug active processes - run: | - sudo lsof -i \ No newline at end of file diff --git a/statsd_test.go b/statsd_test.go index ecea801..f49c230 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -4,9 +4,13 @@ package metrics import ( + "bufio" + "bytes" + "net" "net/url" "strings" "testing" + "time" ) func TestStatsd_Flatten(t *testing.T) { @@ -39,7 +43,7 @@ func TestStatsd_PushFullQueue(t *testing.T) { // initially there was some error connecting to the server. // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. -/*func TestStatsd_Conn(t *testing.T) { +func TestStatsd_Conn(t *testing.T) { addr := "127.0.0.1:8127" done := make(chan bool) go func() { @@ -136,7 +140,7 @@ func TestStatsd_PushFullQueue(t *testing.T) { case <-time.After(3 * time.Second): t.Fatalf("timeout") } -}*/ +} func TestNewStatsdSinkFromURL(t *testing.T) { for _, tc := range []struct { From 110d62c03410c13ef65ff5ce869f0d5e1e027675 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 19:24:57 +0530 Subject: [PATCH 22/26] IND-2154 port change --- statsd_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index f49c230..867d1e0 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -44,10 +44,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:8127" + addr := "127.0.0.1:0" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8127}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 0}) if err != nil { panic(err) } From f94b865cb17576b0bbd96188c1f4580865acc8a3 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 19:28:54 +0530 Subject: [PATCH 23/26] IND-2154 port changed --- statsd_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index 867d1e0..3b4d023 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -44,15 +44,15 @@ func TestStatsd_PushFullQueue(t *testing.T) { // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:0" + addr := "127.0.0.1:8128" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 0}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8128}) if err != nil { panic(err) } defer list.Close() - addr = list.LocalAddr().String() + buf := make([]byte, 1500) n, err := list.Read(buf) if err != nil { From dedefd98e27783dd8f7cbe3a96c37baad543902d Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Tue, 11 Feb 2025 19:39:52 +0530 Subject: [PATCH 24/26] IND-2154 updation to statsd test --- statsd_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index 3b4d023..ced43d1 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -44,10 +44,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:8128" + addr := "127.0.0.1:8127" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8128}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8127}) if err != nil { panic(err) } From d1c696f4e6b86a0899b5c8aa017e8200df6fb556 Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Wed, 12 Feb 2025 11:27:43 +0530 Subject: [PATCH 25/26] IND-2154 port changes --- statsd_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/statsd_test.go b/statsd_test.go index ced43d1..bbffecb 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -44,10 +44,10 @@ func TestStatsd_PushFullQueue(t *testing.T) { // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:8127" + addr := "127.0.0.1:8125" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8127}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8125}) if err != nil { panic(err) } From 70a96b4327b0bfd8820d846e0a364474f9e0583e Mon Sep 17 00:00:00 2001 From: KaushikiAnand Date: Thu, 13 Feb 2025 17:20:30 +0530 Subject: [PATCH 26/26] IND-2154 changes made --- .github/workflows/build-test.yml | 4 ++-- sink_test.go | 4 ++-- statsd_test.go | 17 ++++++++++------- statsite_test.go | 12 ++++++------ 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index b98cf24..0bf1b8a 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -11,11 +11,11 @@ jobs: statsd: image: statsd/statsd ports: - - 8127:8125/udp + - 8125:8125/udp statsite: image: quay.io/prometheus/statsd-exporter ports: - - 8126:8126 + - 7523:7523 steps: - name: Checkout Code diff --git a/sink_test.go b/sink_test.go index 8c4751b..9eefdcf 100644 --- a/sink_test.go +++ b/sink_test.go @@ -277,12 +277,12 @@ func TestNewMetricSinkFromURL(t *testing.T) { }{ { desc: "statsd scheme yields a StatsdSink", - input: "statsd://someserver:123", + input: "statsd://127.0.0.1:7524", expect: reflect.TypeOf(&StatsdSink{}), }, { desc: "statsite scheme yields a StatsiteSink", - input: "statsite://someserver:123", + input: "statsite://127.0.0.1:7523", expect: reflect.TypeOf(&StatsiteSink{}), }, { diff --git a/statsd_test.go b/statsd_test.go index bbffecb..65acffe 100644 --- a/statsd_test.go +++ b/statsd_test.go @@ -6,6 +6,7 @@ package metrics import ( "bufio" "bytes" + "fmt" "net" "net/url" "strings" @@ -44,15 +45,17 @@ func TestStatsd_PushFullQueue(t *testing.T) { // to correct it used the 8125 port which is a standard udp port and also added container creation in workflow // but on above changes showed address already in use. func TestStatsd_Conn(t *testing.T) { - addr := "127.0.0.1:8125" + addr := "127.0.0.1:7524" done := make(chan bool) go func() { - list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 8125}) + list, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 7524}) if err != nil { panic(err) } defer list.Close() + fmt.Println("UDP server listening on", list.LocalAddr()) + buf := make([]byte, 1500) n, err := list.Read(buf) if err != nil { @@ -137,7 +140,7 @@ func TestStatsd_Conn(t *testing.T) { select { case <-done: s.Shutdown() - case <-time.After(3 * time.Second): + case <-time.After(5 * time.Second): t.Fatalf("timeout") } } @@ -151,13 +154,13 @@ func TestNewStatsdSinkFromURL(t *testing.T) { }{ { desc: "address is populated", - input: "statsd://statsd.service.consul", - expectAddr: "statsd.service.consul", + input: "statsd://127.0.0.1:8125", + expectAddr: "127.0.0.1:8125", }, { desc: "address includes port", - input: "statsd://statsd.service.consul:8125", - expectAddr: "statsd.service.consul:8125", + input: "statsd://127.0.0.1:8125", + expectAddr: "127.0.0.1:8125", }, } { t.Run(tc.desc, func(t *testing.T) { diff --git a/statsite_test.go b/statsite_test.go index 349f407..6d66fd6 100644 --- a/statsite_test.go +++ b/statsite_test.go @@ -43,7 +43,7 @@ func TestStatsite_PushFullQueue(t *testing.T) { // to correct it used the 8126 port and also added container creation in workflow // but on above changes showed invalid address or nil pointer reference func TestStatsite_Conn(t *testing.T) { - addr := "localhost:8126" + addr := "127.0.0.1:7523" ln, _ := net.Listen("tcp", addr) @@ -133,7 +133,7 @@ func TestStatsite_Conn(t *testing.T) { select { case <-done: s.Shutdown() - case <-time.After(3 * time.Second): + case <-time.After(5 * time.Second): t.Fatalf("timeout") } } @@ -147,13 +147,13 @@ func TestNewStatsiteSinkFromURL(t *testing.T) { }{ { desc: "address is populated", - input: "statsd://statsd.service.consul", - expectAddr: "statsd.service.consul", + input: "statsd://127.0.0.1:7523", + expectAddr: "127.0.0.1:7523", }, { desc: "address includes port", - input: "statsd://statsd.service.consul:8125", - expectAddr: "statsd.service.consul:8125", + input: "statsd://127.0.0.1:7523", + expectAddr: "127.0.0.1:7523", }, } { t.Run(tc.desc, func(t *testing.T) {