Skip to content

Commit

Permalink
test(pyroscope): add simple unscientific benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershafir committed Jan 11, 2024
1 parent dfec83d commit 02ea6cb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
1 change: 1 addition & 0 deletions exporter/clickhouseprofileexporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func initMetrics(meter metric.Meter) error {
if otelcolExporterClickhouseProfileFlushTimeMillis, err = meter.Int64Histogram(
fmt.Sprint(prefix, "flush_time_millis"),
metric.WithDescription("Clickhouse profile exporter flush time in millis"),
metric.WithExplicitBucketBoundaries(0, 5, 10, 20, 50, 100, 200, 500, 1000, 5000),
); err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions receiver/pyroscopereceiver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ func initMetrics(meter metric.Meter) error {
if otelcolReceiverPyroscopeRequestBodyUncompressedSizeBytes, err = meter.Int64Histogram(
fmt.Sprint(prefix, "request_body_uncompressed_size_bytes"),
metric.WithDescription("Pyroscope receiver uncompressed request body size in bytes"),
metric.WithExplicitBucketBoundaries(0, 1024, 4096, 16384, 32768, 65536, 131072, 262144, 524288, 1048576),
); err != nil {
return err
}
if otelcolReceiverPyroscopeParsedBodyUncompressedSizeBytes, err = meter.Int64Histogram(
fmt.Sprint(prefix, "parsed_body_uncompressed_size_bytes"),
metric.WithDescription("Pyroscope receiver uncompressed parsed body size in bytes"),
metric.WithExplicitBucketBoundaries(0, 1024, 4096, 16384, 32768, 65536, 131072, 262144, 524288, 1048576),
); err != nil {
return err
}
if otelcolReceiverPyroscopeHttpResponseTimeMillis, err = meter.Int64Histogram(
fmt.Sprint(prefix, "http_response_time_millis"),
metric.WithDescription("Pyroscope receiver http response time in millis"),
metric.WithExplicitBucketBoundaries(0, 5, 10, 20, 50, 100, 200, 500, 1000, 5000),
); err != nil {
return err
}
Expand Down
45 changes: 45 additions & 0 deletions receiver/pyroscopereceiver/pyroscope_pipeline_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package pyroscopereceiver

import (
"fmt"
"path/filepath"
"testing"
)

type request struct {
urlParams map[string]string
jfr string
}

// Benchmarks a running otelcol pyroscope write pipeline (collector and Clickhouse).
// Adjust collectorAddr to bench a your target if needed.
func BenchmarkPyroscopePipeline(b *testing.B) {
dist := []request{
{
urlParams: map[string]string{
"name": "com.example.App{dc=us-east-1,kubernetes_pod_name=app-abcd1234}",
"from": "1700332322",
"until": "1700332329",
"format": "jfr",
"sampleRate": "100",
},
jfr: filepath.Join("testdata", "cortex-dev-01__kafka-0__cpu__0.jfr"),
},
{
urlParams: map[string]string{
"name": "com.example.App{dc=us-east-1,kubernetes_pod_name=app-abcd1234}",
"from": "1700332322",
"until": "1700332329",
"format": "jfr",
},
jfr: filepath.Join("testdata", "memory_alloc_live_example.jfr"),
},
}
collectorAddr := fmt.Sprintf("http://%s%s", defaultHttpAddr, ingestPath)

b.ResetTimer()
for i, j := 0, 0; i < b.N; i++ {
send(collectorAddr, dist[j].urlParams, dist[j].jfr)
j = (j + 1) % len(dist)
}
}
8 changes: 3 additions & 5 deletions receiver/pyroscopereceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func loadTestData(t *testing.T, filename string) []byte {
func run(t *testing.T, tests []jfrtest, collectorAddr string, sink *consumertest.LogsSink) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.NoError(t, send(t, collectorAddr, tt.urlParams, tt.jfr), "send shouldn't have been failed")
assert.NoError(t, send(collectorAddr, tt.urlParams, tt.jfr), "send shouldn't have been failed")
actual := sink.AllLogs()
assert.NoError(t, plogtest.CompareLogs(tt.expected, actual[0]))
sink.Reset()
Expand All @@ -63,9 +63,7 @@ func startHttpServer(t *testing.T) (string, *consumertest.LogsSink) {
MaxRequestBodySize: defaultMaxRequestBodySize,
},
},
Timeout: defaultTimeout,
RequestBodyUncompressedSizeBytes: defaultRequestBodyUncompressedSizeBytesExpectedValue,
ParsedBodyUncompressedSizeBytes: defaultParsedBodyUncompressedSizeBytesExpectedValue,
Timeout: defaultTimeout,
}
sink := new(consumertest.LogsSink)
set := receivertest.NewNopCreateSettings()
Expand All @@ -79,7 +77,7 @@ func startHttpServer(t *testing.T) (string, *consumertest.LogsSink) {
return addr, sink
}

func send(t *testing.T, addr string, urlParams map[string]string, jfr string) error {
func send(addr string, urlParams map[string]string, jfr string) error {
data, err := os.ReadFile(jfr)
if err != nil {
return err
Expand Down

0 comments on commit 02ea6cb

Please sign in to comment.