Skip to content

fix(enterprise/cli): add CODER_PROVISIONER_DAEMON_LOG_* options #11279

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 9 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(enterprise/cli): plumb through CODER_PROVISIONERD_LOG_* options
  • Loading branch information
johnstcn committed Dec 19, 2023
commit e83c1c01d7f149321c75c77acfb2cf97f7c1615d
47 changes: 47 additions & 0 deletions docs/cli/provisionerd_start.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 58 additions & 10 deletions enterprise/cli/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"golang.org/x/xerrors"

"cdr.dev/slog"
"cdr.dev/slog/sloggers/sloghuman"
agpl "github.com/coder/coder/v2/cli"
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/clilog"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/cliutil"
"github.com/coder/coder/v2/coderd/database"
Expand Down Expand Up @@ -55,12 +55,17 @@ func validateProvisionerDaemonName(name string) error {

func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
var (
cacheDir string
rawTags []string
pollInterval time.Duration
pollJitter time.Duration
preSharedKey string
name string
cacheDir string
logHuman string
logJSON string
logStackdriver string
logFilter []string
name string
rawTags []string
pollInterval time.Duration
pollJitter time.Duration
preSharedKey string
verbose bool
)
client := new(codersdk.Client)
cmd := &clibase.Cmd{
Expand Down Expand Up @@ -89,10 +94,18 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
return err
}

logger := slog.Make(sloghuman.Sink(inv.Stderr))
if ok, _ := inv.ParsedFlags().GetBool("verbose"); ok {
logger = logger.Leveled(slog.LevelDebug)
logOpts := []clilog.Option{
clilog.WithFilter(logFilter...),
clilog.WithHuman(logHuman),
clilog.WithJSON(logJSON),
clilog.WithStackdriver(logStackdriver),
}
if verbose {
logOpts = append(logOpts, clilog.WithVerbose())
}

logger, closeLogger, err := clilog.New(logOpts...).Build(inv)
defer closeLogger()

if len(tags) != 0 {
logger.Info(ctx, "note: tagged provisioners can currently pick up jobs from untagged templates")
Expand Down Expand Up @@ -234,6 +247,41 @@ func (r *RootCmd) provisionerDaemonStart() *clibase.Cmd {
Value: clibase.StringOf(&name),
Default: "",
},
{
Flag: "verbose",
Env: "CODER_PROVISIONER_DAEMON_VERBOSE",
Description: "Output debug-level logs.",
Value: clibase.BoolOf(&verbose),
Default: "false",
},
{
Flag: "log-human",
Env: "CODER_PROVISIONER_DAEMON_LOGGING_HUMAN",
Description: "Output human-readable logs to a given file.",
Value: clibase.StringOf(&logHuman),
Default: "/dev/stderr",
},
{
Flag: "log-json",
Env: "CODER_PROVISIONER_DAEMON_LOGGING_JSON",
Description: "Output JSON logs to a given file.",
Value: clibase.StringOf(&logJSON),
Default: "",
},
{
Flag: "log-stackdriver",
Env: "CODER_PROVISIONER_DAEMON_LOGGING_STACKDRIVER",
Description: "Output Stackdriver compatible logs to a given file.",
Value: clibase.StringOf(&logStackdriver),
Default: "",
},
{
Flag: "log-filter",
Env: "CODER_PROVISIONER_DAEMON_LOG_FILTER",
Description: "Filter debug logs by matching against a given regex. Use .* to match all debug logs.",
Value: clibase.StringArrayOf(&logFilter),
Default: "",
},
}

return cmd
Expand Down
16 changes: 16 additions & 0 deletions enterprise/cli/testdata/coder_provisionerd_start_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ OPTIONS:
-c, --cache-dir string, $CODER_CACHE_DIRECTORY (default: [cache dir])
Directory to store cached data.

--log-filter string-array, $CODER_PROVISIONER_DAEMON_LOG_FILTER
Filter debug logs by matching against a given regex. Use .* to match
all debug logs.

--log-human string, $CODER_PROVISIONER_DAEMON_LOGGING_HUMAN (default: /dev/stderr)
Output human-readable logs to a given file.

--log-json string, $CODER_PROVISIONER_DAEMON_LOGGING_JSON
Output JSON logs to a given file.

--log-stackdriver string, $CODER_PROVISIONER_DAEMON_LOGGING_STACKDRIVER
Output Stackdriver compatible logs to a given file.

--name string, $CODER_PROVISIONER_DAEMON_NAME
Name of this provisioner daemon. Defaults to the current hostname
without FQDN.
Expand All @@ -25,5 +38,8 @@ OPTIONS:
-t, --tag string-array, $CODER_PROVISIONERD_TAGS
Tags to filter provisioner jobs by.

--verbose bool, $CODER_PROVISIONER_DAEMON_VERBOSE (default: false)
Output debug-level logs.

———
Run `coder --help` for a list of global options.