less duplicate logs
Some checks failed
Build and Publish / BuildAndDeploy (push) Has been cancelled

This commit is contained in:
matst80
2024-11-10 00:46:35 +01:00
parent 2831e627b8
commit ee9f0e776f
2 changed files with 8 additions and 7 deletions

View File

@@ -86,11 +86,13 @@ func (a *App) HandleSave(w http.ResponseWriter, r *http.Request) {
} }
type PoolServer struct { type PoolServer struct {
pod_name string
pool GrainPool pool GrainPool
} }
func NewPoolServer(pool GrainPool) *PoolServer { func NewPoolServer(pool GrainPool, pod_name string) *PoolServer {
return &PoolServer{ return &PoolServer{
pod_name: pod_name,
pool: pool, pool: pool,
} }
} }
@@ -104,6 +106,7 @@ func (s *PoolServer) HandleGet(w http.ResponseWriter, r *http.Request) {
return return
} }
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Pod-Name", s.pod_name)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write(data) w.Write(data)
} }
@@ -121,6 +124,7 @@ func (s *PoolServer) HandleAddSku(w http.ResponseWriter, r *http.Request) {
return return
} }
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.Header().Set("X-Pod-Name", s.pod_name)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
w.Write(data) w.Write(data)
} }
@@ -186,7 +190,7 @@ func main() {
} }
}() }()
syncedServer := NewPoolServer(syncedPool) syncedServer := NewPoolServer(syncedPool, name)
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/api/", http.StripPrefix("/api", syncedServer.Serve())) mux.Handle("/api/", http.StripPrefix("/api", syncedServer.Serve()))
mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("GET /add/remote/{host}", func(w http.ResponseWriter, r *http.Request) {

View File

@@ -302,11 +302,9 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
case RemoteGrainChanged: case RemoteGrainChanged:
// remote grain changed // remote grain changed
grainSyncCount.Inc() grainSyncCount.Inc()
log.Printf("Remote grain changed\n")
idAndHost := make([]byte, packet.DataLength) idAndHost := make([]byte, packet.DataLength)
_, err = conn.Read(idAndHost) _, err = conn.Read(idAndHost)
log.Printf("Remote grain %s changed\n", idAndHost)
if err != nil { if err != nil {
break break
} }
@@ -328,7 +326,6 @@ func (p *SyncedPool) handleConnection(conn net.Conn) {
if !found { if !found {
log.Printf("Remote host %s not found\n", idAndHostParts[1]) log.Printf("Remote host %s not found\n", idAndHostParts[1])
log.Printf("Remotes %v\n", p.remotes)
} else { } else {
SendPacket(conn, AckChange, func(w io.Writer) error { SendPacket(conn, AckChange, func(w io.Writer) error {
_, err := w.Write([]byte("ok")) _, err := w.Write([]byte("ok"))