@@ -3,10 +3,8 @@ package environments
33import (
44 "fmt"
55 "log"
6- "os"
76 "strings"
87
9- "github.com/getsentry/sentry-go"
108 "github.com/spf13/pflag"
119 "k8s.io/client-go/kubernetes"
1210 "k8s.io/client-go/rest"
@@ -18,7 +16,6 @@ import (
1816 envtypes "github.com/openshift-online/maestro/cmd/maestro/environments/types"
1917 "github.com/openshift-online/maestro/pkg/client/cloudevents"
2018 "github.com/openshift-online/maestro/pkg/client/grpcauthorizer"
21- "github.com/openshift-online/maestro/pkg/client/ocm"
2219 "github.com/openshift-online/maestro/pkg/config"
2320 "github.com/openshift-online/maestro/pkg/errors"
2421)
@@ -84,8 +81,6 @@ func (e *Env) Initialize() error {
8481
8582 messages := environment .Config .ReadFiles ()
8683 if len (messages ) != 0 {
87- err := fmt .Errorf ("unable to read configuration files:\n %s" , strings .Join (messages , "\n " ))
88- sentry .CaptureException (err )
8984 log .Fatalf ("Unable to read configuration files:\n %s" , strings .Join (messages , "\n " ))
9085 }
9186
@@ -112,11 +107,6 @@ func (e *Env) Initialize() error {
112107 log .Fatalf ("Failed to visit Clients: %s" , err )
113108 }
114109
115- err = e .InitializeSentry ()
116- if err != nil {
117- return fmt .Errorf ("failed to initialize sentry: %w" , err )
118- }
119-
120110 seedErr := e .Seed ()
121111 if seedErr != nil {
122112 return seedErr
@@ -144,28 +134,6 @@ func (e *Env) LoadServices() {
144134}
145135
146136func (e * Env ) LoadClients () error {
147- var err error
148-
149- ocmConfig := ocm.Config {
150- BaseURL : e .Config .OCM .BaseURL ,
151- ClientID : e .Config .OCM .ClientID ,
152- ClientSecret : e .Config .OCM .ClientSecret ,
153- SelfToken : e .Config .OCM .SelfToken ,
154- TokenURL : e .Config .OCM .TokenURL ,
155- Debug : e .Config .OCM .Debug ,
156- }
157-
158- // Create OCM Authz client
159- if e .Config .OCM .EnableMock {
160- klog .V (4 ).Info ("Using Mock OCM Authz Client" )
161- e .Clients .OCM , err = ocm .NewClientMock (ocmConfig )
162- } else {
163- e .Clients .OCM , err = ocm .NewClient (ocmConfig )
164- }
165- if err != nil {
166- return fmt .Errorf ("Unable to create OCM Authz client: %v" , err )
167- }
168-
169137 // Create CloudEvents Source client
170138 if e .Config .MessageBroker .EnableMock {
171139 klog .V (4 ).Info ("Using Mock CloudEvents Source Client" )
@@ -218,54 +186,11 @@ func (e *Env) LoadClients() error {
218186 return nil
219187}
220188
221- func (e * Env ) InitializeSentry () error {
222- options := sentry.ClientOptions {}
223-
224- if e .Config .Sentry .Enabled {
225- key := e .Config .Sentry .Key
226- url := e .Config .Sentry .URL
227- project := e .Config .Sentry .Project
228- klog .V (4 ).Infof ("Sentry error reporting enabled to %s on project %s" , url , project )
229- options .Dsn = fmt .Sprintf ("https://%s@%s/%s" , key , url , project )
230- } else {
231- // Setting the DSN to an empty string effectively disables sentry
232- // See https://godoc.org/github.com/getsentry/sentry-go#ClientOptions Dsn
233- klog .V (4 ).Info ("Disabling Sentry error reporting" )
234- options .Dsn = ""
235- }
236-
237- transport := sentry .NewHTTPTransport ()
238- transport .Timeout = e .Config .Sentry .Timeout
239- // since sentry.HTTPTransport is asynchronous, Sentry needs a buffer to cache pending requests.
240- // the BufferSize is the size of the buffer. Sentry drops requests when the buffer is full:
241- // https://github.com/getsentry/sentry-go/blob/4f72d7725080f61e924409c8ddd008739fd4a837/transport.go#L312
242- // errors in our system are relatively sparse, we don't need a large BufferSize.
243- transport .BufferSize = 10
244- options .Transport = transport
245- options .Debug = e .Config .Sentry .Debug
246- options .AttachStacktrace = true
247- options .Environment = e .Name
248-
249- hostname , err := os .Hostname ()
250- if err != nil && hostname != "" {
251- options .ServerName = hostname
252- }
253- // TODO figure out some way to set options.Release and options.Dist
254-
255- err = sentry .Init (options )
256- if err != nil {
257- return fmt .Errorf ("Unable to initialize sentry integration: %s" , err .Error ())
258- }
259-
260- return nil
261- }
262-
263189func (e * Env ) Teardown () {
264190 if e .Name != envtypes .TestingEnv {
265191 if err := e .Database .SessionFactory .Close (); err != nil {
266192 log .Fatalf ("Unable to close db connection: %s" , err .Error ())
267193 }
268- e .Clients .OCM .Close ()
269194 }
270195}
271196
0 commit comments