# This is a combination of 12 commits.

# This is the 1st commit message:

init without tests

# This is the commit message #2:

change log

# This is the commit message #3:

fix tests

# This is the commit message #4:

fix tests

# This is the commit message #5:

added tests

# This is the commit message #6:

change log breaking change

# This is the commit message #7:

removed breaking change

# This is the commit message #8:

fix test

# This is the commit message #9:

keeping the test behaviour same

# This is the commit message #10:

made enable debug atomic bool

# This is the commit message #11:

fix lint

# This is the commit message #12:

fix test true enable debug
pull/17565/head
absolutelightning 2023-06-21 18:33:07 +05:30
parent 10f500e895
commit e08c309101
11 changed files with 65 additions and 23 deletions

View File

@ -19,6 +19,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/armon/go-metrics" "github.com/armon/go-metrics"
@ -4290,7 +4291,8 @@ func (a *Agent) reloadConfigInternal(newCfg *config.RuntimeConfig) error {
a.proxyConfig.SetUpdateRateLimit(newCfg.XDSUpdateRateLimit) a.proxyConfig.SetUpdateRateLimit(newCfg.XDSUpdateRateLimit)
a.config.EnableDebug = newCfg.EnableDebug a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(newCfg.EnableDebug.Load())
return nil return nil
} }

View File

