Skip to content

Commit

Permalink
Add security measures for metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
joe94 committed Nov 28, 2017
1 parent d888a61 commit 78ccd7f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tr1d1um/tr1d1um.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const (
defaultNetDialerTimeout = "5s"
defaultRetryInterval = "2s"
defaultMaxRetries = 2
defaultMetricsAddress = ":8080"

supportedServicesKey = "supportedServices"
targetURLKey = "targetURL"
Expand All @@ -63,6 +64,7 @@ const (
reqRetryIntervalKey = "requestRetryInterval"
reqMaxRetriesKey = "requestMaxRetries"
respWaitTimeoutKey = "respWaitTimeout"
metricsAddressKey = "metricsAddress"

releaseKey = "release"
)
Expand All @@ -89,6 +91,7 @@ func tr1d1um(arguments []string) (exitCode int) {
v.SetDefault(reqRetryIntervalKey, defaultRetryInterval)
v.SetDefault(reqMaxRetriesKey, defaultMaxRetries)
v.SetDefault(netDialerTimeoutKey, defaultNetDialerTimeout)
v.SetDefault(metricsAddressKey, defaultMetricsAddress)

//release and internal OS info set up
if releaseVal := v.GetString(releaseKey); releaseVal != "" {
Expand Down Expand Up @@ -144,9 +147,9 @@ func tr1d1um(arguments []string) (exitCode int) {
go snsFactory.PrepareAndStart()

// prometheus metrics set up
http.Handle("/metrics", promhttp.Handler())
http.Handle("/metrics", preHandler.Then(promhttp.Handler()))
go func() {
if prometheusEndpointErr := http.ListenAndServe(":8080", nil); prometheusEndpointErr != nil {
if prometheusEndpointErr := http.ListenAndServe(v.GetString(metricsAddressKey), nil); prometheusEndpointErr != nil {
errorLogger.Log(logging.MessageKey(), "error with prometheus endpoint", logging.ErrorKey(), prometheusEndpointErr)
}
}()
Expand Down

0 comments on commit 78ccd7f

Please sign in to comment.