Skip to content

Commit

Permalink
Add configurable config endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Icikowski committed Jan 12, 2022
1 parent 97925bf commit 90e3ac6
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
9 changes: 6 additions & 3 deletions application/common/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ var (
// HealthchecksPort determines the port number on which liveness & readiness endpoints will be running (defaults to 8081)
HealthchecksPort = getIntegerFromEnvironment("GPTS_HEALTHCHECKS_PORT", 8081)

// DefaultConfigOnStartup determines if default config should be loaded when application starts
// ConfigurationEndpoint determines the path of the configuration endpoint (defaults to /config)
ConfigurationEndpoint = getStringFromEnvironment("GPTS_CONFIG_ENDPOINT", "/config")

// DefaultConfigOnStartup determines if default config should be loaded when application starts (defaults to false)
DefaultConfigOnStartup = getBooleanFromEnvironment("GPTS_DEFAULT_CONFIG_ON_STARTUP", false)

// PrettyLog determines if pretty logging should be enabled
// PrettyLog determines if pretty logging should be enabled (defaults to false)
PrettyLog = getBooleanFromEnvironment("GPTS_PRETTY_LOG", false)

// LogLevel determines the level of application log
// LogLevel determines the level of application log (defaults to "info")
LogLevel = getStringFromEnvironment("GPTS_LOG_LEVEL", "info")
)
6 changes: 4 additions & 2 deletions application/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
func init() {
flag.IntVar(&common.ServicePort, "service-port", common.ServicePort, "Port on which the service will be running")
flag.IntVar(&common.HealthchecksPort, "health-port", common.HealthchecksPort, "Port on which the healthchecks will be running")
flag.StringVar(&common.ConfigurationEndpoint, "config-endpoint", common.ConfigurationEndpoint, "Path of the configuration endpoint")
flag.BoolVar(&common.DefaultConfigOnStartup, "default-config", common.DefaultConfigOnStartup, "Enables loading the default configuration on startup")
flag.BoolVar(&common.PrettyLog, "pretty-log", common.PrettyLog, "Enables the pretty logger")
flag.StringVar(&common.LogLevel, "log-level", common.LogLevel, "Global log level; one of [debug, info, warn, error, fatal, panic, trace]")
Expand All @@ -39,7 +40,8 @@ func main() {
l.Info().
Int("servicePort", common.ServicePort).
Int("healthchecksPort", common.HealthchecksPort).
Msg("starting application")
Str("configurationEndpoint", common.ConfigurationEndpoint).
Msg("starting application with provided configuration")

healthServer := health.PrepareHealthEndpoints(log, common.HealthchecksPort)
go func() {
Expand All @@ -62,7 +64,7 @@ func main() {
health.ServiceStatus.SetStatus(true)
if err := server.ListenAndServe(); err != nil {
if service.ExpectingShutdown && err == http.ErrServerClosed {
l.Info().Msg("service has been shut down for planned maintenance")
l.Info().Msg("service has been shut down for configuration change")
} else {
l.Fatal().Err(err).Msg("service has been shut down unexpectedly")
}
Expand Down
2 changes: 1 addition & 1 deletion application/service/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func PrepareServer(log zerolog.Logger, port int) *http.Server {
Addr: fmt.Sprintf(":%d", port),
}

r.HandleFunc("/config", getConfigHandlerFunction(l, server))
r.HandleFunc(common.ConfigurationEndpoint, getConfigHandlerFunction(l, server))

entries := config.CurrentConfiguration.GetConfiguration()
sortedRoutes := getSortedRoutes(entries)
Expand Down
2 changes: 1 addition & 1 deletion application/service/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getConfigHandlerFunction(log zerolog.Logger, server *http.Server) func(w ht
Dict(
"endpoint",
zerolog.Dict().
Str("path", "/config").
Str("path", common.ConfigurationEndpoint).
Str("type", "builtin"),
).
Logger()
Expand Down
2 changes: 2 additions & 0 deletions chart/gpts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ spec:
value: {{ .Values.gpts.servicePort | default 8080 | quote }}
- name: GPTS_HEALTHCHECKS_PORT
value: {{ .Values.gpts.healthchecksPort | default 8081 | quote }}
- name: GPTS_CONFIG_ENDPOINT
value: {{ .Values.gpts.configEndpoint | default "/config" | quote }}
- name: GPTS_DEFAULT_CONFIG_ON_STARTUP
value: {{ .Values.gpts.defaultConfigOnStartup | default "false" | quote }}
- name: GPTS_LOG_LEVEL
Expand Down
1 change: 1 addition & 0 deletions chart/gpts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ overrides:
gpts:
servicePort: 8080
healthchecksPort: 8081
configEndpoint: /config
defaultConfigOnStartup: false
logLevel: info
prettyLog: false
Expand Down

0 comments on commit 90e3ac6

Please sign in to comment.