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

add debug printout for orchestrator #5

Merged
merged 1 commit into from
Apr 3, 2025
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@

# Dotenv environment variables file
.env

experiment/
8 changes: 8 additions & 0 deletions orchestrator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ To generate many keys from a single originating key, use the following action:
When no `password-env` is provided, empty password will be used to decode the originating private key (`./root-key`)
and to encode new private keys (`./keys/key-0`, `./keys/key-1` ...).

## Debug Printout

You can enable debug printout of graphql requests by adding

`"printRequests":"true"`

in config.json **and** set `"logLevel":"debug"` or lower

## Build from sources

- Make sure you have `Go v1.20+` installed.
Expand Down
1 change: 1 addition & 0 deletions orchestrator/src/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Config struct {
StopDaemonDelaySec int
FundDaemonPorts []string
UrlOverrides []string
PrintRequests bool
}

type OutputF = func(name string, value any, multiple bool, sensitive bool)
Expand Down
7 changes: 6 additions & 1 deletion orchestrator/src/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ var _ graphql.Doer = (*SequentialAuthenticator)(nil)

func NewGqlClient(config Config, addr NodeAddress) (*NodeEntry, error) {
url := "http://" + string(addr) + "/graphql"
authenticator := NewAuthenticator(config.Sk, http.DefaultClient)
httpClient := http.DefaultClient
if config.PrintRequests {
rt := RoundTripper{logger: config.Log}
httpClient = &http.Client{Transport: rt}
}
authenticator := NewAuthenticator(config.Sk, httpClient)
authClient := graphql.NewClient(url, authenticator)
resp, err := auth(config.Ctx, authClient)
if err != nil {
Expand Down
36 changes: 36 additions & 0 deletions orchestrator/src/http_roundtripper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package itn_orchestrator

import (
"net/http"

logging "github.com/ipfs/go-log/v2"
)

type RoundTripper struct {
logger logging.StandardLogger
}

func (t RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
body, err := readBody(req)
if err != nil {
return nil, err
}
reqBodyString := string(body)

var headers string
for name, values := range req.Header {
for _, value := range values {
headers += "\tHeaders: " + name + ": " + value + "\n"
}
}
t.logger.Debugf("RoundTripper: %s %s %s\nHeaders: %s", req.Method, req.URL, reqBodyString, headers)

resp, err := http.DefaultTransport.RoundTrip(req)
if err != nil {
return resp, err
}

t.logger.Debugf("RoundTripper: %s %s %s", resp.Status, resp.Request.Method, resp.Request.URL)

return resp, err
}
2 changes: 2 additions & 0 deletions orchestrator/src/itn_orchestrator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type AppConfig struct {
GenesisTimestamp itn_json_types.Time
ControlExec string `json:",omitempty"`
UrlOverrides []string `json:",omitempty"`
PrintRequests bool `json:"printRequests,omitempty"`
}

func (config *AwsConfig) GetBucketName() string {
Expand Down Expand Up @@ -227,6 +228,7 @@ func main() {
ControlExec: appConfig.ControlExec,
OnlineURL: appConfig.OnlineURL,
UrlOverrides: appConfig.UrlOverrides,
PrintRequests: appConfig.PrintRequests,
}
if config.MinaExec == "" {
config.MinaExec = "mina"
Expand Down