mirror of
https://github.com/prymitive/karma
synced 2026-08-17 11:27:01 +00:00
feat(test): report more metrics when running go benchmarks
This commit is contained in:
committed by
Łukasz Mierzwa
parent
9b0e92fb8f
commit
9563b9119d
+30
-1
@@ -68,7 +68,36 @@ jobs:
|
||||
script:
|
||||
- ./scripts/gist-get.py 6a1f1aa15a7a308dac7ea2726021836c ui
|
||||
- make -C ui build/stats.json
|
||||
- ./scripts/cra-bundle-stats-diff.py ui/stats.json ui/build/stats.json
|
||||
- ./scripts/cra-bundle-stats-diff.py ui/stats.json ui/build/stats.json | tee diff.html
|
||||
- ./scripts/pr-comment.py "Webpack bundle size diff" diff.html html
|
||||
|
||||
- stage: Stats
|
||||
name: Benchmark Go code snapshot
|
||||
if: repo = prymitive/karma AND type = push AND branch = master
|
||||
<<: *DEFAULTS_GO
|
||||
env:
|
||||
# GITHUB_TOKEN for CI Bundle size diff comments and gist uploads
|
||||
- secure: "Or5fiXZfgIsXvzoOdEprRwJ0uwUjMvxGHE3LG+h3OsIBO6WA8vgOqVOjqVHV2dgC9cSjm5A7MX52S7cDqfkQDkgnVHpVxRwDC9n9O4vnaFdCZ4nC+d18z8dikbiwgdeWQ+Wi6RhZENye1Lu5sBaAJ09wYgx9lNdEVpRaTUvUw6grSlESJZSXoxfxWWpmTyx+yPH4sxuWjZ7gCspDX9s9k4fjpY4LkhQQwLlk8wPc2hfDg48e+K1OR6sYB8uRS33Xc4fQtzElzazmaZ0fn77h5ysDgC1g/ko+E2j8HHMbZvFpzYpm1bCpIv1G/0A2ItH7gT3HsuwkDvfH/it56JTCbBWJJ+hTDeswCQNu0h797QM6jv0o5wgKpHR1t+AeM9vDe4Ds0pAXouJz0LJewNOdNvi5O1BZA9OooKc34hwTJs/zj5NwiZuOyPSMhDBGa++Vhsr9K3rPD9+97M2hac6NO6TBVWZjvqJilmkjJs+bKrl//ClBvdhDGkJNDbB+2emdD1/wzpPVJPp3IRhzeEF89IVE58qE+OQnIwtbEZ2W1ct6Ep7ZJdrXWc/VBdJB1ELfUtNmkvWFZD5IJfnb/Z5MS6iespXlV5alPQ7eZ2jNl3tn7uDaCStuQN1tO2wthNnsSU/OkfFRch/Ks3gYC5+v7n8aJMkTYFmHr4Y/xlXBsrA="
|
||||
before_script:
|
||||
- travis_retry make mock-assets
|
||||
script:
|
||||
- make benchmark-go | tee benchmark.txt
|
||||
- ./scripts/gist-upload.py 15db36b1bd11f22645ddf80c078ad9e8 benchmark.txt
|
||||
|
||||
- stage: Stats
|
||||
name: Benchmark Go code compare
|
||||
if: (repo = prymitive/karma AND type = pull_request)
|
||||
<<: *DEFAULTS_GO
|
||||
env:
|
||||
# GITHUB_TOKEN for CI Bundle size diff comments and gist uploads
|
||||
- secure: "Or5fiXZfgIsXvzoOdEprRwJ0uwUjMvxGHE3LG+h3OsIBO6WA8vgOqVOjqVHV2dgC9cSjm5A7MX52S7cDqfkQDkgnVHpVxRwDC9n9O4vnaFdCZ4nC+d18z8dikbiwgdeWQ+Wi6RhZENye1Lu5sBaAJ09wYgx9lNdEVpRaTUvUw6grSlESJZSXoxfxWWpmTyx+yPH4sxuWjZ7gCspDX9s9k4fjpY4LkhQQwLlk8wPc2hfDg48e+K1OR6sYB8uRS33Xc4fQtzElzazmaZ0fn77h5ysDgC1g/ko+E2j8HHMbZvFpzYpm1bCpIv1G/0A2ItH7gT3HsuwkDvfH/it56JTCbBWJJ+hTDeswCQNu0h797QM6jv0o5wgKpHR1t+AeM9vDe4Ds0pAXouJz0LJewNOdNvi5O1BZA9OooKc34hwTJs/zj5NwiZuOyPSMhDBGa++Vhsr9K3rPD9+97M2hac6NO6TBVWZjvqJilmkjJs+bKrl//ClBvdhDGkJNDbB+2emdD1/wzpPVJPp3IRhzeEF89IVE58qE+OQnIwtbEZ2W1ct6Ep7ZJdrXWc/VBdJB1ELfUtNmkvWFZD5IJfnb/Z5MS6iespXlV5alPQ7eZ2jNl3tn7uDaCStuQN1tO2wthNnsSU/OkfFRch/Ks3gYC5+v7n8aJMkTYFmHr4Y/xlXBsrA="
|
||||
before_script:
|
||||
- travis_retry make mock-assets
|
||||
script:
|
||||
- ./scripts/gist-get.py 15db36b1bd11f22645ddf80c078ad9e8 .
|
||||
- make benchmark-go | tee new.txt
|
||||
- make benchmark-compare-go | tee benchstat.txt
|
||||
- ./scripts/pr-comment.py "Go benchmark diff" benchstat.txt noformat
|
||||
|
||||
- stage: Test
|
||||
name: Test Go code
|
||||
|
||||
+119
-34
@@ -1,25 +1,45 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http/httptest"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/prymitive/karma/internal/mock"
|
||||
)
|
||||
|
||||
func reportMemoryMetrics(b *testing.B) {
|
||||
var m runtime.MemStats
|
||||
|
||||
runtime.GC()
|
||||
runtime.ReadMemStats(&m)
|
||||
|
||||
b.ReportMetric(float64(m.Alloc), "B/alloc")
|
||||
}
|
||||
|
||||
func BenchmarkCompress(b *testing.B) {
|
||||
data, err := ioutil.ReadFile("./tests/compress/alerts.json")
|
||||
if err != nil {
|
||||
b.Errorf("Failed to read data: %s", err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
compressed, err := compressResponse(data)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to compress data: %s", err.Error())
|
||||
b.Run("Run", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
compressed, err := compressResponse(data)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to compress data: %s", err.Error())
|
||||
}
|
||||
|
||||
b.StopTimer()
|
||||
reportMemoryMetrics(b)
|
||||
|
||||
ratio := float64(len(compressed)) / float64(len(data))
|
||||
b.ReportMetric(ratio, "%/compression")
|
||||
b.StartTimer()
|
||||
}
|
||||
if len(compressed) == 0 {
|
||||
b.Errorf("Got zero bytes compress data")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDecompress(b *testing.B) {
|
||||
@@ -33,15 +53,18 @@ func BenchmarkDecompress(b *testing.B) {
|
||||
b.Errorf("Failed to compress data: %s", err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
decompressed, err := decompressCachedResponse(compressed)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to decompress data: %s", err.Error())
|
||||
b.Run("Run", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_, err := decompressCachedResponse(compressed)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to decompress data: %s", err.Error())
|
||||
}
|
||||
|
||||
b.StopTimer()
|
||||
reportMemoryMetrics(b)
|
||||
b.StartTimer()
|
||||
}
|
||||
if len(decompressed) != len(data) {
|
||||
b.Errorf("Got %d decompressed bytes, input was %d", len(decompressed), len(data))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkCompressionAndDecompression(b *testing.B) {
|
||||
@@ -50,26 +73,88 @@ func BenchmarkCompressionAndDecompression(b *testing.B) {
|
||||
b.Errorf("Failed to read data: %s", err.Error())
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
compressed, err := compressResponse(data)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to compress data: %s", err.Error())
|
||||
}
|
||||
if len(compressed) == 0 {
|
||||
b.Errorf("Got zero bytes compress data")
|
||||
}
|
||||
b.Run("Run", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
compressed, err := compressResponse(data)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to compress data: %s", err.Error())
|
||||
}
|
||||
|
||||
decompressed, err := decompressCachedResponse(compressed)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to decompress data: %s", err.Error())
|
||||
}
|
||||
if len(decompressed) != len(data) {
|
||||
b.Errorf("Got %d decompressed bytes, input was %d", len(decompressed), len(data))
|
||||
}
|
||||
_, err = decompressCachedResponse(compressed)
|
||||
if err != nil {
|
||||
b.Errorf("Failed to decompress data: %s", err.Error())
|
||||
}
|
||||
|
||||
if i == 0 {
|
||||
ratio := float64(len(compressed)) / float64(len(data))
|
||||
b.Logf("Compression ratio: %.2f", ratio)
|
||||
b.StopTimer()
|
||||
reportMemoryMetrics(b)
|
||||
b.StartTimer()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkPullAlerts(b *testing.B) {
|
||||
mockConfig()
|
||||
for _, version := range mock.ListAllMocks() {
|
||||
b.Run(version, func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
mockAlerts(version)
|
||||
|
||||
b.StopTimer()
|
||||
reportMemoryMetrics(b)
|
||||
b.StartTimer()
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAlertsAPIMisses(b *testing.B) {
|
||||
mockConfig()
|
||||
for _, version := range mock.ListAllMocks() {
|
||||
mockAlerts(version)
|
||||
r := ginTestEngine()
|
||||
b.Run(version, func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
uri := fmt.Sprintf("/alerts.json?q=&_=%d", i)
|
||||
req := httptest.NewRequest("GET", uri, nil)
|
||||
resp := httptest.NewRecorder()
|
||||
b.StartTimer()
|
||||
r.ServeHTTP(resp, req)
|
||||
|
||||
b.StopTimer()
|
||||
reportMemoryMetrics(b)
|
||||
apiCache.Flush()
|
||||
b.StartTimer()
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkAlertsAPIHits(b *testing.B) {
|
||||
mockConfig()
|
||||
for _, version := range mock.ListAllMocks() {
|
||||
mockAlerts(version)
|
||||
r := ginTestEngine()
|
||||
|
||||
req := httptest.NewRequest("GET", "/alerts.json?q=", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
r.ServeHTTP(resp, req)
|
||||
|
||||
b.Run(version, func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
req := httptest.NewRequest("GET", "/alerts.json?q=", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
b.StartTimer()
|
||||
r.ServeHTTP(resp, req)
|
||||
|
||||
b.StopTimer()
|
||||
reportMemoryMetrics(b)
|
||||
b.StartTimer()
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +112,11 @@ func mockAlerts(version string) {
|
||||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
apiCache = cache.New(cache.NoExpiration, 10*time.Second)
|
||||
if apiCache == nil {
|
||||
apiCache = cache.New(cache.NoExpiration, time.Hour)
|
||||
} else {
|
||||
apiCache.Flush()
|
||||
}
|
||||
|
||||
mock.RegisterURL("http://localhost/metrics", version, "metrics")
|
||||
mock.RegisterURL("http://localhost/api/v2/status", version, "api/v2/status")
|
||||
|
||||
@@ -38,6 +38,7 @@ require (
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/spf13/viper v1.6.2 // indirect
|
||||
github.com/xlab/handysort v0.0.0-20150421192137-fb3537ed64a1 // indirect
|
||||
golang.org/x/perf v0.0.0-20200318175901-9c9101da8316
|
||||
gopkg.in/go-playground/colors.v1 v1.2.0
|
||||
gopkg.in/yaml.v2 v2.3.0
|
||||
vbom.ml/util v0.0.0-20180919145318-efcd4e0f9787
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
cloud.google.com/go v0.0.0-20170206221025-ce650573d812/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
@@ -5,6 +6,7 @@ github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586 h1:vDSj8WQZo
|
||||
github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586/go.mod h1:kMi/fSDAgvjo9TYfYwYeQ2vkyj+VTR/tB6u/Tjh39t0=
|
||||
github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157 h1:hY39LwQHh+1kaovmIjOrlqnXNX6tygSRfLkkK33IkZU=
|
||||
github.com/Djarvur/go-err113 v0.0.0-20200410182137-af658d038157/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs=
|
||||
github.com/GoogleCloudPlatform/cloudsql-proxy v0.0.0-20190129172621-c8b1d7a94ddf/go.mod h1:aJ4qN3TfrelA6NZ6AXsXRfmEVaYin3EDbSPJrKS8OXo=
|
||||
github.com/Masterminds/semver/v3 v3.1.0 h1:Y2lUDsFKVRSYGojLJ1yLxSXdMmMYTYls0rCvoqmMUQk=
|
||||
github.com/Masterminds/semver/v3 v3.1.0/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
@@ -16,6 +18,8 @@ github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
|
||||
github.com/aclements/go-gg v0.0.0-20170118225347-6dbb4e4fefb0/go.mod h1:55qNq4vcpkIuHowELi5C8e+1yUHtoLoOUR9QU5j7Tes=
|
||||
github.com/aclements/go-moremath v0.0.0-20161014184102-0ff62e0875ff/go.mod h1:idZL3yvz4kzx1dsBOAC+oYv6L92P1oFEhUXUB1A/lwQ=
|
||||
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
|
||||
@@ -178,6 +182,7 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+
|
||||
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
|
||||
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
|
||||
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
|
||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-toolsmith/astcast v1.0.0 h1:JojxlmI6STnFVG9yOImLeGREv8W2ocNUM+iOhR6jE7g=
|
||||
@@ -254,6 +259,11 @@ github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0 h1:HVfrLniijszjS1
|
||||
github.com/golangci/revgrep v0.0.0-20180526074752-d9c87f5ffaf0/go.mod h1:qOQCunEYvmd/TLamH+7LlVccLvUH5kZNhbCgTHoBbp4=
|
||||
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4 h1:zwtduBRr5SSWhqsYNgcuWO2kFlpdOZbP0+yRjmvPGys=
|
||||
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg8RkN3rCIMLGE9CyYmU9pY2Jer6DgANEnZ/L/cQ=
|
||||
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc=
|
||||
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg=
|
||||
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks=
|
||||
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A=
|
||||
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
@@ -272,6 +282,7 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
|
||||
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go v0.0.0-20161107002406-da06d194a00e/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
|
||||
github.com/gookit/color v1.2.4/go.mod h1:AhIE+pS6D4Ql0SQWbBeXPHw7gY0/sjHoA4s/n1KB7xg=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
@@ -360,6 +371,7 @@ github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mattn/go-sqlite3 v0.0.0-20161215041557-2d44decb4941/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
|
||||
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
@@ -564,11 +576,15 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
|
||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/perf v0.0.0-20200318175901-9c9101da8316 h1:4kYIkqY0RFzbXzKPeT7sNOlcJK5JY1HSnMBOUlzXlZU=
|
||||
golang.org/x/perf v0.0.0-20200318175901-9c9101da8316/go.mod h1:FrqOtQDO3iMDVUtw5nNTDFpR1HUCGh00M3kj2wiSzLQ=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -630,10 +646,12 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.0.0-20170206182103-3d017632ea10/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/grpc v0.0.0-20170208002647-2a6bf6142e96/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
|
||||
@@ -13,18 +13,24 @@ func BenchmarkDedupAlerts(b *testing.B) {
|
||||
if err := pullAlerts(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for n := 0; n < b.N; n++ {
|
||||
alertmanager.DedupAlerts()
|
||||
}
|
||||
|
||||
b.Run("Run", func(b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
alertmanager.DedupAlerts()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDedupAutocomplete(b *testing.B) {
|
||||
if err := pullAlerts(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for n := 0; n < b.N; n++ {
|
||||
alertmanager.DedupAutocomplete()
|
||||
}
|
||||
|
||||
b.Run("Run", func(b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
alertmanager.DedupAutocomplete()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkDedupColors(b *testing.B) {
|
||||
@@ -38,7 +44,10 @@ func BenchmarkDedupColors(b *testing.B) {
|
||||
if err := pullAlerts(); err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
for n := 0; n < b.N; n++ {
|
||||
alertmanager.DedupColors()
|
||||
}
|
||||
|
||||
b.Run("Run", func(b *testing.B) {
|
||||
for n := 0; n < b.N; n++ {
|
||||
alertmanager.DedupColors()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package models_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/prymitive/karma/internal/models"
|
||||
)
|
||||
@@ -53,56 +52,3 @@ func TestAlertState(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkLabelsFingerprint(b *testing.B) {
|
||||
alert := models.Alert{
|
||||
Labels: map[string]string{
|
||||
"foo1": "bar1",
|
||||
"foo1bar1": "545jjjssd",
|
||||
"foo1xxxx": "bdjjs88ff",
|
||||
"agdfdfd": "bar1",
|
||||
"fossdsf3o1": "bar11111",
|
||||
"fdfdgfdgoo1": "bar1",
|
||||
},
|
||||
}
|
||||
for n := 0; n < b.N; n++ {
|
||||
alert.LabelsFingerprint()
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkLabelsContent(b *testing.B) {
|
||||
alert := models.Alert{
|
||||
Annotations: models.Annotations{
|
||||
models.Annotation{
|
||||
Name: "foo",
|
||||
Value: "bar",
|
||||
Visible: true,
|
||||
},
|
||||
models.Annotation{
|
||||
Name: "abc",
|
||||
Value: "Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...",
|
||||
Visible: true,
|
||||
},
|
||||
},
|
||||
Labels: map[string]string{
|
||||
"foo1": "bar1",
|
||||
"foo1bar1": "545jjjssd",
|
||||
"foo1xxxx": "bdjjs88ff",
|
||||
"agdfdfd": "bar1",
|
||||
"fossdsf3o1": "bar11111",
|
||||
"fdfdgfdgoo1": "bar1",
|
||||
},
|
||||
State: models.AlertStateActive,
|
||||
StartsAt: time.Date(2015, time.March, 10, 0, 0, 0, 0, time.UTC),
|
||||
Alertmanager: []models.AlertmanagerInstance{
|
||||
{
|
||||
Name: "default",
|
||||
State: models.AlertStateActive,
|
||||
},
|
||||
},
|
||||
}
|
||||
alert.UpdateFingerprints()
|
||||
for n := 0; n < b.N; n++ {
|
||||
alert.LabelsFingerprint()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,12 +121,3 @@ func TestStringSliceToSHA1(t *testing.T) {
|
||||
t.Errorf("StringSliceToSHA1() returned empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkStringSliceToSHA1(b *testing.B) {
|
||||
for _, stringSliceTest := range stringSliceTests {
|
||||
_, err := slices.StringSliceToSHA1(stringSliceTest.array)
|
||||
if err != nil {
|
||||
b.Errorf("StringSliceToSHA1() returned error: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
-3
@@ -1,7 +1,7 @@
|
||||
include make/vars.mk
|
||||
|
||||
ENV := GO111MODULE=on
|
||||
GO := $(ENV) go
|
||||
ENV := GO111MODULE=on
|
||||
GO := $(ENV) go
|
||||
GOBIN := $(shell go env GOBIN)
|
||||
ifeq ($(GOBIN),)
|
||||
GOBIN = $(shell go env GOPATH)/bin
|
||||
@@ -28,9 +28,15 @@ test-go:
|
||||
$(ENV) ./scripts/test-main.sh
|
||||
$(ENV) ./scripts/gocovmerge.sh
|
||||
|
||||
GOBENCHMARKCOUNT := 20
|
||||
.PHONY: benchmark-go
|
||||
benchmark-go:
|
||||
$(GO) test -run=NONE -bench=. -benchmem ./...
|
||||
@env GOMAXPROCS=2 $(GO) test -count=$(GOBENCHMARKCOUNT) -run=NONE -bench=. -benchmem ./...
|
||||
|
||||
$(GOBIN)/benchstat: go.mod go.sum
|
||||
@$(GO) install golang.org/x/perf/cmd/benchstat
|
||||
benchmark-compare-go: $(GOBIN)/benchstat
|
||||
@$(GOBIN)/benchstat benchmark.txt new.txt
|
||||
|
||||
$(GOBIN)/golangci-lint: go.mod go.sum
|
||||
$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||
|
||||
@@ -5,7 +5,6 @@ from collections import namedtuple
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib2
|
||||
|
||||
|
||||
Bundle = namedtuple('Bundle' , 'seq ext bundleName totalBytes files')
|
||||
@@ -160,26 +159,12 @@ def summarize(diffs):
|
||||
sign=sign, totalDiff=humanize(totalDiff))
|
||||
|
||||
|
||||
def postComment(diffs, pr, token, owner='prymitive', repo='karma'):
|
||||
api = 'api.github.com'
|
||||
uri = 'https://{api}/repos/{owner}/{repo}/issues/{pr}/comments'.format(
|
||||
api=api, owner=owner, repo=repo, pr=pr)
|
||||
|
||||
def printDiff(diffs):
|
||||
rows = []
|
||||
for diff in diffs:
|
||||
rows.append(printBundleDiff(diff))
|
||||
summary = summarize(diffs)
|
||||
data = '*Webpack bundle size diff*\n{summary}\n{rows}'.format(
|
||||
summary=summary, rows='\n'.join(rows))
|
||||
encoded = json.dumps({'body': data})
|
||||
|
||||
req = urllib2.Request(uri)
|
||||
req.add_header('Authorization', 'token %s' % token)
|
||||
req.add_header("Content-Type", "application/json")
|
||||
try:
|
||||
response = urllib2.urlopen(req, encoded)
|
||||
except Exception as e:
|
||||
print("Request to '%s' failed: %s" % (uri, e))
|
||||
print('{summary}\n{rows}'.format(summary=summary, rows='\n'.join(rows)))
|
||||
|
||||
|
||||
def diffBundles(a, b):
|
||||
@@ -231,24 +216,12 @@ if __name__ == '__main__':
|
||||
print('Usage: PATH1 PATH2')
|
||||
sys.exit(1)
|
||||
|
||||
token = os.getenv('GITHUB_TOKEN')
|
||||
pr = os.getenv('TRAVIS_PULL_REQUEST')
|
||||
bundleA = readBundle(sys.argv[1])
|
||||
bundleB = readBundle(sys.argv[2])
|
||||
|
||||
if not token:
|
||||
print('GITHUB_TOKEN env variable is missing')
|
||||
sys.exit(1)
|
||||
if not pr:
|
||||
print('TRAVIS_PULL_REQUEST env variable is missing')
|
||||
sys.exit(1)
|
||||
if not bundleA or not bundleB:
|
||||
print('Usage: PATH1 PATH2')
|
||||
sys.exit(1)
|
||||
|
||||
diffs = diffBundles(bundleA, bundleB)
|
||||
if diffs:
|
||||
print('Found diffs, posting to GitHub')
|
||||
postComment(diffs, pr, token)
|
||||
else:
|
||||
print('No diff found')
|
||||
printDiff(diffs)
|
||||
|
||||
Executable
+92
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib2
|
||||
|
||||
|
||||
def apiRequest(token, path, owner='prymitive', repo='karma'):
|
||||
api = 'api.github.com'
|
||||
uri = 'https://{api}/repos/{owner}/{repo}{path}'.format(
|
||||
api=api, owner=owner, repo=repo, pr=pr, path=path)
|
||||
|
||||
req = urllib2.Request(uri)
|
||||
req.add_header('Authorization', 'token %s' % token)
|
||||
req.add_header("Content-Type", "application/json")
|
||||
|
||||
return req
|
||||
|
||||
def findComment(pr, token, commentName):
|
||||
req = apiRequest(token, "/issues/{pr}/comments".format(pr=pr))
|
||||
try:
|
||||
response = urllib2.urlopen(req)
|
||||
except Exception as e:
|
||||
print("Request to '%s' failed: %s" % (uri, e))
|
||||
else:
|
||||
comments = json.load(response)
|
||||
for comment in comments:
|
||||
if comment['body'].startswith(commentName):
|
||||
return comment['id']
|
||||
|
||||
|
||||
def formatComment(commentName, comment):
|
||||
return '{name}\n\n{body}'.format(name=commentName, body=comment)
|
||||
|
||||
|
||||
def editComment(pr, token, commentID, commentName, comment):
|
||||
req = apiRequest(token, "/issues/comments/{id}".format(id=commentID))
|
||||
req.get_method = lambda: 'PATCH'
|
||||
print('Editing a comment on {uri}'.format(uri=req.get_full_url()))
|
||||
|
||||
try:
|
||||
response = urllib2.urlopen(
|
||||
req, json.dumps({"body": formatComment(commentName, comment)}))
|
||||
except Exception as e:
|
||||
print("Failed to updated comment '%s': %s" % (req.get_full_url(), e))
|
||||
|
||||
|
||||
def postComment(pr, token, commentName, comment):
|
||||
req = apiRequest(token, "/issues/{pr}/comments".format(pr=pr))
|
||||
print('Posting new comment to {uri}'.format(uri=req.get_full_url()))
|
||||
|
||||
try:
|
||||
response = urllib2.urlopen(
|
||||
req, json.dumps({"body": formatComment(commentName, comment)}))
|
||||
except Exception as e:
|
||||
print("Failed to create a comment '%s': %s" % (req.get_full_url(), e))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 4:
|
||||
print('Usage: NAME PATH FORMAT')
|
||||
sys.exit(1)
|
||||
|
||||
token = os.getenv('GITHUB_TOKEN')
|
||||
pr = os.getenv('TRAVIS_PULL_REQUEST')
|
||||
commentName = sys.argv[1]
|
||||
commentFile = sys.argv[2]
|
||||
format = sys.argv[3]
|
||||
|
||||
if not token:
|
||||
print('GITHUB_TOKEN env variable is missing')
|
||||
sys.exit(1)
|
||||
if not pr:
|
||||
print('TRAVIS_PULL_REQUEST env variable is missing')
|
||||
sys.exit(1)
|
||||
if not commentName or not commentFile or not format:
|
||||
print('Usage: NAME PATH FORMAT')
|
||||
sys.exit(1)
|
||||
|
||||
with open(commentFile) as f:
|
||||
comment = f.read()
|
||||
|
||||
if format == 'noformat':
|
||||
comment = '```\n{body}\n```'.format(body=comment)
|
||||
|
||||
commentID = findComment(pr, token, commentName)
|
||||
if commentID is None:
|
||||
postComment(pr, token, commentName, comment)
|
||||
else:
|
||||
editComment(pr, token, commentID, commentName, comment)
|
||||
Reference in New Issue
Block a user