Skip to content

Commit

Permalink
import pyroscope goldga
Browse files Browse the repository at this point in the history
  • Loading branch information
dhanusaputra committed Feb 19, 2022
1 parent 2d5f15c commit 5a8b80c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 39 deletions.
3 changes: 2 additions & 1 deletion benchmark/internal/cireport/metareport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pyroscope-io/goldga"
)

var _ = Describe("metareport", func() {
Expand All @@ -15,7 +16,7 @@ var _ = Describe("metareport", func() {
report, err := mr.Report("Server Benchmark", []string{"execution=5m", "seed=4"})
Expect(err).ToNot(HaveOccurred())

Expect(report).To(BeEquivalentTo("## Server Benchmark\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Value |\n|-------------|------------|\n| `execution` | `5m` |\n| `seed` | `4` |\n</details>\n"))
Expect(report).To(goldga.Match())
})

Context("error conditions", func() {
Expand Down
7 changes: 4 additions & 3 deletions benchmark/internal/cireport/tablereport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/pyroscope-io/goldga"
)

type mockQuerier struct {
Expand Down Expand Up @@ -58,7 +59,7 @@ var _ = Describe("tablereport", func() {
report, err := tr.Report(context.Background(), &qc)

Expect(err).ToNot(HaveOccurred())
Expect(report).To(BeEquivalentTo("## Result\n| | base name | target name | diff | threshold |\n|-------------|------------------------------|----------------------|---------------------|----------------|\n| my name | 1.00 | 1.00 | 0.00 (0.00%) | 5% |\n\n\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Description | Query for base name | Query for target name |\n|----------|-------------|----------------------|----------------------|\n| my name | my description | `query_base` | `query_target` |\n\n\n</details>\n"))
Expect(report).To(goldga.Match())
})
})

Expand All @@ -73,7 +74,7 @@ var _ = Describe("tablereport", func() {
report, err := tr.Report(context.Background(), &qc)

Expect(err).ToNot(HaveOccurred())
Expect(report).To(BeEquivalentTo("## Result\n| | base name | target name | diff | threshold |\n|-------------|------------------------------|----------------------|---------------------|----------------|\n| my name | 0.00 | 2.00 | :green_square: 2.00 (200.00%) | 5% |\n\n\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Description | Query for base name | Query for target name |\n|----------|-------------|----------------------|----------------------|\n| my name | my description | `query_base` | `query_target` |\n\n\n</details>\n"))
Expect(report).To(goldga.Match())
})
})

