-
Notifications
You must be signed in to change notification settings - Fork 894
feat: Enable workspace debug logging #6838
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
Changes from 16 commits
3f57a28
1283b7c
aa69b59
245b505
2fb359c
750cfc3
a9a05d4
3a3147d
96936ca
43611ed
864d2b2
02e5ddc
35cf509
e7b1e3c
f86005a
e24db7f
1d3bccc
af908fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,12 @@ type WorkspacesResponse struct { | |
Count int `json:"count"` | ||
} | ||
|
||
type ProvisionerLogLevel string | ||
|
||
const ( | ||
ProvisionerLogLevelDebug ProvisionerLogLevel = "debug" | ||
) | ||
|
||
// CreateWorkspaceBuildRequest provides options to update the latest workspace build. | ||
type CreateWorkspaceBuildRequest struct { | ||
TemplateVersionID uuid.UUID `json:"template_version_id,omitempty" format:"uuid"` | ||
|
@@ -59,6 +65,9 @@ type CreateWorkspaceBuildRequest struct { | |
// This will not delete old params not included in this list. | ||
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"` | ||
RichParameterValues []WorkspaceBuildParameter `json:"rich_parameter_values,omitempty"` | ||
|
||
// Log level changes the default logging verbosity of a provider ("info" if empty). | ||
LogLevel ProvisionerLogLevel `json:"log_level,omitempty" validate:"omitempty,oneof=debug"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Add a comment so this gets documented in the API doc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed! |
||
} | ||
|
||
type WorkspaceOptions struct { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,7 +192,12 @@ func (e *echo) Provision(stream proto.DRPCProvisioner_ProvisionStream) error { | |
if err != nil { | ||
return xerrors.Errorf("unmarshal: %w", err) | ||
} | ||
err = stream.Send(&response) | ||
r, ok := filterLogResponses(config, &response) | ||
if !ok { | ||
continue | ||
} | ||
|
||
err = stream.Send(r) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -282,3 +287,23 @@ func Tar(responses *Responses) ([]byte, error) { | |
} | ||
return buffer.Bytes(), nil | ||
} | ||
|
||
func filterLogResponses(config *proto.Provision_Config, response *proto.Provision_Response) (*proto.Provision_Response, bool) { | ||
responseLog, ok := response.Type.(*proto.Provision_Response_Log) | ||
if !ok { | ||
// Pass all non-log responses | ||
return response, true | ||
} | ||
|
||
if config.ProvisionerLogLevel == "" { | ||
// Don't change the default behavior of "echo" | ||
return response, true | ||
} | ||
|
||
provisionerLogLevel := proto.LogLevel_value[strings.ToUpper(config.ProvisionerLogLevel)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to avoid having to upper/lowercase this? Not blocking, just curious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that the only way to do this is to switch to |
||
if int32(responseLog.Log.Level) < provisionerLogLevel { | ||
// Log level is not enabled | ||
return nil, false | ||
} | ||
return response, true | ||
} |
Uh oh!
There was an error while loading. Please reload this page.