From 1e19ed7a95b99bba1908c6e3a85f81923b8e8089 Mon Sep 17 00:00:00 2001 From: Peter Van Bouwel Date: Wed, 29 Jan 2025 16:54:53 +0100 Subject: [PATCH] benchmark: use plain text proxy. In order to not have misleading benchmark outcomes as detailed in https://github.com/VITObelgium/fakes3pp/pull/21#issuecomment-2620902233 we will benchmark with a plaintext proxy from now on. This will make the process slower but the results will be more intuitive. --- cmd/benchmark_test.go | 18 +++++++++++++++++- cmd/test-utils.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/cmd/benchmark_test.go b/cmd/benchmark_test.go index bf5e0fa..5d19e9b 100644 --- a/cmd/benchmark_test.go +++ b/cmd/benchmark_test.go @@ -117,10 +117,26 @@ func getTestBucketObjectContentReadLength(t testing.TB, client s3.Client, object return written, nil } +//This is a testing fixture but where sts and s3 proxy are running in plaintext mode +//This is not really a common deployment setup but if we use TLS for our proxy but not for our testing backend +//Then we get misleading performance metrics as mentioned in https://github.com/VITObelgium/fakes3pp/pull/21#issuecomment-2620902233 +//Using plain text will be a fairer comparison. +func testingFixturePlainTextProxy(t testing.TB) (tearDown func ()(), getToken func(subject string, d time.Duration, tags AWSSessionTags) string){ + resetEnv := fixture_with_environment_values(t, map[string]string{ + FAKES3PP_SECURE: "false", + }) + tearDown1, getToken := testingFixture(t) + tearDown = func() { + tearDown1() + resetEnv() + } + return tearDown, getToken +} + func BenchmarkFakeS3Proxy(b *testing.B) { initializeTestLogging() - tearDown, getSignedToken := testingFixture(b) + tearDown, getSignedToken := testingFixturePlainTextProxy(b) defer tearDown() token := getSignedToken("mySubject", time.Minute * 20, AWSSessionTags{PrincipalTags: map[string][]string{"org": {"a"}}}) //Given the policy Manager that has our test policies diff --git a/cmd/test-utils.go b/cmd/test-utils.go index 59ea0e1..17ee8cc 100644 --- a/cmd/test-utils.go +++ b/cmd/test-utils.go @@ -85,4 +85,41 @@ func assertHttpRequestOK(tb testing.TB, resp *http.Response) { if resp.StatusCode != http.StatusOK { tb.Errorf("Should have gotten succesful request") } +} + +func fixture_with_environment_values(tb testing.TB, new_env map[string]string) (tearDown func ()()){ + old_env_variables := map[string]string{} + + for new_env_key, new_env_value := range new_env { + old_value, old_value_exists := os.LookupEnv(new_env_key) + if old_value_exists { + old_env_variables[new_env_key] = old_value + } + err := os.Setenv(new_env_key, new_env_value) + if err != nil { + tb.Errorf("Issue environment fixture when setting %s=%s got %s", new_env_key, new_env_value, err) + tb.FailNow() + } + } + + tearDown = func() () { + for new_env_key, new_env_value := range new_env { + old_value, old_value_exists := os.LookupEnv(new_env_key) + if old_value_exists { + err := os.Setenv(new_env_key, old_value) + if err != nil { + tb.Errorf("Issue environment fixture when setting %s=%s got %s", new_env_key, new_env_value, err) + tb.FailNow() + } + } else { + err := os.Unsetenv(new_env_key) + if err != nil { + tb.Errorf("Issue environment fixture when unsetting %s=%s got %s", new_env_key, new_env_value, err) + tb.FailNow() + } + } + + } + } + return tearDown } \ No newline at end of file