Skip to content

Commit

Permalink
Make admin listener configurable (#3520)
Browse files Browse the repository at this point in the history
* Make admin listener configurable

Admin listener is made configurable by adding `admin_enabled`.
It is enabled by default.
Making it configurable allows a host company to not run the listener
on admin port if they desire to do so.

* move Enabled to a separate Admin struct
  • Loading branch information
maditya committed Mar 25, 2024
1 parent 94148bf commit a6267d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Configuration struct {
UnixSocketName string `mapstructure:"unix_socket_name"`
Client HTTPClient `mapstructure:"http_client"`
CacheClient HTTPClient `mapstructure:"http_client_cache"`
Admin Admin `mapstructure:"admin"`
AdminPort int `mapstructure:"admin_port"`
Compression Compression `mapstructure:"compression"`
// GarbageCollectorThreshold allocates virtual memory (in bytes) which is not used by PBS but
Expand Down Expand Up @@ -102,6 +103,9 @@ type Configuration struct {
PriceFloors PriceFloors `mapstructure:"price_floors"`
}

type Admin struct {
Enabled bool `mapstructure:"enabled"`
}
type PriceFloors struct {
Enabled bool `mapstructure:"enabled"`
Fetcher PriceFloorFetcher `mapstructure:"fetcher"`
Expand Down Expand Up @@ -884,6 +888,7 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.SetDefault("unix_socket_enable", false) // boolean which decide if the socket-server will be started.
v.SetDefault("unix_socket_name", "prebid-server.sock") // path of the socket's file which must be listened.
v.SetDefault("admin_port", 6060)
v.SetDefault("admin.enabled", true) // boolean to determine if admin listener will be started.
v.SetDefault("garbage_collector_threshold", 0)
v.SetDefault("status_response", "")
v.SetDefault("datacenter", "")
Expand Down
20 changes: 11 additions & 9 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
stopPrometheus := make(chan os.Signal)
done := make(chan struct{})

adminServer := newAdminServer(cfg, adminHandler)
go shutdownAfterSignals(adminServer, stopAdmin, done)

if cfg.UnixSocketEnable && len(cfg.UnixSocketName) > 0 { // start the unix_socket server if config enable-it.
var (
socketListener net.Listener
Expand All @@ -56,12 +53,17 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
go runServer(mainServer, "Main", mainListener)
}

var adminListener net.Listener
if adminListener, err = newTCPListener(adminServer.Addr, nil); err != nil {
glog.Errorf("Error listening for TCP connections on %s: %v for admin server", adminServer.Addr, err)
return
if cfg.Admin.Enabled {
adminServer := newAdminServer(cfg, adminHandler)
go shutdownAfterSignals(adminServer, stopAdmin, done)

var adminListener net.Listener
if adminListener, err = newTCPListener(adminServer.Addr, nil); err != nil {
glog.Errorf("Error listening for TCP connections on %s: %v for admin server", adminServer.Addr, err)
return
}
go runServer(adminServer, "Admin", adminListener)
}
go runServer(adminServer, "Admin", adminListener)

if cfg.Metrics.Prometheus.Port != 0 {
var (
Expand All @@ -70,7 +72,7 @@ func Listen(cfg *config.Configuration, handler http.Handler, adminHandler http.H
)
go shutdownAfterSignals(prometheusServer, stopPrometheus, done)
if prometheusListener, err = newTCPListener(prometheusServer.Addr, nil); err != nil {
glog.Errorf("Error listening for TCP connections on %s: %v for prometheus server", adminServer.Addr, err)
glog.Errorf("Error listening for TCP connections on %s: %v for prometheus server", prometheusServer.Addr, err)
return
}

Expand Down

0 comments on commit a6267d7

Please sign in to comment.