github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/ingestion/ingestion.go (about)

     1  package ingestion
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  	"time"
     7  
     8  	"github.com/pyroscope-io/pyroscope/pkg/storage"
     9  	"github.com/pyroscope-io/pyroscope/pkg/storage/metadata"
    10  	"github.com/pyroscope-io/pyroscope/pkg/storage/segment"
    11  )
    12  
    13  type Ingester interface {
    14  	Ingest(context.Context, *IngestInput) error
    15  }
    16  
    17  type IngestInput struct {
    18  	Format   Format
    19  	Profile  RawProfile
    20  	Metadata Metadata
    21  }
    22  
    23  type Format string
    24  
    25  const (
    26  	FormatPprof      Format = "pprof"
    27  	FormatJFR        Format = "jfr"
    28  	FormatTrie       Format = "trie"
    29  	FormatTree       Format = "tree"
    30  	FormatLines      Format = "lines"
    31  	FormatGroups     Format = "groups"
    32  	FormatSpeedscope Format = "speedscope"
    33  )
    34  
    35  type RawProfile interface {
    36  	Parse(context.Context, storage.Putter, storage.MetricsExporter, Metadata) error
    37  	Bytes() ([]byte, error)
    38  	// ContentType denotes Bytes output type. Must be only called after Bytes.
    39  	ContentType() string
    40  }
    41  
    42  type Metadata struct {
    43  	StartTime       time.Time
    44  	EndTime         time.Time
    45  	Key             *segment.Key
    46  	SpyName         string
    47  	SampleRate      uint32
    48  	Units           metadata.Units
    49  	AggregationType metadata.AggregationType
    50  }
    51  
    52  type Error struct{ Err error }
    53  
    54  func (e Error) Error() string { return e.Err.Error() }
    55  
    56  func (e Error) Unwrap() error { return e.Err }
    57  
    58  func IsIngestionError(err error) bool {
    59  	if err == nil {
    60  		return false
    61  	}
    62  	var v Error
    63  	return errors.As(err, &v)
    64  }