Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow disabling profiling endpoints #2195

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions config/flipt.schema.cue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import "strings"
authentication?: #authentication
cache?: #cache
cors?: #cors
diagnostics?: #diagnostics
storage?: #storage
db?: #db
log?: #log
Expand Down Expand Up @@ -121,6 +122,12 @@ import "strings"
allowed_origins?: [...] | string | *["*"]
}

#diagnostics: {
profiling?: {
enabled?: bool | *true
}
}

#storage: {
type: "database" | "git" | "local" | "object" | *""
local?: path: string | *"."
Expand Down
21 changes: 21 additions & 0 deletions config/flipt.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"db": {
"$ref": "#/definitions/db"
},
"diagnostics": {
"$ref": "#/definitions/diagnostics"
},
"storage": {
"$ref": "#/definitions/storage"
},
Expand Down Expand Up @@ -397,6 +400,24 @@
"required": [],
"title": "Cors"
},
"diagnostics": {
"type": "object",
"additionalProperties": false,
"properties": {
"profiling": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"default": true
}
}
}
},
"required": [],
"title": "Diagnostics"
},
"db": {
"type": "object",
"additionalProperties": false,
Expand Down
6 changes: 5 additions & 1 deletion internal/cmd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@
})
r.Use(middleware.Compress(gzip.DefaultCompression))
r.Use(middleware.Recoverer)
r.Mount("/debug", middleware.Profiler())

if cfg.Diagnostics.Profiling.Enabled {
r.Mount("/debug", middleware.Profiler())
}

Check warning on line 114 in internal/cmd/http.go

View check run for this annotation

Codecov / codecov/patch

internal/cmd/http.go#L111-L114

Added lines #L111 - L114 were not covered by tests

r.Mount("/metrics", promhttp.Handler())

r.Group(func(r chi.Router) {
Expand Down
21 changes: 14 additions & 7 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,19 @@ var DecodeHooks = []mapstructure.DecodeHookFunc{
// any errors derived from the resulting state of the configuration.
type Config struct {
Version string `json:"version,omitempty" mapstructure:"version,omitempty" yaml:"version,omitempty"`
Audit AuditConfig `json:"audit,omitempty" mapstructure:"audit" yaml:"audit,omitempty"`
Authentication AuthenticationConfig `json:"authentication,omitempty" mapstructure:"authentication" yaml:"authentication,omitempty"`
Cache CacheConfig `json:"cache,omitempty" mapstructure:"cache" yaml:"cache,omitempty"`
Cors CorsConfig `json:"cors,omitempty" mapstructure:"cors" yaml:"cors,omitempty"`
Database DatabaseConfig `json:"db,omitempty" mapstructure:"db" yaml:"db,omitempty"`
Diagnostics DiagnosticConfig `json:"diagnostics,omitempty" mapstructure:"diagnostics" yaml:"diagnostics,omitempty"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the only addition, the rest were just re-organized in alphabetical order

Experimental ExperimentalConfig `json:"experimental,omitempty" mapstructure:"experimental" yaml:"experimental,omitempty"`
Log LogConfig `json:"log,omitempty" mapstructure:"log" yaml:"log,omitempty"`
UI UIConfig `json:"ui,omitempty" mapstructure:"ui" yaml:"ui,omitempty"`
Cors CorsConfig `json:"cors,omitempty" mapstructure:"cors" yaml:"cors,omitempty"`
Cache CacheConfig `json:"cache,omitempty" mapstructure:"cache" yaml:"cache,omitempty"`
Meta MetaConfig `json:"meta,omitempty" mapstructure:"meta" yaml:"meta,omitempty"`
Server ServerConfig `json:"server,omitempty" mapstructure:"server" yaml:"server,omitempty"`
Storage StorageConfig `json:"storage,omitempty" mapstructure:"storage" yaml:"storage,omitempty"`
Tracing TracingConfig `json:"tracing,omitempty" mapstructure:"tracing" yaml:"tracing,omitempty"`
Database DatabaseConfig `json:"db,omitempty" mapstructure:"db" yaml:"db,omitempty"`
Meta MetaConfig `json:"meta,omitempty" mapstructure:"meta" yaml:"meta,omitempty"`
Authentication AuthenticationConfig `json:"authentication,omitempty" mapstructure:"authentication" yaml:"authentication,omitempty"`
Audit AuditConfig `json:"audit,omitempty" mapstructure:"audit" yaml:"audit,omitempty"`
UI UIConfig `json:"ui,omitempty" mapstructure:"ui" yaml:"ui,omitempty"`
}

type Result struct {
Expand Down Expand Up @@ -469,6 +470,12 @@ func Default() *Config {
},
},

Diagnostics: DiagnosticConfig{
Profiling: ProfilingDiagnosticConfig{
Enabled: true,
},
},

Server: ServerConfig{
Host: "0.0.0.0",
Protocol: HTTP,
Expand Down
24 changes: 24 additions & 0 deletions internal/config/diagnostics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package config

import "github.com/spf13/viper"

// cheers up the unparam linter
var _ defaulter = (*DiagnosticConfig)(nil)

type DiagnosticConfig struct {
Profiling ProfilingDiagnosticConfig `json:"profiling,omitempty" mapstructure:"profiling" yaml:"profiling,omitempty"`
}

type ProfilingDiagnosticConfig struct {
Enabled bool `json:"enabled,omitempty" mapstructure:"enabled" yaml:"enabled,omitempty"`
}

func (c *DiagnosticConfig) setDefaults(v *viper.Viper) error {
v.SetDefault("diagnostics", map[string]any{
"profiling": map[string]any{
"enabled": true,
},
})

return nil
}
5 changes: 4 additions & 1 deletion internal/config/testdata/marshal/yaml/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ ui:
cors:
enabled: false
allowed_origins:
- '*'
- "*"
server:
host: 0.0.0.0
http_port: 8080
https_port: 443
grpc_port: 9000
storage:
type: database
diagnostics:
profiling:
enabled: true
db:
url: file:/tmp/flipt/flipt.db
max_idle_conn: 2
Expand Down
Loading