Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve /health endpoint informations #7

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 13 additions & 5 deletions cmd/uptime-tracker/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (
"log/syslog"
"os"
"strings"
"time"

"github.com/SkycoinPro/skywire-services/internal/pg"
"github.com/SkycoinPro/skywire-services/internal/utmetrics"
"github.com/SkycoinPro/skywire-services/pkg/uptime-tracker/api"
"github.com/SkycoinPro/skywire-services/pkg/uptime-tracker/store"
logrussyslog "github.com/sirupsen/logrus/hooks/syslog"
"github.com/skycoin/dmsg/pkg/direct"
"github.com/skycoin/dmsg/pkg/dmsg"
"github.com/skycoin/dmsg/pkg/dmsghttp"
"github.com/skycoin/skywire-ut/internal/pg"
"github.com/skycoin/skywire-ut/internal/utmetrics"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/api"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/store"
"github.com/spf13/cobra"
"gorm.io/gorm"

Expand Down Expand Up @@ -204,10 +205,17 @@ var rootCmd = &cobra.Command{

defer closeDmsgDC()

go func() {
for {
utAPI.DmsgServers = dmsgDC.ConnectedServersPK()
time.Sleep(time.Second)
}
}()

go dmsghttp.UpdateServers(ctx, dClient, dmsgDisc, dmsgDC, logger)

go func() {
if err := dmsghttp.ListenAndServe(ctx, pk, sk, utAPI, dClient, dmsg.DefaultDmsgHTTPPort, config, dmsgDC, logger); err != nil {
if err := dmsghttp.ListenAndServe(ctx, sk, utAPI, dClient, dmsg.DefaultDmsgHTTPPort, dmsgDC, logger); err != nil {
logger.Errorf("dmsghttp.ListenAndServe utAPI: %v", err)
cancel()
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/uptime-tracker/uptime-tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
package main

import (
"github.com/SkycoinPro/skywire-services/cmd/uptime-tracker/commands"
"github.com/skycoin/skywire-ut/cmd/uptime-tracker/commands"
)

func main() {
Expand Down
22 changes: 11 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/SkycoinPro/skywire-services
module github.com/skycoin/skywire-ut

go 1.17
go 1.21

require (
github.com/go-chi/chi/v5 v5.0.8-0.20220103230436-7dbe9a0bd10f
github.com/go-chi/httprate v0.4.0
github.com/go-echarts/go-echarts/v2 v2.2.4
github.com/sirupsen/logrus v1.8.1
github.com/skycoin/dmsg v1.2.1-0.20221225152341-8062711bcd6e
github.com/skycoin/skywire-utilities v0.0.0-20230314131305-bdd8e27cbd46
github.com/skycoin/dmsg v1.3.12-0.20231130180155-65d707cd1b01
github.com/skycoin/skywire-utilities v0.0.0-20231120175000-12be4345eb26
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
gorm.io/driver/postgres v1.3.8
gorm.io/gorm v1.23.8
)
Expand All @@ -21,6 +21,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
Expand All @@ -35,7 +36,7 @@ require (
github.com/json-iterator/go v1.1.12 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -44,14 +45,13 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/skycoin/noise v0.0.0-20180327030543-2492fe189ae6 // indirect
github.com/skycoin/skycoin v0.27.1 // indirect
github.com/skycoin/yamux v0.0.0-20200803175205-571ceb89da9f // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

Expand Down
774 changes: 31 additions & 743 deletions go.sum

Large diffs are not rendered by default.

24 changes: 14 additions & 10 deletions pkg/uptime-tracker/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import (
"sync"
"time"

"github.com/SkycoinPro/skywire-services/internal/utmetrics"
"github.com/SkycoinPro/skywire-services/pkg/uptime-tracker/store"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/httprate"
"github.com/go-echarts/go-echarts/v2/charts"
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/sirupsen/logrus"
"github.com/skycoin/skywire-ut/internal/utmetrics"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/store"

"github.com/skycoin/skywire-utilities/pkg/buildinfo"
"github.com/skycoin/skywire-utilities/pkg/cipher"
Expand Down Expand Up @@ -58,7 +58,8 @@ type API struct {
storeUptimesCutoff int
storeUptimesPath string

dmsgAddr string
dmsgAddr string
DmsgServers []string
}

// PrivateAPI register all the PrivateAPI endpoints.
Expand All @@ -71,9 +72,10 @@ type PrivateAPI struct {

// HealthCheckResponse is struct of /health endpoint
type HealthCheckResponse struct {
BuildInfo *buildinfo.Info `json:"build_info,omitempty"`
StartedAt time.Time `json:"started_at,omitempty"`
DmsgAddr string `json:"dmsg_address,omitempty"`
BuildInfo *buildinfo.Info `json:"build_info,omitempty"`
StartedAt time.Time `json:"started_at,omitempty"`
DmsgAddr string `json:"dmsg_address,omitempty"`
DmsgServers []string `json:"dmsg_servers,omitempty"`
}

// New constructs a new API instance.
Expand All @@ -92,6 +94,7 @@ func New(log logrus.FieldLogger, s store.Store, nonceStore httpauth.NonceStore,
storeUptimesCutoff: storeDataCutoff,
storeUptimesPath: storeDataPath,
dmsgAddr: dmsgAddr,
DmsgServers: []string{},
}

r := chi.NewRouter()
Expand Down Expand Up @@ -344,7 +347,7 @@ func (api *API) handleVisors(w http.ResponseWriter, r *http.Request) {
}
}

func sendGone(w http.ResponseWriter, r *http.Request) {
func sendGone(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusGone)
}

Expand Down Expand Up @@ -554,9 +557,10 @@ func (api *API) handleUptime(w http.ResponseWriter, r *http.Request) {
func (api *API) health(w http.ResponseWriter, r *http.Request) {
info := buildinfo.Get()
api.writeJSON(w, r, http.StatusOK, HealthCheckResponse{
BuildInfo: info,
StartedAt: api.startedAt,
DmsgAddr: api.dmsgAddr,
BuildInfo: info,
StartedAt: api.startedAt,
DmsgAddr: api.dmsgAddr,
DmsgServers: api.DmsgServers,
})
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/uptime-tracker/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"net/http/httptest"
"testing"

"github.com/SkycoinPro/skywire-services/internal/utmetrics"
"github.com/SkycoinPro/skywire-services/pkg/uptime-tracker/store"
"github.com/skycoin/skywire-ut/internal/utmetrics"
"github.com/skycoin/skywire-ut/pkg/uptime-tracker/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down
4 changes: 2 additions & 2 deletions pkg/uptime-tracker/store/memory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewMemoryStore() Store {
}
}

func (s *memStore) UpdateUptime(pk, ip, version string) error {
func (s *memStore) UpdateUptime(pk, ip, _ string) error {
s.mu.Lock()
defer s.mu.Unlock()

Expand Down Expand Up @@ -249,6 +249,6 @@ func (s *memStore) GetOldestEntry() (DailyUptimeHistory, error) {
return DailyUptimeHistory{}, nil
}

func (s *memStore) GetSpecificDayData(time time.Time) ([]DailyUptimeHistory, error) {
func (s *memStore) GetSpecificDayData(_ time.Time) ([]DailyUptimeHistory, error) {
return []DailyUptimeHistory{}, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading