From 97294f2d4a98a2e418f4c310337b99189e9a4e57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Renan=20Gon=C3=A7alves?= Date: Thu, 12 Apr 2018 18:23:01 +0200 Subject: [PATCH] Support a custom host for health server Instead of forcing to listen on all interfaces we should give the possibility for the user to make the health server listen on a specific host/ip. --- pkg/config/config_params.go | 6 ++++-- pkg/config/config_params_test.go | 4 ++++ pkg/daemon/daemon.go | 7 +++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pkg/config/config_params.go b/pkg/config/config_params.go index a3dca683..f24d38d1 100644 --- a/pkg/config/config_params.go +++ b/pkg/config/config_params.go @@ -102,8 +102,10 @@ type Config struct { LogSeverityScreen string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"` LogSeveritySys string `config:"oneof(DEBUG,INFO,WARNING,ERROR,CRITICAL);INFO"` - HealthEnabled bool `config:"bool;false"` - HealthPort int `config:"int(0,65535);9098"` + HealthEnabled bool `config:"bool;false"` + HealthHost string `config:"string;localhost"` + HealthPort int `config:"int(0,65535);9098"` + PrometheusMetricsEnabled bool `config:"bool;false"` PrometheusMetricsPort int `config:"int(0,65535);9093"` PrometheusGoMetricsEnabled bool `config:"bool;true"` diff --git a/pkg/config/config_params_test.go b/pkg/config/config_params_test.go index 658f6ed6..80952907 100644 --- a/pkg/config/config_params_test.go +++ b/pkg/config/config_params_test.go @@ -68,6 +68,10 @@ var _ = DescribeTable("Config parsing", Entry("LogSeveritySys", "LogSeveritySys", "error", "ERROR"), Entry("LogSeveritySys", "LogSeveritySys", "critical", "CRITICAL"), + Entry("HealthEnabled", "HealthEnabled", "true", true), + Entry("HealthHost", "HealthHost", "127.0.0.1", "127.0.0.1"), + Entry("HealthPort", "HealthPort", "1234", int(1234)), + Entry("PrometheusMetricsEnabled", "PrometheusMetricsEnabled", "true", true), Entry("PrometheusMetricsPort", "PrometheusMetricsPort", "1234", int(1234)), Entry("PrometheusGoMetricsEnabled", "PrometheusGoMetricsEnabled", "false", false), diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index ae8d9917..01b6041d 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -360,8 +360,11 @@ func (t *TyphaDaemon) Start(cxt context.Context) { } if t.ConfigParams.HealthEnabled { - log.WithField("port", t.ConfigParams.HealthPort).Info("Health enabled. Starting server.") - t.healthAggregator.ServeHTTP(t.ConfigParams.HealthEnabled, "", t.ConfigParams.HealthPort) + log.WithFields(log.Fields{ + "host": t.ConfigParams.HealthHost, + "port": t.ConfigParams.HealthPort, + }).Info("Health enabled. Starting server.") + t.healthAggregator.ServeHTTP(t.ConfigParams.HealthEnabled, t.ConfigParams.HealthHost, t.ConfigParams.HealthPort) } }