Skip to content

Commit

Permalink
Dump container logs when it fails to become ready
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick committed Apr 30, 2024
1 parent 8c4b671 commit b922098
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/trinodb/trino-go-client
go 1.21

require (
github.com/ahmetb/dlog v0.0.0-20170105205344-4fb5f8204f26
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/ory/dockertest/v3 v3.10.0
github.com/stretchr/testify v1.9.0
Expand All @@ -14,6 +15,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect
github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/containerd/continuity v0.4.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw=
github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5/go.mod h1:lmUJ/7eu/Q8D7ML55dXQrVaamCz2vxCfdQBasLZfHKk=
github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26 h1:pzStYMLAXM7CNQjS/Wn+zK9MUxDhSUNfVvnHsyQyjs0=
github.com/ahmetalpbalkan/dlog v0.0.0-20170105205344-4fb5f8204f26/go.mod h1:ilK+u7u1HoqaDk0mjhh27QJB7PyWMreGffEvOCoEKiY=
github.com/ahmetb/dlog v0.0.0-20170105205344-4fb5f8204f26 h1:3YVZUqkoev4mL+aCwVOSWV4M7pN+NURHL38Z2zq5JKA=
github.com/ahmetb/dlog v0.0.0-20170105205344-4fb5f8204f26/go.mod h1:ymXt5bw5uSNu4jveerFxE0vNYxF8ncqbptntMaFMg3k=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8=
Expand Down
2 changes: 1 addition & 1 deletion trino/etc/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ http-server.authentication.jwt.key-file=/etc/trino/secrets/public_key.pem
http-server.https.enabled=true
http-server.https.port=8443
http-server.authentication.allow-insecure-over-http=true
http-server.https.keystore.path=/etc/trino/secrets/certificate_with_key.pem
http-server.https.keystore.path=/etc/trino/secrets/xcertificate_with_key.pem
internal-communication.shared-secret=gotrino
20 changes: 19 additions & 1 deletion trino/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package trino

import (
"bytes"
"context"
"crypto/rand"
"crypto/rsa"
Expand All @@ -36,8 +37,10 @@ import (
"testing"
"time"

"github.com/ahmetb/dlog"
"github.com/golang-jwt/jwt/v4"
dt "github.com/ory/dockertest/v3"
docker "github.com/ory/dockertest/v3/docker"
)

var (
Expand Down Expand Up @@ -121,7 +124,8 @@ func TestMain(m *testing.M) {
}
return nil
}); err != nil {
log.Fatalf("Timed out waiting for container to get ready: %s", err)
logs := getLogs(resource.Container.ID)
log.Fatalf("Timed out waiting for container to get ready: %s\nContainer logs:\n%s", err, logs)
}
*integrationServerFlag = "http://test@localhost:" + resource.GetPort("8080/tcp")
tlsServer = "https://test@localhost:" + resource.GetPort("8443/tcp")
Expand Down Expand Up @@ -263,6 +267,20 @@ func getTLSConfig(dir string) (*tls.Config, error) {
}, nil
}

func getLogs(id string) []byte {
var buf bytes.Buffer
pool.Client.Logs(docker.LogsOptions{
Container: id,
OutputStream: &buf,
ErrorStream: &buf,
Stdout: true,
Stderr: true,
RawTerminal: true,
})
logs, _ := io.ReadAll(dlog.NewReader(&buf))
return logs
}

// integrationOpen opens a connection to the integration test server.
func integrationOpen(t *testing.T, dsn ...string) *sql.DB {
if testing.Short() {
Expand Down

0 comments on commit b922098

Please sign in to comment.