Expand All @@ -88,7 +89,7 @@ var _ = Describe("tablereport", func() {
report, err := tr.Report(context.Background(), &qc)

Expect(err).ToNot(HaveOccurred())
Expect(report).To(BeEquivalentTo("## Result\n| | base name | target name | diff | threshold |\n|-------------|------------------------------|----------------------|---------------------|----------------|\n| my name | 2.00 | 0.00 | :red_square: -2.00 (-200.00%) | 5% |\n\n\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Description | Query for base name | Query for target name |\n|----------|-------------|----------------------|----------------------|\n| my name | my description | `query_base` | `query_target` |\n\n\n</details>\n"))
Expect(report).To(goldga.Match())
})
})
})
5 changes: 5 additions & 0 deletions benchmark/internal/cireport/testdata/metareport.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generated by goldga. DO NOT EDIT.
[snapshots]
"metareport generates a markdown report correctly" = '''
(string) (len=171) "## Server Benchmark\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Value |\n|-------------|------------|\n| `execution` | `5m` |\n| `seed` | `4` |\n</details>\n"
'''
11 changes: 11 additions & 0 deletions benchmark/internal/cireport/testdata/tablereport.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Generated by goldga. DO NOT EDIT.
[snapshots]
"tablereport diff bigger than threshold should generate a report correctly" = '''
(string) (len=538) "## Result\n| | base name | target name | diff | threshold |\n|-------------|------------------------------|----------------------|---------------------|----------------|\n| my name | 0.00 | 2.00 | :green_square: 2.00 (200.00%) | 5% |\n\n\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Description | Query for base name | Query for target name |\n|----------|-------------|----------------------|----------------------|\n| my name | my description | `query_base` | `query_target` |\n\n\n</details>\n"
'''
"tablereport diff smaller than threshold should generate a report correctly" = '''
(string) (len=538) "## Result\n| | base name | target name | diff | threshold |\n|-------------|------------------------------|----------------------|---------------------|----------------|\n| my name | 2.00 | 0.00 | :red_square: -2.00 (-200.00%) | 5% |\n\n\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Description | Query for base name | Query for target name |\n|----------|-------------|----------------------|----------------------|\n| my name | my description | `query_base` | `query_target` |\n\n\n</details>\n"
'''
"tablereport diff within threshold should generate a report correctly" = '''
(string) (len=521) "## Result\n| | base name | target name | diff | threshold |\n|-------------|------------------------------|----------------------|---------------------|----------------|\n| my name | 1.00 | 1.00 | 0.00 (0.00%) | 5% |\n\n\n\n<details>\n <summary>Details</summary>\n\n\n| Name | Description | Query for base name | Query for target name |\n|----------|-------------|----------------------|----------------------|\n| my name | my description | `query_base` | `query_target` |\n\n\n</details>\n"
'''
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ require (
github.com/prometheus/common v0.32.1
github.com/pyroscope-io/client v0.0.0-20211206204731-3fd0a4b8239c
github.com/pyroscope-io/dotnetdiag v1.2.1
github.com/pyroscope-io/goldga v0.4.2-0.20220218190441-817afcc3a7f1
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rlmcpherson/s3gof3r v0.5.0
github.com/shirou/gopsutil v3.21.4+incompatible
Expand Down
16 changes: 13 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSY
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DataDog/zstd v1.4.1 h1:3oxKN3wbHibqx897utPC2LTQU4J+IHWWJO+glkAkpFM=
github.com/DataDog/zstd v1.4.1/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
Expand All @@ -73,6 +74,8 @@ github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRF
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a h1:E/8AP5dFtMhl5KPJz66Kt9G0n+7Sn41Fy1wv9/jHOrc=
github.com/alecthomas/units v0.0.0-20210927113745-59d0afb8317a/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
Expand Down Expand Up @@ -479,6 +482,8 @@ github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/logrusorgru/aurora/v3 v3.0.0 h1:R6zcoZZbvVcGMvDCKo45A9U/lzYyzl5NfYIvznmDfE4=
github.com/logrusorgru/aurora/v3 v3.0.0/go.mod h1:vsR12bk5grlLvLXAYrBsb5Oc/N+LxAlxggSjiwMnCUc=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand All @@ -501,8 +506,9 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
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-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.10 h1:CoZ3S2P7pvtP45xOtBw+/mDL2z0RKI576gSkzRRpdGg=
Expand Down Expand Up @@ -609,6 +615,8 @@ github.com/pyroscope-io/client v0.0.0-20211206204731-3fd0a4b8239c h1:QVplAdQO7l4
github.com/pyroscope-io/client v0.0.0-20211206204731-3fd0a4b8239c/go.mod h1:zRdQXIGxy0H2QbKEkCmZBR6KOLLIFYLWsdzVI0MRm2E=
github.com/pyroscope-io/dotnetdiag v1.2.1 h1:3XEMrfFJnZ87BiEhozyQKmCUAuMd/Spq7KChPuD2Cf0=
github.com/pyroscope-io/dotnetdiag v1.2.1/go.mod h1:eFUEHCp4eD1TgcXMlJihC+R4MrqGf7nTRdWxNADbDHA=
github.com/pyroscope-io/goldga v0.4.2-0.20220218190441-817afcc3a7f1 h1:T1fDdt3E3UpaGZ7tRF2IYrUFwNyuPlIWGeCOjfINp1s=
github.com/pyroscope-io/goldga v0.4.2-0.20220218190441-817afcc3a7f1/go.mod h1:PbX5bxlj/WxyKIEAxYgNMNWUpXP4rt9GqtjfvTf8m+I=
github.com/pyroscope-io/revive v1.0.6-0.20210330033039-4a71146f9dc1 h1:0v9lBNgdmVtpyyk9PP/DfpJlOHkXriu5YgNlrhQw5YE=
github.com/pyroscope-io/revive v1.0.6-0.20210330033039-4a71146f9dc1/go.mod h1:tSw34BaGZ0iF+oVKDOjq1/LuxGifgW7shaJ6+dBYFXg=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
Expand All @@ -626,8 +634,9 @@ github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shirou/gopsutil v3.21.4+incompatible h1:fuHcTm5mX+wzo542cmYcV9RTGQLbnHLI5SyQ5ryTVck=
github.com/shirou/gopsutil v3.21.4+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
Expand Down Expand Up @@ -946,6 +955,7 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211020174200-9d6173849985 h1:LOlKVhfDyahgmqa97awczplwkjzNaELFg3zRIJ13RYo=
Expand Down
69 changes: 37 additions & 32 deletions pkg/agent/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,45 @@ func (u *upstreamMock) Upload(j *upstream.UploadJob) {

var _ = Describe("agent.Session", func() {
Describe("NewSession", func() {
It("creates a new session and performs chunking", func(done Done) {
u := &upstreamMock{}
uploadRate := 200 * time.Millisecond
s, _ := NewSession(SessionConfig{
Upstream: u,
AppName: "test-app",
ProfilingTypes: []spy.ProfileType{spy.ProfileCPU},
SpyName: "debugspy",
SampleRate: 100,
UploadRate: uploadRate,
Pid: os.Getpid(),
WithSubprocesses: true,
Logger: logrus.StandardLogger(),
})
now := time.Now()
time.Sleep(now.Truncate(uploadRate).Add(uploadRate + 10*time.Millisecond).Sub(now))
err := s.Start()
It("creates a new session and performs chunking", func() {
done := make(chan interface{})
go func() {
defer GinkgoRecover()
u := &upstreamMock{}
uploadRate := 200 * time.Millisecond
s, _ := NewSession(SessionConfig{
Upstream: u,
AppName: "test-app",
ProfilingTypes: []spy.ProfileType{spy.ProfileCPU},
SpyName: "debugspy",
SampleRate: 100,
UploadRate: uploadRate,
Pid: os.Getpid(),
WithSubprocesses: true,
Logger: logrus.StandardLogger(),
})
now := time.Now()
time.Sleep(now.Truncate(uploadRate).Add(uploadRate + 10*time.Millisecond).Sub(now))
err := s.Start()

Expect(err).ToNot(HaveOccurred())
time.Sleep(500 * time.Millisecond)
s.Stop()
Expect(err).ToNot(HaveOccurred())
time.Sleep(500 * time.Millisecond)
s.Stop()

Expect(u.uploads).To(HaveLen(3))
u.uploads[0].Trie.Iterate(func(name []byte, val uint64) {
Expect(val).To(BeNumerically("~", 19, 2))
})
u.uploads[1].Trie.Iterate(func(name []byte, val uint64) {
Expect(val).To(BeNumerically("~", 20, 2))
})
u.uploads[2].Trie.Iterate(func(name []byte, val uint64) {
Expect(val).To(BeNumerically("~", 11, 2))
})
close(done)
Expect(u.uploads[0].Name).To(Equal("test-app.cpu{}"))
Expect(u.uploads).To(HaveLen(3))
u.uploads[0].Trie.Iterate(func(name []byte, val uint64) {
Expect(val).To(BeNumerically("~", 19, 2))
})
u.uploads[1].Trie.Iterate(func(name []byte, val uint64) {
Expect(val).To(BeNumerically("~", 20, 2))
})
u.uploads[2].Trie.Iterate(func(name []byte, val uint64) {
Expect(val).To(BeNumerically("~", 11, 2))
})
close(done)
Expect(u.uploads[0].Name).To(Equal("test-app.cpu{}"))
}()
Eventually(done, 3).Should(BeClosed())
})

When("tags specified", func() {
Expand Down

0 comments on commit 5a8b80c

Please sign in to comment.