Skip to content

feat: Fine-tune logs presentation #6771

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

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion coderd/provisionerjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ func (api *API) followProvisionerJobLogs(actor rbac.Subject, jobID uuid.UUID) (<
logger := api.Logger.With(slog.F("job_id", jobID))

var (
bufferedLogs = make(chan *database.ProvisionerJobLog, 128)
// With debug logging enabled length = 128 is insufficient
bufferedLogs = make(chan *database.ProvisionerJobLog, 1024)
endOfLogs atomic.Bool
lastSentLogID atomic.Int64
)
Expand Down
22 changes: 21 additions & 1 deletion provisioner/terraform/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,27 @@ func readAndLog(sink logSink, r io.Reader, done chan<- any, level proto.LogLevel
defer close(done)
scanner := bufio.NewScanner(r)
for scanner.Scan() {
sink.Log(&proto.Log{Level: level, Output: scanner.Text()})
var log terraformProvisionLog
err := json.Unmarshal(scanner.Bytes(), &log)
if err != nil {
if strings.TrimSpace(scanner.Text()) == "" {
continue
}

sink.Log(&proto.Log{Level: level, Output: scanner.Text()})
continue
}

logLevel := convertTerraformLogLevel(log.Level, sink)
if logLevel == proto.LogLevel_TRACE {
continue // skip TRACE log entries as they produce a lot of noise
}

// Degrade JSON log entries marked as INFO as these are logs produced in debug mode.
if logLevel == proto.LogLevel_INFO {
logLevel = proto.LogLevel_DEBUG
}
sink.Log(&proto.Log{Level: logLevel, Output: log.Message})
}
}

Expand Down
1 change: 1 addition & 0 deletions provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func provisionEnv(config *proto.Provision_Config, params []*proto.ParameterValue
for _, gitAuth := range gitAuth {
env = append(env, provider.GitAuthAccessTokenEnvironmentVariable(gitAuth.Id)+"="+gitAuth.AccessToken)
}
// FIXME env = append(env, "TF_LOG=JSON")
return env, nil
}

Expand Down
6 changes: 5 additions & 1 deletion site/src/components/Logs/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ const useStyles = makeStyles<
backgroundColor: theme.palette.error.dark,
},

"&.warning": {
"&.debug": {
backgroundColor: theme.palette.grey[900],
},

"&.warn": {
backgroundColor: theme.palette.warning.dark,
},
},
Expand Down