Bladeren bron

add debug log for scale test

Max Ma 9 maanden geleden
bovenliggende
commit
f722b8a5be
4 gewijzigde bestanden met toevoegingen van 25 en 5 verwijderingen
  1. 6 0
      controllers/hosts.go
  2. 6 0
      logic/hosts.go
  3. 7 0
      mq/handlers.go
  4. 6 5
      mq/publishers.go

+ 6 - 0
controllers/hosts.go

@@ -319,6 +319,9 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
 	switch hostUpdate.Action {
 	case models.CheckIn:
 		sendPeerUpdate = mq.HandleHostCheckin(&hostUpdate.Host, currentHost)
+		if sendPeerUpdate {
+			slog.Error("sendPeerUpdate from CheckIn", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
+		}
 
 	case models.UpdateHost:
 		if hostUpdate.Host.PublicKey != currentHost.PublicKey {
@@ -326,6 +329,9 @@ func hostUpdateFallback(w http.ResponseWriter, r *http.Request) {
 			replacePeers = true
 		}
 		sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
+		if sendPeerUpdate {
+			slog.Error("sendPeerUpdate from UpdateHost", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
+		}
 		err := logic.UpsertHost(currentHost)
 		if err != nil {
 			slog.Error("failed to update host", "id", currentHost.ID, "error", err)

+ 6 - 0
logic/hosts.go

@@ -243,25 +243,30 @@ func UpdateHost(newHost, currentHost *models.Host) {
 // UpdateHostFromClient - used for updating host on server with update recieved from client
 func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool) {
 	if newHost.PublicKey != currHost.PublicKey {
+		slog.Error("PublicKey changed:", "Debug")
 		currHost.PublicKey = newHost.PublicKey
 		sendPeerUpdate = true
 	}
 	if newHost.ListenPort != 0 && currHost.ListenPort != newHost.ListenPort {
+		slog.Error("ListenPort changed:", "Debug", currHost.ListenPort, newHost.ListenPort)
 		currHost.ListenPort = newHost.ListenPort
 		sendPeerUpdate = true
 	}
 	if newHost.WgPublicListenPort != 0 &&
 		currHost.WgPublicListenPort != newHost.WgPublicListenPort {
+		slog.Error("WgPublicListenPort changed:", "Debug", currHost.WgPublicListenPort, newHost.WgPublicListenPort)
 		currHost.WgPublicListenPort = newHost.WgPublicListenPort
 		sendPeerUpdate = true
 	}
 	isEndpointChanged := false
 	if currHost.EndpointIP.String() != newHost.EndpointIP.String() {
+		slog.Error("EndpointIP changed:", "Debug", currHost.EndpointIP, newHost.EndpointIP)
 		currHost.EndpointIP = newHost.EndpointIP
 		sendPeerUpdate = true
 		isEndpointChanged = true
 	}
 	if currHost.EndpointIPv6.String() != newHost.EndpointIPv6.String() {
+		slog.Error("EndpointIPv6 changed:", "Debug", currHost.EndpointIPv6, newHost.EndpointIPv6)
 		currHost.EndpointIPv6 = newHost.EndpointIPv6
 		sendPeerUpdate = true
 		isEndpointChanged = true
@@ -290,6 +295,7 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
 
 	currHost.Name = newHost.Name
 	if len(newHost.NatType) > 0 && newHost.NatType != currHost.NatType {
+		slog.Error("NatType changed:", "Debug", currHost.NatType, newHost.NatType)
 		currHost.NatType = newHost.NatType
 		sendPeerUpdate = true
 	}

+ 7 - 0
mq/handlers.go

@@ -106,6 +106,10 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
 	switch hostUpdate.Action {
 	case models.CheckIn:
 		sendPeerUpdate = HandleHostCheckin(&hostUpdate.Host, currentHost)
+		if sendPeerUpdate {
+			slog.Error("sendPeerUpdate from UpdateHost.CheckIn", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
+		}
+
 	case models.Acknowledgement:
 		hu := hostactions.GetAction(currentHost.ID.String())
 		if hu != nil {
@@ -129,6 +133,9 @@ func UpdateHost(client mqtt.Client, msg mqtt.Message) {
 			replacePeers = true
 		}
 		sendPeerUpdate = logic.UpdateHostFromClient(&hostUpdate.Host, currentHost)
+		if sendPeerUpdate {
+			slog.Error("sendPeerUpdate from UpdateHost.UpdateHost", "Debug", sendPeerUpdate, &hostUpdate.Host.Name, &hostUpdate.Host.ID)
+		}
 		err := logic.UpsertHost(currentHost)
 		if err != nil {
 			slog.Error("failed to update host", "id", currentHost.ID, "error", err)

+ 6 - 5
mq/publishers.go

@@ -18,16 +18,17 @@ import (
 
 var batchSize = servercfg.GetPeerUpdateBatchSize()
 var batchUpdate = servercfg.GetBatchPeerUpdate()
-var peerUpdateTS = time.Now().Unix()
+
+//var peerUpdateTS = time.Now().Unix()
 
 // PublishPeerUpdate --- determines and publishes a peer update to all the hosts
 func PublishPeerUpdate(replacePeers bool) error {
 	slog.Error("entering PublishPeerUpdate", "Debug")
 	t1 := time.Now().Unix()
-	if time.Now().Unix()-peerUpdateTS < 60 {
-		return nil
-	}
-	peerUpdateTS = time.Now().Unix()
+	//if time.Now().Unix()-peerUpdateTS < 60 {
+	//	return nil
+	//}
+	//peerUpdateTS = time.Now().Unix()
 
 	pc, file, no, ok := runtime.Caller(1)
 	if ok {