Skip to content

Commit f3ab1b7

Browse files
authored
Add Config struct with DisableConfigEndpoint option to profutils profiling server. Register config section under "prof" key with pflags generation and conditionally skip the /config HTTP handler when disabled. (#7016)
* Add Config struct with DisableConfigEndpoint option to profutils profiling server. Register config section under "prof" key with pflags generation and conditionally skip the /config HTTP handler when disabled. Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com> * Fix tests Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com> * Fix config registration Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com> * Fix unit tests Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com> * Fix test Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com> --------- Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
1 parent ecb7706 commit f3ab1b7

File tree

6 files changed

+205
-5
lines changed

6 files changed

+205
-5
lines changed

flyteadmin/auth/cookie_manager_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ func TestExtractAccessTokenFromCookies(t *testing.T) {
315315
t.Logf("Cookie 1 raw decoded (first 50 bytes): %s", string(decoded[:50]))
316316
}
317317
s := securecookie.New(hashKey, blockKey)
318+
s.MaxAge(0) // Disable timestamp validation so hardcoded cookies don't expire
318319
var firstHalf string
319320
err = s.Decode("flyte_at_1", cookieValue1, &firstHalf)
320321
if err != nil {
@@ -323,6 +324,7 @@ func TestExtractAccessTokenFromCookies(t *testing.T) {
323324
err2 := s2.Decode("flyte_at_1", cookieValue1, &firstHalf)
324325
t.Logf("Error with validation enabled: %v", err2)
325326
}
327+
326328
require.NoError(t, err)
327329
t.Logf("First half of access token: %s", firstHalf)
328330

flytestdlib/profutils/config.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package profutils
2+
3+
import "github.com/flyteorg/flyte/flytestdlib/config"
4+
5+
//go:generate pflags Config --default-var=defaultConfig
6+
7+
const configSectionKey = "prof"
8+
9+
var (
10+
configSection = config.MustRegisterSection(configSectionKey, defaultConfig)
11+
defaultConfig = &Config{}
12+
)
13+
14+
type Config struct {
15+
DisableConfigEndpoint bool `config:"DisableConfigEndpoint"`
16+
}
17+
18+
func GetConfig() *Config {
19+
return configSection.GetConfig().(*Config)
20+
}

flytestdlib/profutils/config_flags.go

Lines changed: 55 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flytestdlib/profutils/config_flags_test.go

Lines changed: 116 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flytestdlib/profutils/server.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,17 @@ func StartProfilingServer(ctx context.Context, pprofPort int) error {
110110
return srv.ListenAndServe()
111111
}
112112

113-
func configureGlobalHTTPHandler(handlers map[string]http.Handler) error {
113+
func configureGlobalHTTPHandler(cfg *Config, handlers map[string]http.Handler) error {
114114
if handlers == nil {
115115
handlers = map[string]http.Handler{}
116116
}
117+
117118
handlers[metricsPath] = promhttp.Handler()
118119
handlers[healthcheck] = http.HandlerFunc(healtcheckHandler)
119120
handlers[versionPath] = http.HandlerFunc(versionHandler)
120-
handlers[configPath] = http.HandlerFunc(configHandler)
121+
if !cfg.DisableConfigEndpoint {
122+
handlers[configPath] = http.HandlerFunc(configHandler)
123+
}
121124

122125
for p, h := range handlers {
123126
http.Handle(p, h)
@@ -126,14 +129,15 @@ func configureGlobalHTTPHandler(handlers map[string]http.Handler) error {
126129
return nil
127130
}
128131

129-
// Forwards the call to StartProfilingServer
132+
// StartProfilingServerWithDefaultHandlers forwards the call to StartProfilingServer
130133
// Also registers:
131134
// 1. the prometheus HTTP handler on '/metrics' path shared with the profiling server.
132135
// 2. A healthcheck (L7) handler on '/healthcheck'.
133136
// 3. A version handler on '/version' provides information about the specific build.
134137
// 4. A config handler on '/config' provides a dump of the currently loaded config.
135138
func StartProfilingServerWithDefaultHandlers(ctx context.Context, pprofPort int, handlers map[string]http.Handler) error {
136-
if err := configureGlobalHTTPHandler(handlers); err != nil {
139+
cfg := GetConfig()
140+
if err := configureGlobalHTTPHandler(cfg, handlers); err != nil {
137141
return err
138142
}
139143

flytestdlib/profutils/server_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type TestObj struct {
3636
}
3737

3838
func init() {
39-
if err := configureGlobalHTTPHandler(nil); err != nil {
39+
if err := configureGlobalHTTPHandler(&Config{}, nil); err != nil {
4040
panic(err)
4141
}
4242
}
@@ -77,6 +77,9 @@ func TestConfigHandler(t *testing.T) {
7777
"type": "json",
7878
},
7979
},
80+
"prof": map[string]interface{}{
81+
"DisableConfigEndpoint": false,
82+
},
8083
}, m)
8184
}
8285

0 commit comments

Comments
 (0)