Skip to content

Commit 3f57a28

Browse files
committed
feat: Enable workspace debug logging
1 parent 1645281 commit 3f57a28

File tree

17 files changed

+396
-297
lines changed

17 files changed

+396
-297
lines changed

coderd/apidoc/docs.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func (server *Server) AcquireJob(ctx context.Context, _ *proto.Empty) (*proto.Ac
273273
TemplateName: template.Name,
274274
TemplateVersion: templateVersion.Name,
275275
},
276+
LogLevel: input.LogLevel,
276277
},
277278
}
278279
case database.ProvisionerJobTypeTemplateVersionDryRun:
@@ -1550,6 +1551,7 @@ type TemplateVersionImportJob struct {
15501551
type WorkspaceProvisionJob struct {
15511552
WorkspaceBuildID uuid.UUID `json:"workspace_build_id"`
15521553
DryRun bool `json:"dry_run"`
1554+
LogLevel string `json:"log_level,omitempty"`
15531555
}
15541556

15551557
// TemplateVersionDryRunJob is the payload for the "template_version_dry_run" job type.

coderd/workspacebuilds.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
582582
workspaceBuildID := uuid.New()
583583
input, err := json.Marshal(provisionerdserver.WorkspaceProvisionJob{
584584
WorkspaceBuildID: workspaceBuildID,
585+
LogLevel: string(createBuild.LogLevel),
585586
})
586587
if err != nil {
587588
return xerrors.Errorf("marshal provision job: %w", err)

codersdk/workspaces.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ type WorkspacesResponse struct {
4646
Count int `json:"count"`
4747
}
4848

49+
type ProvisionerLogLevel string
50+
51+
const (
52+
ProvisionerLogLevelDebug ProvisionerLogLevel = "debug"
53+
)
54+
4955
// CreateWorkspaceBuildRequest provides options to update the latest workspace build.
5056
type CreateWorkspaceBuildRequest struct {
5157
TemplateVersionID uuid.UUID `json:"template_version_id,omitempty" format:"uuid"`
@@ -59,6 +65,8 @@ type CreateWorkspaceBuildRequest struct {
5965
// This will not delete old params not included in this list.
6066
ParameterValues []CreateParameterRequest `json:"parameter_values,omitempty"`
6167
RichParameterValues []WorkspaceBuildParameter `json:"rich_parameter_values,omitempty"`
68+
69+
LogLevel ProvisionerLogLevel `json:"log_level" validate:"oneof=debug"`
6270
}
6371

6472
type WorkspaceOptions struct {

docs/api/builds.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ curl -X POST http://coder-server:8080/api/v2/workspaces/{workspace}/builds \
11661166
```json
11671167
{
11681168
"dry_run": true,
1169+
"log_level": "debug",
11691170
"orphan": true,
11701171
"parameter_values": [
11711172
{

docs/api/schemas.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
14631463
```json
14641464
{
14651465
"dry_run": true,
1466+
"log_level": "debug",
14661467
"orphan": true,
14671468
"parameter_values": [
14681469
{
@@ -1490,6 +1491,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
14901491
| Name | Type | Required | Restrictions | Description |
14911492
| ----------------------- | ----------------------------------------------------------------------------- | -------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
14921493
| `dry_run` | boolean | false | | |
1494+
| `log_level` | [codersdk.ProvisionerLogLevel](#codersdkprovisionerloglevel) | false | | |
14931495
| `orphan` | boolean | false | | Orphan may be set for the Destroy transition. |
14941496
| `parameter_values` | array of [codersdk.CreateParameterRequest](#codersdkcreateparameterrequest) | false | | Parameter values are optional. It will write params to the 'workspace' scope. This will overwrite any existing parameters with the same name. This will not delete old params not included in this list. |
14951497
| `rich_parameter_values` | array of [codersdk.WorkspaceBuildParameter](#codersdkworkspacebuildparameter) | false | | |
@@ -1501,6 +1503,7 @@ CreateParameterRequest is a structure used to create a new parameter value for a
15011503

15021504
| Property | Value |
15031505
| ------------ | -------- |
1506+
| `log_level` | `debug` |
15041507
| `transition` | `create` |
15051508
| `transition` | `start` |
15061509
| `transition` | `stop` |
@@ -3251,6 +3254,20 @@ Parameter represents a set value for the scope.
32513254
| `canceled` |
32523255
| `failed` |
32533256

3257+
## codersdk.ProvisionerLogLevel
3258+
3259+
```json
3260+
"debug"
3261+
```
3262+
3263+
### Properties
3264+
3265+
#### Enumerated Values
3266+
3267+
| Value |
3268+
| ------- |
3269+
| `debug` |
3270+
32543271
## codersdk.ProvisionerStorageMethod
32553272

32563273
```json

docs/cli.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ Coder — A tool for provisioning self-hosted development environments with Terr
6161

6262
### --global-config
6363

64-
| | |
65-
| ----------- | ------------------------------ |
66-
| Type | <code>string</code> |
67-
| Environment | <code>$CODER_CONFIG_DIR</code> |
68-
| Default | <code>~/.config/coderv2</code> |
64+
| | |
65+
| ----------- | -------------------------------------------------- |
66+
| Type | <code>string</code> |
67+
| Environment | <code>$CODER_CONFIG_DIR</code> |
68+
| Default | <code>~/Library/Application Support/coderv2</code> |
6969

7070
Path to the global `coder` config directory.
7171

provisioner/terraform/provision.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (s *server) Provision(stream proto.DRPCProvisioner_ProvisionStream) error {
136136
return xerrors.Errorf("initialize terraform: %w", err)
137137
}
138138
s.logger.Debug(ctx, "ran initialization")
139-
env, err := provisionEnv(config, request.GetPlan().GetParameterValues(), request.GetPlan().GetRichParameterValues(), request.GetPlan().GetGitAuthProviders())
139+
env, err := provisionEnv(config, request.GetPlan().GetParameterValues(), request.GetPlan().GetRichParameterValues(), request.GetPlan().GetGitAuthProviders(), config.ProvisionerLogLevel)
140140
if err != nil {
141141
return err
142142
}
@@ -205,7 +205,7 @@ func planVars(plan *proto.Provision_Plan) ([]string, error) {
205205
return vars, nil
206206
}
207207

208-
func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue, richParams []*proto.RichParameterValue, gitAuth []*proto.GitAuthProvider) ([]string, error) {
208+
func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue, richParams []*proto.RichParameterValue, gitAuth []*proto.GitAuthProvider, logLevel string) ([]string, error) {
209209
env := safeEnviron()
210210
env = append(env,
211211
"CODER_AGENT_URL="+config.Metadata.CoderUrl,
@@ -236,7 +236,14 @@ func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue
236236
for _, gitAuth := range gitAuth {
237237
env = append(env, provider.GitAuthAccessTokenEnvironmentVariable(gitAuth.Id)+"="+gitAuth.AccessToken)
238238
}
239-
// FIXME env = append(env, "TF_LOG=JSON")
239+
240+
if logLevel == "debug" {
241+
// TF_LOG=JSON enables all kind of logging: trace-debug-info-warn-error.
242+
// Coder shows info-warn-error by default, so we need to filter "trace" log entries,
243+
// on the upper layer.
244+
// The idea behind using TF_LOG=JSON instead of TF_LOG=debug is ensuring the proper log format.
245+
env = append(env, "TF_LOG=JSON")
246+
}
240247
return env, nil
241248
}
242249

0 commit comments

Comments
 (0)