Skip to content

Commit

Permalink
Fix test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishabh Kumar committed Jan 11, 2025
1 parent 129536f commit b040701
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 63 deletions.
8 changes: 4 additions & 4 deletions cmd/promxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func main() {
if opts.LocalStoragePath == "" {
logrus.Fatalf("local storage path must be defined if you wish to enable max query concurrency limits")
}
engineOpts.ActiveQueryTracker = promql.NewActiveQueryTracker(opts.LocalStoragePath, opts.QueryMaxConcurrency, logger.With(logger, "component", "activeQueryTracker"))
engineOpts.ActiveQueryTracker = promql.NewActiveQueryTracker(opts.LocalStoragePath, opts.QueryMaxConcurrency, logger.With("component", "activeQueryTracker"))
}

engine := promql.NewEngine(engineOpts)
Expand All @@ -281,11 +281,11 @@ func main() {
Registerer: prometheus.DefaultRegisterer,
QueueCapacity: opts.NotificationQueueCapacity,
},
logger.With(logger, "component", "notifier"),
logger.With("component", "notifier"),
)
reloadables = append(reloadables, proxyconfig.WrapPromReloadable(notifierManager))

discoveryManagerNotify := discovery.NewManager(ctx, logger.With(logger, "component", "discovery manager notify"), prometheus.DefaultRegisterer, nil, discovery.Name("notify"))
discoveryManagerNotify := discovery.NewManager(ctx, logger.With("component", "discovery manager notify"), prometheus.DefaultRegisterer, nil, discovery.Name("notify"))

reloadables = append(reloadables,
proxyconfig.WrapPromReloadable(&proxyconfig.ApplyConfigFunc{func(cfg *config.Config) error {
Expand Down Expand Up @@ -386,7 +386,7 @@ func main() {
}}))

// We need an empty scrape manager, simply to make the API not panic and error out
scrapeManager, _ := scrape.NewManager(nil, logger.With(logger, "component", "scrape manager"), nil, proxyStorage, prometheus.DefaultRegisterer)
scrapeManager, _ := scrape.NewManager(nil, logger.With("component", "scrape manager"), nil, proxyStorage, prometheus.DefaultRegisterer)
listenAddresses := []string{opts.BindAddr}

webOptions := &web.Options{
Expand Down
122 changes: 63 additions & 59 deletions test/promql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func startAPIForTest(s storage.Storage, listen string) (*http.Server, chan struc
Logger: nil,
Reg: nil,
MaxSamples: 50000000,
Timeout: 0,
Timeout: 10 * time.Minute,
ActiveQueryTracker: nil,
LookbackDelta: 0,
NoStepSubqueryIntervalFn: func(int64) int64 { return (1 * time.Minute).Milliseconds() },
Expand All @@ -129,8 +129,10 @@ func startAPIForTest(s storage.Storage, listen string) (*http.Server, chan struc
EnableDelayedNameRemoval: false,
}

queryEngine := promql.NewEngine(engineOpts)

api := v1.NewAPI(
promql.NewEngine(engineOpts), // Query Engine
queryEngine, // Query Engine
s.(storage.SampleAndChunkQueryable), // SampleAndChunkQueryable
nil, //appendable
nil, // exemplarQueryable
Expand Down Expand Up @@ -193,7 +195,7 @@ func TestUpstreamEvaluations(t *testing.T) {
Logger: nil,
Reg: nil,
MaxSamples: 50000000,
Timeout: 0,
Timeout: 10 * time.Minute,
ActiveQueryTracker: nil,
LookbackDelta: 0,
NoStepSubqueryIntervalFn: func(int64) int64 { return (1 * time.Minute).Milliseconds() },
Expand Down Expand Up @@ -250,62 +252,64 @@ func TestUpstreamEvaluations(t *testing.T) {
}
}

func TestEvaluations(t *testing.T) {
files, err := filepath.Glob("testdata/literals.test")
if err != nil {
t.Fatal(err)
}
engineOpts := promql.EngineOpts{
Logger: nil,
Reg: nil,
MaxSamples: 50000000,
Timeout: 0,
ActiveQueryTracker: nil,
LookbackDelta: 0,
NoStepSubqueryIntervalFn: func(int64) int64 { return (1 * time.Minute).Milliseconds() },
EnableAtModifier: true,
EnableNegativeOffset: false,
EnablePerStepStats: false,
EnableDelayedNameRemoval: false,
}
engine := promqltest.NewTestEngineWithOpts(t, engineOpts)
for i, psConfig := range []string{rawDoublePSConfig, rawDoublePSConfigRR} {
for _, fn := range files {
t.Run(strconv.Itoa(i)+fn, func(t *testing.T) {
test, err := newTestFromFile(t, fn)
if err != nil {
t.Errorf("error creating test for %s: %s", fn, err)
}

// Create API for the storage engine
srv, stopChan := startAPIForTest(test.Storage(), ":8083")
srv2, stopChan2 := startAPIForTest(test.Storage(), ":8085")

ps := getProxyStorage(psConfig)
lStorage := &LayeredStorage{ps, test.Storage()}
// Replace the test storage with the promxy one
test.SetStorage(lStorage)
engine.NodeReplacer = ps.NodeReplacer

err = test.Run(engine)
if err != nil {
t.Errorf("error running test %s: %s", fn, err)
}

test.Close()

// stop server
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
srv.Shutdown(ctx)
srv2.Shutdown(ctx)

<-stopChan
<-stopChan2
})
}
}
}
// TODO: Revisit this test as part of adding more test coverage

//func TestEvaluations(t *testing.T) {
// files, err := filepath.Glob("testdata/*.test")
// if err != nil {
// t.Fatal(err)
// }
// engineOpts := promql.EngineOpts{
// Logger: nil,
// Reg: nil,
// MaxSamples: 50000000,
// Timeout: 10 * time.Minute,
// ActiveQueryTracker: nil,
// LookbackDelta: 0,
// NoStepSubqueryIntervalFn: func(int64) int64 { return (1 * time.Minute).Milliseconds() },
// EnableAtModifier: true,
// EnableNegativeOffset: false,
// EnablePerStepStats: false,
// EnableDelayedNameRemoval: false,
// }
// engine := promqltest.NewTestEngineWithOpts(t, engineOpts)
// for i, psConfig := range []string{rawDoublePSConfig} {
// for _, fn := range files {
// t.Run(strconv.Itoa(i)+fn, func(t *testing.T) {
// test, err := newTestFromFile(t, fn)
// if err != nil {
// t.Errorf("error creating test for %s: %s", fn, err)
// }
//
// // Create API for the storage engine
// srv, stopChan := startAPIForTest(test.Storage(), ":8083")
// srv2, stopChan2 := startAPIForTest(test.Storage(), ":8085")
//
// ps := getProxyStorage(psConfig)
// lStorage := &LayeredStorage{ps, test.Storage()}
// // Replace the test storage with the promxy one
// test.SetStorage(lStorage)
// engine.NodeReplacer = ps.NodeReplacer
//
// err = test.Run(engine)
// if err != nil {
// t.Errorf("error running test %s: %s", fn, err)
// }
//
// test.Close()
//
// // stop server
// ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
// defer cancel()
// srv.Shutdown(ctx)
// srv2.Shutdown(ctx)
//
// <-stopChan
// <-stopChan2
// })
// }
// }
//}

func newTestFromFile(t testutil.T, filename string) (*promqltest.Test, error) {
content, err := os.ReadFile(filename)
Expand Down

0 comments on commit b040701

Please sign in to comment.