github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/server/exemplars_merge_test.go (about) 1 package server 2 3 import ( 4 "bytes" 5 "encoding/json" 6 "io" 7 "net/http" 8 "net/http/httptest" 9 10 . "github.com/onsi/ginkgo/v2" 11 . "github.com/onsi/gomega" 12 "github.com/prometheus/client_golang/prometheus" 13 "github.com/sirupsen/logrus" 14 15 "github.com/pyroscope-io/pyroscope/pkg/config" 16 "github.com/pyroscope-io/pyroscope/pkg/exporter" 17 "github.com/pyroscope-io/pyroscope/pkg/health" 18 "github.com/pyroscope-io/pyroscope/pkg/parser" 19 "github.com/pyroscope-io/pyroscope/pkg/storage" 20 "github.com/pyroscope-io/pyroscope/pkg/testing" 21 ) 22 23 var _ = Describe("render merge test", func() { 24 var httpServer *httptest.Server 25 var s *storage.Storage 26 27 testing.WithConfig(func(cfg **config.Config) { 28 BeforeEach(func() { 29 (*cfg).Server.APIBindAddr = ":10044" 30 var err error 31 s, err = storage.New( 32 storage.NewConfig(&(*cfg).Server), 33 logrus.StandardLogger(), 34 prometheus.NewRegistry(), 35 new(health.Controller), 36 storage.NoopApplicationMetadataService{}, 37 ) 38 Expect(err).ToNot(HaveOccurred()) 39 e, _ := exporter.NewExporter(nil, nil) 40 c, _ := New(Config{ 41 Configuration: &(*cfg).Server, 42 Storage: s, 43 Ingester: parser.New(logrus.StandardLogger(), s, e), 44 Logger: logrus.New(), 45 MetricsRegisterer: prometheus.NewRegistry(), 46 ExportedMetricsRegistry: prometheus.NewRegistry(), 47 Notifier: mockNotifier{}, 48 }) 49 h, _ := c.serverMux() 50 httpServer = httptest.NewServer(h) 51 }) 52 53 JustAfterEach(func() { 54 s.Close() 55 httpServer.Close() 56 }) 57 58 Context("/merge", func() { 59 It("handles merge requests", func() { 60 defer httpServer.Close() 61 62 resp, err := http.Post(httpServer.URL+"/merge", "application/json", reqBody(mergeExemplarsRequest{ 63 AppName: "app.cpu", 64 Profiles: []string{"a", "b"}, 65 })) 66 67 Expect(err).ToNot(HaveOccurred()) 68 Expect(resp.StatusCode).To(Equal(http.StatusOK)) 69 70 var merged mergeExemplarsResponse 71 Expect(json.NewDecoder(resp.Body).Decode(&merged)).ToNot(HaveOccurred()) 72 Expect(merged.Validate()).ToNot(HaveOccurred()) 73 }) 74 }) 75 }) 76 }) 77 78 func reqBody(v interface{}) io.Reader { 79 var b bytes.Buffer 80 Expect(json.NewEncoder(&b).Encode(v)).ToNot(HaveOccurred()) 81 return &b 82 }