[bug][pyroscope] Submitting cpu profiles to `/pyroscope/ingest` results in sample type "samples" instead of "nanoseconds"
- Dominant language
- Go
- Stars
- 11.7k
- Forks
- 802
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 80
Description
#### Describe the bug
CPU profiles should generally be shown in "nanoseconds", or at least a time unit per convention. Instead, they are shown as generic "samples", and not scaled to period length.
#### To Reproduce
Use latest weekly build [weekly-f8-1e364093](https://hub.docker.com/layers/grafana/phlare/weekly-f8-1e364093/images/sha256-b8c99494fa8fe73d9499bacd4288cee4583e11be765beafc842b5761702256fc?context=explore) which implements `/pyroscope/ingest`
I wrote is a simple server HTTP server used to intercept the pyroscope payload and save it for analysis:
```
package main
import (
"fmt"
"io"
"os"
"log"
"net/http"
)
var n = 0
func main() {
// Set routing rules
http.HandleFunc("/", Tmp)
//Use the default DefaultServeMux.
err := http.ListenAndServe(":4040", nil)
if err != nil {
log.Fatal(err)
}
}
func Tmp(w http.ResponseWriter, r *http.Request) {
fmt.Printf("request %d %+v\n", n, r)
f, _ := os.Create(fmt.Sprintf("profile%d.pb.gz", n))
defer f.Close()
io.Copy(f, r.Body)
defer r.Body.Close()
n++
}
```
Next we'll use the pyroscope simple ruby app:
https://github.com/grafana/pyroscope/tree/main/examples/ruby/simple
We'll override the server address to point to the interceptor server.
Here is one such captured profile:
[foo.pb.gz](https://github.com/grafana/phlare/files/11165596/foo.pb.gz)
We can see a breakdown of the tags in the profile:
```
go tool pprof -tags ../foo.pb.gz
Main binary filename not available.
function: Total 619.0
485.0 (78.35%): slow
134.0 (21.65%): fast
hostname: Total 619.0
619.0 ( 100%): test
region: Total 619.0
619.0 ( 100%): us-east
```
We'll submit this along to Phlare as so:
```
curl --data-binary @./foo.pb.gz http://127.0.0.1:4100/pyroscope/ingest\?name\=foo&from\=1680742794\&until\=1680742804\&spyName\=rbspy\&sampleRate\=100\&format\=pprof
```
When we view the resulting profile in the Phlare UI, we get this:

#### Expected behavior
We should expect for the profiles drop-down to be "profile_cpu - cpu", but it is "profile_cpu - samples".
We should expect for the value to be scaled to nanoseconds.
#### Environment
- Infrastructure: Kubernetes
- Deployment tool: jsonnet + custom tooling
#### Additional Context
This appears to not be the desired behaviour, as this conversion is done here:
https://github.com/grafana/phlare/blob/4639eee074662648e4e0c9e311bb0ad9aab516cf/pkg/ingester/pyroscope/ingest_adapter.go#L74-L78
However, the value set at the **profile level** is what is used:
https://github.com/grafana/phlare/blob/4639eee074662648e4e0c9e311bb0ad9aab516cf/pkg/ingester/pyroscope/ingest_adapter.go#L65-L73
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.