From 032ec8ae8dab2d632b0aabbdb837320fb3cc6ad6 Mon Sep 17 00:00:00 2001 From: Ying WANG Date: Fri, 28 Mar 2025 19:25:26 +0100 Subject: [PATCH 1/3] update ci pipeline --- .github/workflows/go.yml | 131 ++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 65 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b79d1fa09..391902b14 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,66 +1,67 @@ --- -name: Go -on: - pull_request: - push: - branches: - - main - - "release-*" - -concurrency: - group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} - cancel-in-progress: true - -# Minimal permissions to be inherited by any job that don't declare it's own permissions -permissions: - contents: read - -jobs: - supportedVersions: - name: Fetch supported Go versions - runs-on: ubuntu-latest - outputs: - supported_versions: ${{ steps.matrix.outputs.supported_versions }} - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Read supported_go_versions.txt - id: matrix - run: | - versions=$(cat supported_go_versions.txt) - matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" - echo "supported_versions=$matrix" >> $GITHUB_OUTPUT - - test: - name: Tests - runs-on: ubuntu-latest - needs: supportedVersions - - strategy: - matrix: - go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} - - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v5.3.0 - with: - go-version: ${{ matrix.go_version }} - - - name: Cache Go modules - id: cache - uses: actions/cache@v4 - with: - path: ~/go/pkg/mod - key: v1-go${{ matrix.go_version }} - - - name: Run tests and check license - run: make check_license test - env: - CI: true - - - name: Run style and unused - if: ${{ matrix.go_version == '1.22' }} - run: make style unused + name: Go + on: + pull_request: + push: + branches: + - main + - "release-*" + + concurrency: + group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} + cancel-in-progress: true + + # Minimal permissions to be inherited by any job that don't declare it's own permissions + permissions: + contents: read + + jobs: + supportedVersions: + name: Fetch supported Go versions + runs-on: ubuntu-latest + outputs: + supported_versions: ${{ steps.matrix.outputs.supported_versions }} + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Read supported_go_versions.txt + id: matrix + run: | + versions=$(cat supported_go_versions.txt) + matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" + echo "supported_versions=$matrix" >> $GITHUB_OUTPUT + + test: + name: Tests + runs-on: ubuntu-latest + needs: supportedVersions + + strategy: + matrix: + go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} + + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up Go ${{ matrix.go_version }} + uses: actions/setup-go@v5.3.0 + with: + go-version: ${{ matrix.go_version }} + + - name: Cache Go modules + id: cache + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: v1-go${{ matrix.go_version }} + + - name: Run tests and check license + run: make check_license test + env: + CI: true + + - name: Run style and unused + if: ${{ matrix.go_version == '1.22' }} + run: make style unused + \ No newline at end of file From 282fb531937aad4478c108e89895f41e1a6139b7 Mon Sep 17 00:00:00 2001 From: Ying WANG Date: Fri, 28 Mar 2025 19:30:13 +0100 Subject: [PATCH 2/3] update pipeline --- .github/workflows/go.yml | 147 +++++++++++++++++++++------------------ 1 file changed, 81 insertions(+), 66 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 391902b14..7ccb84011 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,67 +1,82 @@ --- - name: Go - on: - pull_request: - push: - branches: - - main - - "release-*" - - concurrency: - group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} - cancel-in-progress: true - - # Minimal permissions to be inherited by any job that don't declare it's own permissions - permissions: - contents: read - - jobs: - supportedVersions: - name: Fetch supported Go versions - runs-on: ubuntu-latest - outputs: - supported_versions: ${{ steps.matrix.outputs.supported_versions }} - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - name: Read supported_go_versions.txt - id: matrix - run: | - versions=$(cat supported_go_versions.txt) - matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" - echo "supported_versions=$matrix" >> $GITHUB_OUTPUT - - test: - name: Tests - runs-on: ubuntu-latest - needs: supportedVersions - - strategy: - matrix: - go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} - - steps: - - name: Checkout code - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - - - name: Set up Go ${{ matrix.go_version }} - uses: actions/setup-go@v5.3.0 - with: - go-version: ${{ matrix.go_version }} - - - name: Cache Go modules - id: cache - uses: actions/cache@v4 - with: - path: ~/go/pkg/mod - key: v1-go${{ matrix.go_version }} - - - name: Run tests and check license - run: make check_license test - env: - CI: true - - - name: Run style and unused - if: ${{ matrix.go_version == '1.22' }} - run: make style unused - \ No newline at end of file +name: Go +on: + pull_request: + push: + branches: + - main + - "release-*" + +concurrency: + group: ${{ github.workflow }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} + cancel-in-progress: true + +# Minimal permissions to be inherited by any job that don't declare it's own permissions +permissions: + contents: read + +jobs: + supportedVersions: + name: Fetch supported Go versions + runs-on: ubuntu-latest + outputs: + supported_versions: ${{ steps.matrix.outputs.supported_versions }} + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Read supported_go_versions.txt + id: matrix + run: | + versions=$(cat supported_go_versions.txt) + matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" + echo "supported_versions=$matrix" >> $GITHUB_OUTPUT + + test: + name: Tests + strategy: + matrix: + go_version: ${{ fromJSON(needs.supportedVersions.outputs.supported_versions) }} + os: [ubuntu-latest, macos-latest, windows-latest] # Matrix for OS + runs-on: ${{ matrix.os }} + needs: supportedVersions + steps: + - name: Checkout code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + + - name: Set up Go ${{ matrix.go_version }} + uses: actions/setup-go@v5.3.0 + with: + go-version: ${{ matrix.go_version }} + + - name: Cache Go modules + id: cache + uses: actions/cache@v4 + with: + path: ~/go/pkg/mod + key: v1-go${{ matrix.go_version }}-${{ matrix.os }} + + - name: Set environment variables for platform without cgo + run: | + echo "Setting environment variables for ${{ matrix.os }}" + if [[ ${{ matrix.os }} == 'macos-latest' ]]; then + echo "GOOS=darwin" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + elif [[ ${{ matrix.os }} == 'windows-latest' ]]; then + echo "GOOS=windows" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + echo "TMPDIR=C:\\Temp" >> $GITHUB_ENV + elif [[ ${{ matrix.os }} == 'ubuntu-latest' ]]; then + echo "GOOS=linux" >> $GITHUB_ENV + echo "GOARCH=amd64" >> $GITHUB_ENV + fi + shell: bash + + - name: Run tests and check license + run: make check_license test + env: + CI: true + CGO_ENABLED: 1 + + - name: Run style and unused + if: ${{ matrix.go_version == '1.22' }} + run: make style unused From e4f8aa69c4c9b460215f9eedf6e0cf564534c406 Mon Sep 17 00:00:00 2001 From: Ying WANG Date: Fri, 28 Mar 2025 20:14:09 +0100 Subject: [PATCH 3/3] fix windows test --- prometheus/go_collector_test.go | 6 +++++- prometheus/histogram_test.go | 5 +++++ prometheus/process_collector_windows_test.go | 2 -- prometheus/timer_test.go | 5 +++++ 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/prometheus/go_collector_test.go b/prometheus/go_collector_test.go index 47b944db5..7d2bed4d0 100644 --- a/prometheus/go_collector_test.go +++ b/prometheus/go_collector_test.go @@ -102,6 +102,10 @@ func TestGoCollectorGC(t *testing.T) { c.Collect(metricCh) // force GC runtime.GC() + // for windows, wait longer to make sure the garbage collection + if runtime.GOOS == "windows" { + time.Sleep(3 * time.Second) + } <-waitCh c.Collect(metricCh) close(endCollectionCh) @@ -148,7 +152,7 @@ func TestGoCollectorGC(t *testing.T) { if diff := *pb.GetSummary().SampleSum - oldPause; diff <= 0 { t.Errorf("want an increase in pause time, got a change of %f", diff) } - case <-time.After(1 * time.Second): + case <-time.After(4 * time.Second): t.Fatalf("expected collect timed out") } break diff --git a/prometheus/histogram_test.go b/prometheus/histogram_test.go index 1a19df2e2..0420b676f 100644 --- a/prometheus/histogram_test.go +++ b/prometheus/histogram_test.go @@ -55,6 +55,11 @@ func benchmarkHistogramObserve(w int, b *testing.B) { }() } + // Extra delay for Windows to ensure synchronization + if runtime.GOOS == "windows" { + time.Sleep(50 * time.Millisecond) + } + b.StartTimer() g.Done() wg.Wait() diff --git a/prometheus/process_collector_windows_test.go b/prometheus/process_collector_windows_test.go index 670c0fc53..1d590d132 100644 --- a/prometheus/process_collector_windows_test.go +++ b/prometheus/process_collector_windows_test.go @@ -51,14 +51,12 @@ func TestWindowsProcessCollector(t *testing.T) { regexp.MustCompile("\nprocess_cpu_seconds_total [0-9]"), regexp.MustCompile("\nprocess_max_fds [1-9]"), regexp.MustCompile("\nprocess_open_fds [1-9]"), - regexp.MustCompile("\nprocess_virtual_memory_max_bytes (-1|[1-9])"), regexp.MustCompile("\nprocess_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_resident_memory_bytes [1-9]"), regexp.MustCompile("\nprocess_start_time_seconds [0-9.]{10,}"), regexp.MustCompile("\nfoobar_process_cpu_seconds_total [0-9]"), regexp.MustCompile("\nfoobar_process_max_fds [1-9]"), regexp.MustCompile("\nfoobar_process_open_fds [1-9]"), - regexp.MustCompile("\nfoobar_process_virtual_memory_max_bytes (-1|[1-9])"), regexp.MustCompile("\nfoobar_process_virtual_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_resident_memory_bytes [1-9]"), regexp.MustCompile("\nfoobar_process_start_time_seconds [0-9.]{10,}"), diff --git a/prometheus/timer_test.go b/prometheus/timer_test.go index a27912dbe..632bbef25 100644 --- a/prometheus/timer_test.go +++ b/prometheus/timer_test.go @@ -16,6 +16,7 @@ package prometheus import ( "reflect" "testing" + "time" "google.golang.org/protobuf/proto" @@ -33,6 +34,10 @@ func TestTimerObserve(t *testing.T) { hisTimer := NewTimer(his) sumTimer := NewTimer(sum) gaugeTimer := NewTimer(ObserverFunc(gauge.Set)) + + // Allow a little delay before observations to help on Windows. + time.Sleep(time.Millisecond * 10) + defer hisTimer.ObserveDuration() defer sumTimer.ObserveDuration() defer gaugeTimer.ObserveDuration()