From b489fc1664634bd041d77f32f0801cdbdcd74a50 Mon Sep 17 00:00:00 2001 From: Integralist Date: Wed, 14 Feb 2024 17:17:05 +0000 Subject: [PATCH 1/4] fix(compute/build): normalise and bucket heap allocations --- pkg/commands/compute/build.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pkg/commands/compute/build.go b/pkg/commands/compute/build.go index a6b4bedb7..cf8efa3ee 100644 --- a/pkg/commands/compute/build.go +++ b/pkg/commands/compute/build.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "io" + "math" "os" "os/exec" "path/filepath" @@ -327,7 +328,7 @@ func (c *BuildCommand) AnnotateWasmBinaryLong(wasmtools string, args []string, l if metadata.BuildInfo == "enable" { dc.BuildInfo = DataCollectionBuildInfo{ - MemoryHeapAlloc: ms.HeapAlloc, + MemoryHeapAlloc: bucketMB(bytesToMB(ms.HeapAlloc)) + "MB", } } if metadata.MachineInfo == "enable" { @@ -823,6 +824,35 @@ func GetNonIgnoredFiles(base string, ignoredFiles map[string]bool) ([]string, er return files, err } +// bytesToMB converts the runtime.MemStats.HeapAlloc bytes into megabytes. +func bytesToMB(bytes uint64) uint64 { + return uint64(math.Round(float64(bytes) / (1024 * 1024))) +} + +// bucketMB determines a consistent bucket size for heap allocation. +// NOTE: This is to avoid building a package with a fluctuation hashsum. +// e.g. `fastly compute hash-files` should be consistent unless memory increase is significant. +func bucketMB(mb uint64) string { + switch { + case mb < 2: + return "<2" + case mb >= 2 && mb < 5: + return "2-5" + case mb >= 5 && mb < 10: + return "5-10" + case mb >= 10 && mb < 20: + return "10-20" + case mb >= 20 && mb < 30: + return "20-30" + case mb >= 30 && mb < 40: + return "30-40" + case mb >= 40 && mb < 50: + return "40-50" + default: + return ">50" + } +} + // DataCollection represents data annotated onto the Wasm binary. type DataCollection struct { BuildInfo DataCollectionBuildInfo `json:"build_info,omitempty"` @@ -833,7 +863,7 @@ type DataCollection struct { // DataCollectionBuildInfo represents build data annotated onto the Wasm binary. type DataCollectionBuildInfo struct { - MemoryHeapAlloc uint64 `json:"mem_heap_alloc,omitempty"` + MemoryHeapAlloc string `json:"mem_heap_alloc,omitempty"` } // DataCollectionMachineInfo represents machine data annotated onto the Wasm binary. From fbb6282ae5c0d3c7d56ff515c5815d7aae9283db Mon Sep 17 00:00:00 2001 From: Integralist Date: Wed, 14 Feb 2024 17:17:18 +0000 Subject: [PATCH 2/4] ci: bump go version to 1.22.x --- .github/workflows/pr_test.yml | 4 ++-- .github/workflows/tag_release.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 2eda4e6ca..68cecb22d 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -29,7 +29,7 @@ jobs: - name: Install Go uses: actions/setup-go@v4 with: - go-version: 1.21.x + go-version: 1.22.x # NOTE: Manage GitHub Actions cache via https://github.com/fastly/cli/actions/caches # This is useful if you need to clear the cache when a dependency doesn't update correctly. # @@ -87,7 +87,7 @@ jobs: strategy: matrix: tinygo-version: [0.27.0] - go-version: [1.21.x] + go-version: [1.22.x] node-version: [18] platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} diff --git a/.github/workflows/tag_release.yml b/.github/workflows/tag_release.yml index c9a8b98f1..b4cc32166 100644 --- a/.github/workflows/tag_release.yml +++ b/.github/workflows/tag_release.yml @@ -15,7 +15,7 @@ jobs: - name: "Install Go" uses: actions/setup-go@v4 with: - go-version: '1.21.x' + go-version: '1.22.x' - name: "Set GOHOSTOS and GOHOSTARCH" run: echo "GOHOSTOS=$(go env GOHOSTOS)" >> $GITHUB_ENV && echo "GOHOSTARCH=$(go env GOHOSTARCH)" >> $GITHUB_ENV - name: "Install Rust" From 9b7423aefb20dd99af9c6c9e0a4e4d115ebf4183 Mon Sep 17 00:00:00 2001 From: Integralist Date: Wed, 14 Feb 2024 17:36:47 +0000 Subject: [PATCH 3/4] ci: disable staticcheck until it's fixed --- .github/workflows/pr_test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 68cecb22d..ac4028d3f 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -76,9 +76,11 @@ jobs: - name: "Run revive" run: make revive shell: bash - - name: "Static analysis check" - run: make staticcheck - shell: bash + # FIXME: Put back staticcheck once it fixes https://github.com/dominikh/go-tools/issues/1496 + # + # - name: "Static analysis check" + # run: make staticcheck + # shell: bash - name: "Security audit" run: make gosec shell: bash From 8babba830732640f62b6500a7fcffa1bfda2d67c Mon Sep 17 00:00:00 2001 From: Mark McDonnell Date: Wed, 14 Feb 2024 17:42:10 +0000 Subject: [PATCH 4/4] doc(compute/build): typo Co-authored-by: Cameron Walters (cee-dub) --- pkg/commands/compute/build.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/compute/build.go b/pkg/commands/compute/build.go index cf8efa3ee..84abad5fd 100644 --- a/pkg/commands/compute/build.go +++ b/pkg/commands/compute/build.go @@ -830,7 +830,7 @@ func bytesToMB(bytes uint64) uint64 { } // bucketMB determines a consistent bucket size for heap allocation. -// NOTE: This is to avoid building a package with a fluctuation hashsum. +// NOTE: This is to avoid building a package with a fluctuating hashsum. // e.g. `fastly compute hash-files` should be consistent unless memory increase is significant. func bucketMB(mb uint64) string { switch {