github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/types.go (about) 1 package storage 2 3 //revive:disable:max-public-structs TODO: we will refactor this later 4 5 import ( 6 "context" 7 "time" 8 9 "github.com/dgraph-io/badger/v2" 10 "github.com/pyroscope-io/pyroscope/pkg/storage/cache" 11 "github.com/pyroscope-io/pyroscope/pkg/util/bytesize" 12 ) 13 14 type Putter interface { 15 Put(context.Context, *PutInput) error 16 } 17 18 type Getter interface { 19 Get(context.Context, *GetInput) (*GetOutput, error) 20 } 21 22 type ExemplarsGetter interface { 23 GetExemplar(context.Context, GetExemplarInput) (GetExemplarOutput, error) 24 } 25 26 type ExemplarsMerger interface { 27 MergeExemplars(context.Context, MergeExemplarsInput) (MergeExemplarsOutput, error) 28 } 29 30 type ExemplarsQuerier interface { 31 QueryExemplars(context.Context, QueryExemplarsInput) (QueryExemplarsOutput, error) 32 } 33 34 type GetLabelKeysByQueryInput struct { 35 StartTime time.Time 36 EndTime time.Time 37 Query string 38 } 39 40 type GetLabelKeysByQueryOutput struct { 41 Keys []string 42 } 43 44 type LabelsGetter interface { 45 GetKeys(ctx context.Context, cb func(string) bool) 46 GetKeysByQuery(ctx context.Context, in GetLabelKeysByQueryInput) (GetLabelKeysByQueryOutput, error) 47 } 48 49 type GetLabelValuesByQueryInput struct { 50 StartTime time.Time 51 EndTime time.Time 52 Label string 53 Query string 54 } 55 56 type GetLabelValuesByQueryOutput struct { 57 Values []string 58 } 59 60 type LabelValuesGetter interface { 61 GetValues(ctx context.Context, key string, cb func(v string) bool) 62 GetValuesByQuery(ctx context.Context, in GetLabelValuesByQueryInput) (GetLabelValuesByQueryOutput, error) 63 } 64 65 // Other functions from storage.Storage: 66 // type Backend interface { 67 // Put(ctx context.Context, pi *PutInput) error 68 // Get(ctx context.Context, gi *GetInput) (*GetOutput, error) 69 70 // GetAppNames(ctx context.Context, ) []string 71 // GetKeys(ctx context.Context, cb func(string) bool) 72 // GetKeysByQuery(ctx context.Context, query string, cb func(_k string) bool) error 73 // GetValues(ctx context.Context, key string, cb func(v string) bool) 74 // GetValuesByQuery(ctx context.Context, label string, query string, cb func(v string) bool) error 75 // DebugExport(ctx context.Context, w http.ResponseWriter, r *http.Request) 76 77 // Delete(ctx context.Context, di *DeleteInput) error 78 // DeleteApp(ctx context.Context, appname string) error 79 // } 80 81 type BadgerDB interface { 82 Update(func(txn *badger.Txn) error) error 83 View(func(txn *badger.Txn) error) error 84 NewWriteBatch() *badger.WriteBatch 85 MaxBatchCount() int64 86 } 87 88 type CacheLayer interface { 89 Put(key string, val interface{}) 90 Evict(percent float64) 91 WriteBack() 92 Delete(key string) error 93 Discard(key string) 94 DiscardPrefix(prefix string) error 95 GetOrCreate(key string) (interface{}, error) 96 Lookup(key string) (interface{}, bool) 97 } 98 99 type BadgerDBWithCache interface { 100 BadgerDB 101 CacheLayer 102 103 Size() bytesize.ByteSize 104 CacheSize() uint64 105 106 DBInstance() *badger.DB 107 CacheInstance() *cache.Cache 108 Name() string 109 }