Files
Aleksandar Petrov e3f5a65372 Pyroscope: Process and display sampling annotations (#109707)
* pyroscope: process sampling annotations

* Enable annotations in classic explore

* Run prettier

* Revert unneeded change to plugin.json

* Tweak wording in sampling annotation

* Fix test

* Disable annotations by default
2025-08-29 13:14:22 +02:00

43 lines
1.3 KiB
Go

package annotation
import (
"encoding/json"
"fmt"
"time"
"github.com/dustin/go-humanize"
)
type annotationWithThrottlingBody struct {
Body profileThrottledAnnotation `json:"body"`
}
type profileThrottledAnnotation struct {
PeriodType string `json:"periodType"`
PeriodLimitMb float64 `json:"periodLimitMb"`
LimitResetTime int64 `json:"limitResetTime"`
SamplingPeriodSec float64 `json:"samplingPeriodSec"`
SamplingRequests int64 `json:"samplingRequests"`
UsageGroup string `json:"usageGroup"`
}
func convertThrottlingAnnotation(raw string, timestamp int64) (*processedProfileAnnotation, error) {
var profileAnnotation annotationWithThrottlingBody
err := json.Unmarshal([]byte(raw), &profileAnnotation)
if err != nil {
return nil, fmt.Errorf("error parsing annotation data: %w", err)
}
throttlingInfo := profileAnnotation.Body
limit := humanize.IBytes(uint64(throttlingInfo.PeriodLimitMb * 1024 * 1024))
id := fmt.Sprintf("%s-%s-%d", throttlingInfo.PeriodType, limit, throttlingInfo.LimitResetTime)
return &processedProfileAnnotation{
id: id,
text: fmt.Sprintf("Ingestion limit (%s/%s) reached", limit, throttlingInfo.PeriodType),
time: timestamp,
timeEnd: throttlingInfo.LimitResetTime * 1000,
isRegion: throttlingInfo.LimitResetTime < time.Now().Unix(),
}, nil
}