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

     1  package storage
     2  
     3  import (
     4  	"context"
     5  	"time"
     6  
     7  	"github.com/pyroscope-io/pyroscope/pkg/storage/metadata"
     8  	"github.com/pyroscope-io/pyroscope/pkg/storage/tree"
     9  )
    10  
    11  type GetExemplarInput struct {
    12  	StartTime time.Time
    13  	EndTime   time.Time
    14  	AppName   string
    15  	ProfileID string
    16  }
    17  
    18  type GetExemplarOutput struct {
    19  	Tree      *tree.Tree
    20  	Labels    map[string]string
    21  	StartTime time.Time
    22  	EndTime   time.Time
    23  	Metadata  metadata.Metadata
    24  
    25  	Telemetry map[string]interface{}
    26  }
    27  
    28  func (s *Storage) GetExemplar(ctx context.Context, gi GetExemplarInput) (out GetExemplarOutput, err error) {
    29  	m, err := s.mergeExemplars(ctx, MergeExemplarsInput{
    30  		AppName:    gi.AppName,
    31  		StartTime:  gi.StartTime,
    32  		EndTime:    gi.EndTime,
    33  		ProfileIDs: []string{gi.ProfileID},
    34  	})
    35  	if err != nil {
    36  		return out, err
    37  	}
    38  
    39  	out.Tree = m.tree
    40  	if m.lastEntry != nil {
    41  		out.Labels = m.lastEntry.Labels
    42  		out.StartTime = time.Unix(0, m.lastEntry.StartTime)
    43  		out.EndTime = time.Unix(0, m.lastEntry.EndTime)
    44  	}
    45  
    46  	if m.segment != nil {
    47  		out.Metadata = m.segment.GetMetadata()
    48  	}
    49  
    50  	return out, nil
    51  }