Skip to content

Commit

Permalink
pkg/util/cluster: Add logging for MS Graph requests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarnes committed Apr 15, 2022
1 parent 8e178b7 commit f8f344f
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 2 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ require (
github.com/jstemmer/go-junit-report v1.0.0
github.com/microsoft/kiota-authentication-azure-go v0.1.0
github.com/microsoftgraph/msgraph-sdk-go v0.19.0
github.com/microsoftgraph/msgraph-sdk-go-core v0.22.0
github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
github.com/openshift/api v0.0.0-20210831091943-07e756545ac1
Expand Down Expand Up @@ -247,7 +249,6 @@ require (
github.com/microsoft/kiota-http-go v0.2.0 // indirect
github.com/microsoft/kiota-serialization-json-go v0.2.1 // indirect
github.com/microsoft/kiota-serialization-text-go v0.1.0 // indirect
github.com/microsoftgraph/msgraph-sdk-go-core v0.22.0 // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
Expand All @@ -259,6 +260,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/moricho/tparallel v0.2.1 // indirect
github.com/motemen/go-nuts v0.0.0-20210915132349-615a782f2c69 // indirect
github.com/mtrmac/gpgme v0.1.2 // indirect
github.com/nakabonne/nestif v0.3.1 // indirect
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 // indirect
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,10 @@ github.com/moricho/tparallel v0.2.1 h1:95FytivzT6rYzdJLdtfn6m1bfFJylOJK41+lgv/EH
github.com/moricho/tparallel v0.2.1/go.mod h1:fXEIZxG2vdfl0ZF8b42f5a78EhjjD5mX8qUplsoSU4k=
github.com/morikuni/aec v0.0.0-20170113033406-39771216ff4c/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27 h1:uAI3rnOT1OSSY4PUtI/M1orb3q0ewkovwd3wr8xSno4=
github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27/go.mod h1:6eu9CfGt5kfrMVgeu9MfB9PRUnpc47I+udLswiTszI8=
github.com/motemen/go-nuts v0.0.0-20210915132349-615a782f2c69 h1:1KtusfE10/BxzK4Vks+ULP7S63TicyRu6cq86vCRWX8=
github.com/motemen/go-nuts v0.0.0-20210915132349-615a782f2c69/go.mod h1:xUDtqIPhzzkB+XSl0pW8qQKXzzR+SU6xcZToxwKi5zA=
github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
github.com/mozilla/scribe v0.0.0-20180711195314-fb71baf557c1/go.mod h1:FIczTrinKo8VaLxe6PWTPEXRXDIHz2QAwiaBaP5/4a8=
github.com/mozilla/tls-observatory v0.0.0-20180409132520-8791a200eb40/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
Expand Down Expand Up @@ -2496,6 +2500,7 @@ github.com/ryanrolds/sqlclosecheck v0.3.0/go.mod h1:1gREqxyTGR3lVtpngyFo3hZAgk0K
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU=
github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E=
github.com/sanposhiho/wastedassign/v2 v2.0.6/go.mod h1:KyZ0MWTwxxBmfwn33zh3k1dmsbF2ud9pAAGfoLfjhtI=
github.com/sanposhiho/wastedassign/v2 v2.0.7 h1:J+6nrY4VW+gC9xFzUc+XjPD3g3wF3je/NsJFwFK7Uxc=
Expand Down
21 changes: 20 additions & 1 deletion pkg/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"math/rand"
"net/http"
"net/http/httputil"
"os"
"strings"
"time"
Expand All @@ -26,6 +27,8 @@ import (
"github.com/jongio/azidext/go/azidext"
auth "github.com/microsoft/kiota-authentication-azure-go"
msgraph "github.com/microsoftgraph/msgraph-sdk-go"
msgraphcore "github.com/microsoftgraph/msgraph-sdk-go-core"
loghttp "github.com/motemen/go-loghttp"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/util/wait"

Expand Down Expand Up @@ -103,7 +106,23 @@ func New(log *logrus.Entry, environment env.Core, ci bool) (*Cluster, error) {
return nil, err
}

adapter, err := msgraph.NewGraphRequestAdapter(authProvider)
// Add logging to the client for debugging.
client := msgraphcore.GetDefaultClient(nil)
client.Transport = &loghttp.Transport{
Transport: client.Transport,
LogRequest: func(req *http.Request) {
if dump, err := httputil.DumpRequestOut(req, true); err == nil {
log.Printf("%s", string(dump))
}
},
LogResponse: func(resp *http.Response) {
if dump, err := httputil.DumpResponse(resp, true); err == nil {
log.Printf("%s", string(dump))
}
},
}

adapter, err := msgraph.NewGraphRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClient(authProvider, nil, nil, client)
if err != nil {
return nil, err
}
Expand Down
24 changes: 24 additions & 0 deletions vendor/github.com/motemen/go-loghttp/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions vendor/github.com/motemen/go-loghttp/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions vendor/github.com/motemen/go-loghttp/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions vendor/github.com/motemen/go-loghttp/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions vendor/github.com/motemen/go-loghttp/loghttp.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 71 additions & 0 deletions vendor/github.com/motemen/go-loghttp/loghttp_go16.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/motemen/go-nuts/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f8f344f

Please sign in to comment.