github.com/grafana/pyroscope@v1.18.0/pkg/og/ingestion/ingestion.go (about)

     1  package ingestion
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"time"
     7  
     8  	"github.com/grafana/pyroscope/api/model/labelset"
     9  	distributormodel "github.com/grafana/pyroscope/pkg/distributor/model"
    10  
    11  	"github.com/grafana/pyroscope/pkg/og/storage"
    12  	"github.com/grafana/pyroscope/pkg/og/storage/metadata"
    13  )
    14  
    15  type Ingester interface {
    16  	Ingest(context.Context, *IngestInput) error
    17  }
    18  
    19  type IngestInput struct {
    20  	Format   Format
    21  	Profile  RawProfile
    22  	Metadata Metadata
    23  }
    24  
    25  type Format string
    26  
    27  const (
    28  	FormatPprof      Format = "pprof"
    29  	FormatJFR        Format = "jfr"
    30  	FormatTrie       Format = "trie"
    31  	FormatTree       Format = "tree"
    32  	FormatLines      Format = "lines"
    33  	FormatGroups     Format = "groups"
    34  	FormatSpeedscope Format = "speedscope"
    35  )
    36  
    37  type RawProfile interface {
    38  	Parse(context.Context, storage.Putter, storage.MetricsExporter, Metadata) error
    39  }
    40  
    41  type Limits interface {
    42  	MaxProfileSizeBytes(tenantID string) int
    43  }
    44  
    45  type ParseableToPprof interface {
    46  	ParseToPprof(context.Context, Metadata, Limits) (*distributormodel.PushRequest, error)
    47  }
    48  
    49  type Metadata struct {
    50  	StartTime       time.Time
    51  	EndTime         time.Time
    52  	LabelSet        *labelset.LabelSet
    53  	SpyName         string
    54  	SampleRate      uint32
    55  	Units           metadata.Units
    56  	AggregationType metadata.AggregationType
    57  }
    58  
    59  type Error struct{ Err error }
    60  
    61  func (e Error) Error() string { return e.Err.Error() }
    62  
    63  func (e Error) Unwrap() error { return e.Err }
    64  
    65  func IsIngestionError(err error) bool {
    66  	if err == nil {
    67  		return false
    68  	}
    69  	var v Error
    70  	return errors.As(err, &v)
    71  }