@ -17,6 +17,7 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -6008,6 +6009,8 @@ func TestAgent_Monitor(t *testing.T) {
cancelCtx, cancelFunc := context.WithCancel(context.Background()) cancelCtx, cancelFunc := context.WithCancel(context.Background())
req = req.WithContext(cancelCtx) req = req.WithContext(cancelCtx)
a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
handler := a.srv.handler() handler := a.srv.handler()
go handler.ServeHTTP(resp, req) go handler.ServeHTTP(resp, req)

View File

@ -4212,7 +4212,7 @@ func TestAgent_ReloadConfig_EnableDebug(t *testing.T) {
}, },
) )
require.NoError(t, a.reloadConfigInternal(c)) require.NoError(t, a.reloadConfigInternal(c))
require.Equal(t, true, a.config.EnableDebug) require.Equal(t, true, a.config.EnableDebug.Load())
c = TestConfig( c = TestConfig(
testutil.Logger(t), testutil.Logger(t),
@ -4223,7 +4223,7 @@ func TestAgent_ReloadConfig_EnableDebug(t *testing.T) {
}, },
) )
require.NoError(t, a.reloadConfigInternal(c)) require.NoError(t, a.reloadConfigInternal(c))
require.Equal(t, false, a.config.EnableDebug) require.Equal(t, false, a.config.EnableDebug.Load())
} }
func TestAgent_consulConfig_AutoEncryptAllowTLS(t *testing.T) { func TestAgent_consulConfig_AutoEncryptAllowTLS(t *testing.T) {

View File

@ -18,6 +18,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"sync/atomic"
"time" "time"
"github.com/armon/go-metrics/prometheus" "github.com/armon/go-metrics/prometheus"
@ -1010,7 +1011,7 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
DiscoveryMaxStale: b.durationVal("discovery_max_stale", c.DiscoveryMaxStale), DiscoveryMaxStale: b.durationVal("discovery_max_stale", c.DiscoveryMaxStale),
EnableAgentTLSForChecks: boolVal(c.EnableAgentTLSForChecks), EnableAgentTLSForChecks: boolVal(c.EnableAgentTLSForChecks),
EnableCentralServiceConfig: boolVal(c.EnableCentralServiceConfig), EnableCentralServiceConfig: boolVal(c.EnableCentralServiceConfig),
EnableDebug: boolVal(c.EnableDebug), EnableDebug: *atomicBoolVal(c.EnableDebug),
EnableRemoteScriptChecks: enableRemoteScriptChecks, EnableRemoteScriptChecks: enableRemoteScriptChecks,
EnableLocalScriptChecks: enableLocalScriptChecks, EnableLocalScriptChecks: enableLocalScriptChecks,
EncryptKey: stringVal(c.EncryptKey), EncryptKey: stringVal(c.EncryptKey),
@ -1942,6 +1943,21 @@ func boolValWithDefault(v *bool, defaultVal bool) bool {
return *v return *v
} }
func atomicBool(v bool) *atomic.Bool {
atomicBool := atomic.Bool{}
atomicBool.Store(v)
return &atomicBool
}
func atomicBoolVal(v *bool) *atomic.Bool {
if v == nil {
return &atomic.Bool{}
}
atomicBool := atomic.Bool{}
atomicBool.Store(*v)
return &atomicBool
}
func boolVal(v *bool) bool { func boolVal(v *bool) bool {
if v == nil { if v == nil {
return false return false

View File

@ -8,6 +8,7 @@ import (
"net" "net"
"reflect" "reflect"
"strings" "strings"
"sync/atomic"
"time" "time"
"github.com/hashicorp/go-uuid" "github.com/hashicorp/go-uuid"
@ -651,7 +652,7 @@ type RuntimeConfig struct {
// EnableDebug is used to enable various debugging features. // EnableDebug is used to enable various debugging features.
// //
// hcl: enable_debug = (true|false) // hcl: enable_debug = (true|false)
EnableDebug bool EnableDebug atomic.Bool
// EnableLocalScriptChecks controls whether health checks declared from the local // EnableLocalScriptChecks controls whether health checks declared from the local
// config file which execute scripts are enabled. This includes regular script // config file which execute scripts are enabled. This includes regular script

View File

@ -17,6 +17,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -324,8 +325,8 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
rt.DevMode = true rt.DevMode = true
rt.DisableAnonymousSignature = true rt.DisableAnonymousSignature = true
rt.DisableKeyringFile = true rt.DisableKeyringFile = true
rt.EnableDebug = true
rt.Experiments = []string{"resource-apis"} rt.Experiments = []string{"resource-apis"}
rt.EnableDebug.Store(true)
rt.UIConfig.Enabled = true rt.UIConfig.Enabled = true
rt.LeaveOnTerm = false rt.LeaveOnTerm = false
rt.Logging.LogLevel = "DEBUG" rt.Logging.LogLevel = "DEBUG"
@ -5976,7 +5977,8 @@ func TestLoad_IntegrationWithFlags(t *testing.T) {
// The logstore settings from first file should not be overridden by a // The logstore settings from first file should not be overridden by a
// later file with nothing to say about logstores! // later file with nothing to say about logstores!
rt.RaftLogStoreConfig.Backend = consul.LogStoreBackendWAL rt.RaftLogStoreConfig.Backend = consul.LogStoreBackendWAL
rt.EnableDebug = true rt.EnableDebug = atomic.Bool{}
rt.EnableDebug.Store(true)
}, },
}) })
} }
@ -6079,6 +6081,8 @@ func TestLoad_FullConfig(t *testing.T) {
_, n, _ := net.ParseCIDR(s) _, n, _ := net.ParseCIDR(s)
return n return n
} }
atomicBoolTrue := atomic.Bool{}
atomicBoolTrue.Store(true)
defaultEntMeta := structs.DefaultEnterpriseMetaInDefaultPartition() defaultEntMeta := structs.DefaultEnterpriseMetaInDefaultPartition()
nodeEntMeta := structs.NodeEnterpriseMetaInDefaultPartition() nodeEntMeta := structs.NodeEnterpriseMetaInDefaultPartition()
@ -6366,7 +6370,7 @@ func TestLoad_FullConfig(t *testing.T) {
DiscoveryMaxStale: 5 * time.Second, DiscoveryMaxStale: 5 * time.Second,
EnableAgentTLSForChecks: true, EnableAgentTLSForChecks: true,
EnableCentralServiceConfig: false, EnableCentralServiceConfig: false,
EnableDebug: true, EnableDebug: *atomicBool(true),
EnableRemoteScriptChecks: true, EnableRemoteScriptChecks: true,
EnableLocalScriptChecks: true, EnableLocalScriptChecks: true,
EncryptKey: "A4wELWqH", EncryptKey: "A4wELWqH",

View File

@ -214,7 +214,7 @@ func (s *HTTPHandlers) handler() http.Handler {
wrapper := func(resp http.ResponseWriter, req *http.Request) { wrapper := func(resp http.ResponseWriter, req *http.Request) {
// If enableDebug or ACL enabled, register wrapped pprof handlers // If enableDebug or ACL enabled, register wrapped pprof handlers
if !s.agent.config.EnableDebug && s.checkACLDisabled() { if !s.agent.config.EnableDebug.Load() && s.checkACLDisabled() {
resp.WriteHeader(http.StatusNotFound) resp.WriteHeader(http.StatusNotFound)
return return
} }

View File

@ -9,6 +9,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -144,7 +145,8 @@ func TestHTTPAPI_OptionMethod_OSS(t *testing.T) {
uri := fmt.Sprintf("http://%s%s", a.HTTPAddr(), path) uri := fmt.Sprintf("http://%s%s", a.HTTPAddr(), path)
req, _ := http.NewRequest("OPTIONS", uri, nil) req, _ := http.NewRequest("OPTIONS", uri, nil)
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
allMethods := append([]string{"OPTIONS"}, methods...) allMethods := append([]string{"OPTIONS"}, methods...)
@ -191,7 +193,8 @@ func TestHTTPAPI_AllowedNets_OSS(t *testing.T) {
req, _ := http.NewRequest(method, uri, nil) req, _ := http.NewRequest(method, uri, nil)
req.RemoteAddr = "192.168.1.2:5555" req.RemoteAddr = "192.168.1.2:5555"
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusForbidden, resp.Code, "%s %s", method, path) require.Equal(t, http.StatusForbidden, resp.Code, "%s %s", method, path)

View File

@ -20,6 +20,7 @@ import (
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync/atomic"
"testing" "testing"
"time" "time"
@ -288,7 +289,8 @@ func TestSetupHTTPServer_HTTP2(t *testing.T) {
err = setupHTTPS(httpServer, noopConnState, time.Second) err = setupHTTPS(httpServer, noopConnState, time.Second)
require.NoError(t, err) require.NoError(t, err)
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
srvHandler := a.srv.handler() srvHandler := a.srv.handler()
mux, ok := srvHandler.(*wrappedMux) mux, ok := srvHandler.(*wrappedMux)
require.True(t, ok, "expected a *wrappedMux, got %T", handler) require.True(t, ok, "expected a *wrappedMux, got %T", handler)
@ -484,7 +486,8 @@ func TestHTTPAPI_Ban_Nonprintable_Characters(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
if got, want := resp.Code, http.StatusBadRequest; got != want { if got, want := resp.Code, http.StatusBadRequest; got != want {
t.Fatalf("bad response code got %d want %d", got, want) t.Fatalf("bad response code got %d want %d", got, want)
@ -508,7 +511,8 @@ func TestHTTPAPI_Allow_Nonprintable_Characters_With_Flag(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
// Key doesn't actually exist so we should get 404 // Key doesn't actually exist so we should get 404
if got, want := resp.Code, http.StatusNotFound; got != want { if got, want := resp.Code, http.StatusNotFound; got != want {
@ -648,7 +652,8 @@ func requireHasHeadersSet(t *testing.T, a *TestAgent, path string) {
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", path, nil) req, _ := http.NewRequest("GET", path, nil)
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
hdrs := resp.Header() hdrs := resp.Header()
@ -710,7 +715,8 @@ func TestAcceptEncodingGzip(t *testing.T) {
// negotiation, but since this call doesn't go through a real // negotiation, but since this call doesn't go through a real
// transport, the header has to be set manually // transport, the header has to be set manually
req.Header["Accept-Encoding"] = []string{"gzip"} req.Header["Accept-Encoding"] = []string{"gzip"}
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, 200, resp.Code) require.Equal(t, 200, resp.Code)
require.Equal(t, "", resp.Header().Get("Content-Encoding")) require.Equal(t, "", resp.Header().Get("Content-Encoding"))
@ -718,7 +724,8 @@ func TestAcceptEncodingGzip(t *testing.T) {
resp = httptest.NewRecorder() resp = httptest.NewRecorder()
req, _ = http.NewRequest("GET", "/v1/kv/long", nil) req, _ = http.NewRequest("GET", "/v1/kv/long", nil)
req.Header["Accept-Encoding"] = []string{"gzip"} req.Header["Accept-Encoding"] = []string{"gzip"}
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, 200, resp.Code) require.Equal(t, 200, resp.Code)
require.Equal(t, "gzip", resp.Header().Get("Content-Encoding")) require.Equal(t, "gzip", resp.Header().Get("Content-Encoding"))
@ -1074,7 +1081,8 @@ func TestHTTPServer_PProfHandlers_EnableDebug(t *testing.T) {
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
req, _ := http.NewRequest("GET", "/debug/pprof/profile?seconds=1", nil) req, _ := http.NewRequest("GET", "/debug/pprof/profile?seconds=1", nil)
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
httpServer := &HTTPHandlers{agent: a.Agent} httpServer := &HTTPHandlers{agent: a.Agent}
httpServer.handler().ServeHTTP(resp, req) httpServer.handler().ServeHTTP(resp, req)
@ -1175,7 +1183,8 @@ func TestHTTPServer_PProfHandlers_ACLs(t *testing.T) {
t.Run(fmt.Sprintf("case %d (%#v)", i, c), func(t *testing.T) { t.Run(fmt.Sprintf("case %d (%#v)", i, c), func(t *testing.T) {
req, _ := http.NewRequest("GET", fmt.Sprintf("%s?token=%s", c.endpoint, c.token), nil) req, _ := http.NewRequest("GET", fmt.Sprintf("%s?token=%s", c.endpoint, c.token), nil)
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
assert.Equal(t, c.code, resp.Code) assert.Equal(t, c.code, resp.Code)
}) })
@ -1486,7 +1495,8 @@ func TestEnableWebUI(t *testing.T) {
req, _ := http.NewRequest("GET", "/ui/", nil) req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code) require.Equal(t, http.StatusOK, resp.Code)
@ -1516,7 +1526,8 @@ func TestEnableWebUI(t *testing.T) {
{ {
req, _ := http.NewRequest("GET", "/ui/", nil) req, _ := http.NewRequest("GET", "/ui/", nil)
resp := httptest.NewRecorder() resp := httptest.NewRecorder()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
a.srv.handler().ServeHTTP(resp, req) a.srv.handler().ServeHTTP(resp, req)
require.Equal(t, http.StatusOK, resp.Code) require.Equal(t, http.StatusOK, resp.Code)
require.Contains(t, resp.Body.String(), `<!-- CONSUL_VERSION:`) require.Contains(t, resp.Body.String(), `<!-- CONSUL_VERSION:`)

View File

@ -58,7 +58,8 @@ func TestUIEndpoint_MetricsProxy_ACLDeny(t *testing.T) {
`, backendURL)) `, backendURL))
defer a.Shutdown() defer a.Shutdown()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.Config.EnableDebug.Store(true)
h := a.srv.handler() h := a.srv.handler()
testrpc.WaitForLeader(t, a.RPC, "dc1") testrpc.WaitForLeader(t, a.RPC, "dc1")

View File

@ -2621,7 +2621,8 @@ func TestUIEndpoint_MetricsProxy(t *testing.T) {
// Now fetch the API handler to run requests against // Now fetch the API handler to run requests against
h := a.srv.handler() h := a.srv.handler()
a.config.EnableDebug = true a.config.EnableDebug = atomic.Bool{}
a.config.EnableDebug.Store(true)
req := httptest.NewRequest("GET", tc.path, nil) req := httptest.NewRequest("GET", tc.path, nil)
rec := httptest.NewRecorder() rec := httptest.NewRecorder()