diff --git a/cmd/uptime-tracker/commands/root.go b/cmd/uptime-tracker/commands/root.go index 2cffc26..66dd64b 100644 --- a/cmd/uptime-tracker/commands/root.go +++ b/cmd/uptime-tracker/commands/root.go @@ -54,6 +54,7 @@ var ( testing bool dmsgDisc string sk cipher.SecKey + dmsgPort uint16 storeDataCutoff int storeDataPath string ) @@ -77,6 +78,7 @@ func init() { rootCmd.Flags().BoolVarP(&testing, "testing", "t", false, "enable testing to start without redis") rootCmd.Flags().StringVar(&dmsgDisc, "dmsg-disc", "http://dmsgd.skywire.skycoin.com", "url of dmsg-discovery") rootCmd.Flags().Var(&sk, "sk", "dmsg secret key") + rootCmd.Flags().Uint16Var(&dmsgPort, "dmsgPort", dmsg.DefaultDmsgHTTPPort, "dmsg port value\r") } var rootCmd = &cobra.Command{ @@ -156,8 +158,13 @@ var rootCmd = &cobra.Command{ m = utmetrics.NewVictoriaMetrics() } + var dmsgAddr string + if !pk.Null() { + dmsgAddr = fmt.Sprintf("%s:%d", pk.Hex(), dmsgPort) + } + enableMetrics := metricsAddr != "" - utAPI := api.New(logger, s, nonceStore, locDetails, enableLoadTesting, enableMetrics, m, storeDataCutoff, storeDataPath) + utAPI := api.New(logger, s, nonceStore, locDetails, enableLoadTesting, enableMetrics, m, storeDataCutoff, storeDataPath, dmsgAddr) utPAPI := api.NewPrivate(logger, s) diff --git a/pkg/uptime-tracker/api/api.go b/pkg/uptime-tracker/api/api.go index 3ef780f..527e3f2 100644 --- a/pkg/uptime-tracker/api/api.go +++ b/pkg/uptime-tracker/api/api.go @@ -57,6 +57,8 @@ type API struct { dailyUptimeCacheMu sync.RWMutex storeUptimesCutoff int storeUptimesPath string + + dmsgAddr string } // PrivateAPI register all the PrivateAPI endpoints. @@ -71,11 +73,12 @@ type PrivateAPI struct { type HealthCheckResponse struct { BuildInfo *buildinfo.Info `json:"build_info,omitempty"` StartedAt time.Time `json:"started_at,omitempty"` + DmsgAddr string `json:"dmsg_address,omitempty"` } // New constructs a new API instance. func New(log logrus.FieldLogger, s store.Store, nonceStore httpauth.NonceStore, locDetails geo.LocationDetails, - enableLoadTesting, enableMetrics bool, m utmetrics.Metrics, storeDataCutoff int, storeDataPath string) *API { + enableLoadTesting, enableMetrics bool, m utmetrics.Metrics, storeDataCutoff int, storeDataPath, dmsgAddr string) *API { if log == nil { log = logging.MustGetLogger("uptime_tracker") } @@ -88,6 +91,7 @@ func New(log logrus.FieldLogger, s store.Store, nonceStore httpauth.NonceStore, startedAt: time.Now(), storeUptimesCutoff: storeDataCutoff, storeUptimesPath: storeDataPath, + dmsgAddr: dmsgAddr, } r := chi.NewRouter() @@ -552,6 +556,7 @@ func (api *API) health(w http.ResponseWriter, r *http.Request) { api.writeJSON(w, r, http.StatusOK, HealthCheckResponse{ BuildInfo: info, StartedAt: api.startedAt, + DmsgAddr: api.dmsgAddr, }) } diff --git a/pkg/uptime-tracker/api/api_test.go b/pkg/uptime-tracker/api/api_test.go index f5ebca4..f1d06b7 100644 --- a/pkg/uptime-tracker/api/api_test.go +++ b/pkg/uptime-tracker/api/api_test.go @@ -41,7 +41,7 @@ func TestHandleUptimes(t *testing.T) { nonceMock, err := httpauth.NewNonceStore(ctx, storeconfig.Config{Type: storeconfig.Memory}, "") require.NoError(t, err) api := New(nil, mock, nonceMock, geoFunc, false, false, - utmetrics.NewEmpty(), 0, "") + utmetrics.NewEmpty(), 0, "", "") pk, _ := cipher.GenerateKeyPair() @@ -75,7 +75,7 @@ func TestAPI_handleUpdate(t *testing.T) { nonceMock, err := httpauth.NewNonceStore(ctx, storeconfig.Config{Type: storeconfig.Memory}, "") require.NoError(t, err) api := New(nil, mock, nonceMock, geoFunc, false, false, - utmetrics.NewEmpty(), 0, "") + utmetrics.NewEmpty(), 0, "", "") t.Run("StatusOK", func(t *testing.T) { w := httptest.NewRecorder() @@ -106,7 +106,7 @@ func TestApi_UpdateRemovedMethod(t *testing.T) { nonceMock, err := httpauth.NewNonceStore(ctx, storeconfig.Config{Type: storeconfig.Memory}, "") require.NoError(t, err) api := New(nil, mock, nonceMock, geoFunc, false, false, - utmetrics.NewEmpty(), 0, "") + utmetrics.NewEmpty(), 0, "", "") t.Run("StatusGone", func(t *testing.T) { w := httptest.NewRecorder()