github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/history/types.go (about) 1 package history 2 3 import ( 4 "context" 5 "net/http" 6 "strconv" 7 "strings" 8 "time" 9 10 "github.com/google/uuid" 11 "github.com/pyroscope-io/pyroscope/pkg/model" 12 ) 13 14 type QueryID string 15 16 type EntryType string 17 18 const ( 19 EntryTypeRender EntryType = "render" 20 EntryTypeMerge EntryType = "merge" 21 EntryTypeCompare EntryType = "compare" 22 EntryTypeDiff EntryType = "diff" 23 ) 24 25 type Entry struct { 26 ID QueryID 27 Type EntryType 28 URL string 29 Referer string 30 Timestamp time.Time 31 AppName string 32 StartTime time.Time 33 EndTime time.Time 34 Profiles []string 35 UserID string 36 UserEmail string 37 OrganizationName string 38 } 39 40 func (in *Entry) PopulateFromRequest(req *http.Request) { 41 in.URL = req.URL.String() 42 in.Referer = req.Header.Get("Referer") 43 if u, ok := model.UserFromContext(req.Context()); ok { 44 in.UserID = strconv.Itoa(int(u.ID)) 45 in.UserEmail = *u.Email 46 } 47 } 48 49 type Manager interface { 50 Add(ctx context.Context, entry *Entry) (QueryID, error) 51 Get(ctx context.Context, id QueryID) (*Entry, error) 52 List(ctx context.Context, cursor string) ([]*Entry, string, error) 53 } 54 55 func GenerateQueryID() QueryID { 56 return QueryID(strings.ReplaceAll(uuid.New().String(), "-", "")) 57 }