Skip to content

Commit

Permalink
Add a way to see the payload if config is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
alinz committed May 26, 2024
1 parent 5907bb5 commit 5dd76b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"log/slog"
"math/rand"
"net/http"
Expand Down Expand Up @@ -161,8 +162,13 @@ func (s *Server) pingContainers() {
defer rc.Close()

config := Config{}
if err := json.NewDecoder(rc).Decode(&config); err != nil {
slog.Error("failed to decode container config", "container_id", c.Id, "url", url, "error", err)
payload, err := io.ReadAll(rc)
if err != nil {
slog.Error("failed to read container config", "container_id", c.Id, "url", url, "error", err)
return
}
if err := json.Unmarshal(payload, &config); err != nil {
slog.Error("failed to decode container config", "container_id", c.Id, "url", url, "error", err, "payload", string(payload))
return
}

Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func createDummyContainer(t *testing.T, config *baker.Config) *baker.Container {
slog.Debug("request", "host", r.Host, "path", r.URL.Path)

if r.URL.Path == "/config" {

b, err := json.Marshal(config)
if err != nil {
t.Fatal(err)
}
w.WriteHeader(http.StatusOK)
w.Write(b)
return
}

w.WriteHeader(http.StatusOK)
Expand Down

0 comments on commit 5dd76b6

Please sign in to comment.