@@ -364,6 +364,9 @@ func (c *WorkspaceAgentConn) DebugMagicsock(ctx context.Context) ([]byte, error)
364364 if err != nil {
365365 return nil , xerrors .Errorf ("do request: %w" , err )
366366 }
367+ if res .StatusCode != http .StatusOK {
368+ return nil , ReadBodyAsError (res )
369+ }
367370 defer res .Body .Close ()
368371 bs , err := io .ReadAll (res .Body )
369372 if err != nil {
@@ -382,6 +385,9 @@ func (c *WorkspaceAgentConn) DebugManifest(ctx context.Context) ([]byte, error)
382385 return nil , xerrors .Errorf ("do request: %w" , err )
383386 }
384387 defer res .Body .Close ()
388+ if res .StatusCode != http .StatusOK {
389+ return nil , ReadBodyAsError (res )
390+ }
385391 bs , err := io .ReadAll (res .Body )
386392 if err != nil {
387393 return nil , xerrors .Errorf ("read response body: %w" , err )
@@ -398,6 +404,28 @@ func (c *WorkspaceAgentConn) DebugLogs(ctx context.Context) ([]byte, error) {
398404 return nil , xerrors .Errorf ("do request: %w" , err )
399405 }
400406 defer res .Body .Close ()
407+ if res .StatusCode != http .StatusOK {
408+ return nil , ReadBodyAsError (res )
409+ }
410+ bs , err := io .ReadAll (res .Body )
411+ if err != nil {
412+ return nil , xerrors .Errorf ("read response body: %w" , err )
413+ }
414+ return bs , nil
415+ }
416+
417+ // PrometheusMetrics returns a response from the agent's prometheus metrics endpoint
418+ func (c * WorkspaceAgentConn ) PrometheusMetrics (ctx context.Context ) ([]byte , error ) {
419+ ctx , span := tracing .StartSpan (ctx )
420+ defer span .End ()
421+ res , err := c .apiRequest (ctx , http .MethodGet , "/debug/prometheus" , nil )
422+ if err != nil {
423+ return nil , xerrors .Errorf ("do request: %w" , err )
424+ }
425+ defer res .Body .Close ()
426+ if res .StatusCode != http .StatusOK {
427+ return nil , ReadBodyAsError (res )
428+ }
401429 bs , err := io .ReadAll (res .Body )
402430 if err != nil {
403431 return nil , xerrors .Errorf ("read response body: %w" , err )
0 commit comments