diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 9ad4dae8dbab..58a4323a3c51 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -629,21 +629,58 @@ func TestHttpHeaders(t *testing.T) { func BenchmarkHttpRequest(b *testing.B) { - hss := &HTTPServerSettings{ - Endpoint: "localhost:0", + tests := []struct { + name string + tlsServerCreds *configtls.TLSServerSetting + tlsClientCreds *configtls.TLSClientSetting + hasError bool + }{ + { + name: "noTLS", + tlsServerCreds: nil, + tlsClientCreds: &configtls.TLSClientSetting{ + Insecure: true, + }, + }, + { + name: "TLS", + tlsServerCreds: &configtls.TLSServerSetting{ + TLSSetting: configtls.TLSSetting{ + CAFile: path.Join(".", "testdata", "ca.crt"), + CertFile: path.Join(".", "testdata", "server.crt"), + KeyFile: path.Join(".", "testdata", "server.key"), + }, + }, + tlsClientCreds: &configtls.TLSClientSetting{ + TLSSetting: configtls.TLSSetting{ + CAFile: path.Join(".", "testdata", "ca.crt"), + }, + ServerName: "localhost", + }, + }, } - s := hss.ToServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - _, errWrite := fmt.Fprint(w, "test") - assert.NoError(b, errWrite) - })) - req := httptest.NewRequest("GET", "/", nil) + for _, bb := range tests { + b.Run(bb.name, func(b *testing.B) { + hss := &HTTPServerSettings{ + Endpoint: "localhost:0", + TLSSetting: bb.tlsServerCreds, + } + s := hss.ToServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _, errWrite := fmt.Fprint(w, "test") + assert.NoError(b, errWrite) + }), componenttest.NewNopTelemetrySettings()) + + req := httptest.NewRequest("GET", "/", nil) - for i := 0; i < b.N; i++ { - rw := httptest.NewRecorder() + for i := 0; i < b.N; i++ { + rw := httptest.NewRecorder() - // Use the handler generated by ToServer for benchmarking - // to avoid network artifacts - s.Handler.ServeHTTP(rw, req) + // Use the handler generated by ToServer for benchmarking + // to avoid network artifacts + s.Handler.ServeHTTP(rw, req) + } + }) } + }