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

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package storage
     5  
     6  import (
     7  	"context"
     8  	"time"
     9  
    10  	. "github.com/onsi/ginkgo/v2"
    11  
    12  	. "github.com/onsi/gomega"
    13  	"github.com/prometheus/client_golang/prometheus"
    14  	"github.com/pyroscope-io/pyroscope/pkg/config"
    15  	"github.com/pyroscope-io/pyroscope/pkg/flameql"
    16  	"github.com/pyroscope-io/pyroscope/pkg/health"
    17  	"github.com/pyroscope-io/pyroscope/pkg/storage/metadata"
    18  	"github.com/pyroscope-io/pyroscope/pkg/testing"
    19  	"github.com/pyroscope-io/pyroscope/pkg/testing/load"
    20  	"github.com/sirupsen/logrus"
    21  )
    22  
    23  var _ = Describe("storage package", func() {
    24  	logrus.SetLevel(logrus.InfoLevel)
    25  	testing.WithConfig(func(cfg **config.Config) {
    26  		JustBeforeEach(func() {
    27  			var err error
    28  			s, err = New(NewConfig(&(*cfg).Server), logrus.StandardLogger(), prometheus.NewRegistry(), new(health.Controller), NoopApplicationMetadataService{})
    29  			Expect(err).ToNot(HaveOccurred())
    30  		})
    31  
    32  		writeFn := func(input load.Input) {
    33  			Expect(s.Put(context.Background(), &PutInput{
    34  				StartTime:       input.StartTime,
    35  				EndTime:         input.EndTime,
    36  				Key:             input.Key,
    37  				Val:             input.Val,
    38  				SpyName:         input.SpyName,
    39  				SampleRate:      input.SampleRate,
    40  				Units:           input.Units,
    41  				AggregationType: input.AggregationType,
    42  			})).ToNot(HaveOccurred())
    43  		}
    44  
    45  		Context("Put", func() {
    46  			It("can be called concurrently", func() {
    47  				defer func() {
    48  					Expect(s.Close()).ToNot(HaveOccurred())
    49  				}()
    50  
    51  				seed := int(time.Now().UnixNano())
    52  				const appName = "test.app.cpu"
    53  
    54  				app := load.NewApp(seed, appName, load.AppConfig{
    55  					SpyName:         "debugspy",
    56  					SampleRate:      100,
    57  					Units:           "samples",
    58  					AggregationType: metadata.SumAggregationType,
    59  					Trees:           10,
    60  					TreeConfig: load.TreeConfig{
    61  						MaxSymLen: 32,
    62  						MaxDepth:  32,
    63  						Width:     16,
    64  					},
    65  					Tags: []load.Tag{
    66  						{
    67  							Name:        "hostname",
    68  							Cardinality: 10,
    69  							MinLen:      16,
    70  							MaxLen:      16,
    71  						},
    72  					},
    73  				})
    74  
    75  				suite := load.NewStorageWriteSuite(load.StorageWriteSuiteConfig{
    76  					Seed:     seed,
    77  					Sources:  100,
    78  					Interval: 10 * time.Second,
    79  					Period:   time.Minute,
    80  					Writers:  8,
    81  					WriteFn:  writeFn,
    82  				})
    83  				suite.AddApp(app)
    84  				suite.Start()
    85  
    86  				output, err := s.Get(context.Background(), &GetInput{
    87  					StartTime: time.Time{},
    88  					EndTime:   maxTime,
    89  					Query:     &flameql.Query{AppName: appName},
    90  				})
    91  
    92  				Expect(err).ToNot(HaveOccurred())
    93  				Expect(app.MergedTree().String()).To(Equal(output.Tree.String()))
    94  				Expect(s.segments.CacheSize()).To(Equal(uint64(10)))
    95  			})
    96  		})
    97  	})
    98  })