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

Net 1165 #839

Merged
merged 2 commits into from
Jul 1, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions functions/mqhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/devilcove/httpclient"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/gravitl/netclient/auth"
"github.com/gravitl/netclient/cache"
"github.com/gravitl/netclient/config"
"github.com/gravitl/netclient/daemon"
Expand Down Expand Up @@ -471,38 +470,32 @@ func handleFwUpdate(server string, payload *models.FwUpdate) {
}

func getServerBrokerStatus() (bool, error) {
type status struct {
Broker bool `json:"broker_connected"`
}

server := config.GetServer(config.CurrServer)
if server == nil {
return false, errors.New("server is nil")
}
token, err := auth.Authenticate(server, config.Netclient())
if err != nil {
logger.Log(1, "failed to authenticate when publishing metrics", err.Error())
return false, err
}
var status map[string]interface{}
url := fmt.Sprintf("https://%s/api/server/status", server.API)
endpoint := httpclient.JSONEndpoint[status, models.ErrorResponse]{
endpoint := httpclient.JSONEndpoint[map[string]interface{}, models.ErrorResponse]{
URL: url,
Method: http.MethodGet,
Authorization: "Bearer " + token,
Data: nil,
Response: status{},
Response: status,
ErrorResponse: models.ErrorResponse{},
}
response, errData, err := endpoint.GetJSON(status{}, models.ErrorResponse{})
response, _, err := endpoint.GetJSON(status, models.ErrorResponse{})
if err != nil {
if errors.Is(err, httpclient.ErrStatus) {
logger.Log(0, "status error calling ", endpoint.URL, errData.Message)
return false, err
}

logger.Log(1, "failed to read from server during metrics publish", err.Error())
return false, err
}
return response.Broker, nil

if _, ok := response["is_broker_conn_open"]; ok {
return response["is_broker_conn_open"].(bool), nil
}

return response["broker_connected"].(bool), nil
}

// MQTT Fallback Mechanism
Expand Down
16 changes: 6 additions & 10 deletions functions/mqpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) {
defer ipTicker.Stop()
checkinTicker := time.NewTicker(time.Minute * 4)
defer checkinTicker.Stop()
metricTicker := time.NewTicker(time.Minute * 5)
metricTicker := time.NewTicker(time.Minute * 10)
defer metricTicker.Stop()
for {
select {
Expand Down Expand Up @@ -76,7 +76,11 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) {
}
if Mqclient == nil || !Mqclient.IsConnectionOpen() {
slog.Warn("MQ client is not connected, using fallback checkin for server", config.CurrServer)
checkinFallback()
// check/update host settings; publish if changed
if err := UpdateHostSettings(true); err != nil {
logger.Log(0, "failed to update host settings", err.Error())
return
}
continue
}
// check/update host settings; publish if changed
Expand Down Expand Up @@ -108,14 +112,6 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) {
}
}

func checkinFallback() {
// check/update host settings; publish if changed
if err := UpdateHostSettings(true); err != nil {
logger.Log(0, "failed to update host settings", err.Error())
return
}
}

// hostUpdateFallback - used to send host updates to server when there is a mq connection failure
func hostUpdateFallback(hu models.HostUpdate) error {

Expand Down
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/google/nftables v0.1.0
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/gravitl/netmaker v0.24.3-0.20240625152215-73303221bc8e
github.com/gravitl/netmaker v0.24.3-0.20240701040845-d593de2b6ef0
github.com/gravitl/tcping v0.1.2-0.20230801110928-546055ebde06
github.com/gravitl/txeh v0.0.0-20230509181318-3778c58bd69f
github.com/guumaster/hostctl v1.1.4
Expand All @@ -40,21 +40,27 @@ require (

require (
aead.dev/minisign v0.2.0 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/coreos/go-oidc/v3 v3.9.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v23.0.5+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-jose/go-jose/v3 v3.0.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -80,6 +86,7 @@ require (
github.com/rqlite/gorqlite v0.0.0-20240122221808-a8a425b1a6aa // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand All @@ -91,6 +98,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/oauth2 v0.21.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
Expand Down
Loading