mirror of https://github.com/coder/coder.git
Improve syntax
This commit is contained in:
parent
3aed5c5bb8
commit
d94a9df773
|
@ -17,7 +17,6 @@ import (
|
|||
"time"
|
||||
|
||||
"cloud.google.com/go/compute/metadata"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
"golang.org/x/xerrors"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
"tailscale.com/util/clientmetric"
|
||||
|
@ -163,11 +162,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
|
|||
sinks = append(sinks, sloghuman.Sink(logWriter))
|
||||
logger := slog.Make(sinks...).Leveled(slog.LevelDebug)
|
||||
|
||||
// This can improve the performance of Coder inside of a container.
|
||||
// See: https://github.com/uber-go/automaxprocs
|
||||
undoMacProcs, err := maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
|
||||
logger.Debug(ctx, fmt.Sprintf(format, args...))
|
||||
}))
|
||||
undoMacProcs, err := limitGoMaxProcs(logger)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("set maxprocs: %w", err)
|
||||
}
|
||||
|
|
14
cli/root.go
14
cli/root.go
|
@ -25,6 +25,7 @@ import (
|
|||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/mitchellh/go-wordwrap"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
|
@ -1128,6 +1129,19 @@ func tailLineStyle() pretty.Style {
|
|||
return pretty.Style{pretty.Nop}
|
||||
}
|
||||
|
||||
// limitGoMaxProcs sets GOMAXPROCS to the number of CPUs available.
|
||||
// This can improve the performance of Coder inside of a container.
|
||||
func limitGoMaxProcs(logger slog.Logger) (func(), error) {
|
||||
// See: https://github.com/uber-go/automaxprocs
|
||||
undoMacProcs, err := maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
|
||||
logger.Debug(context.Background(), fmt.Sprintf(format, args...))
|
||||
}))
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("set maxprocs: %w", err)
|
||||
}
|
||||
return undoMacProcs, nil
|
||||
}
|
||||
|
||||
//nolint:unused
|
||||
func SlimUnsupported(w io.Writer, cmd string) {
|
||||
_, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", pretty.Sprint(cliui.DefaultStyles.Code, cmd))
|
||||
|
|
|
@ -44,7 +44,6 @@ import (
|
|||
"go.opentelemetry.io/otel"
|
||||
"go.opentelemetry.io/otel/propagation"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/automaxprocs/maxprocs"
|
||||
"golang.org/x/mod/semver"
|
||||
"golang.org/x/oauth2"
|
||||
xgithub "golang.org/x/oauth2/github"
|
||||
|
@ -324,11 +323,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
|
|||
logger.Debug(ctx, "started debug logging")
|
||||
logger.Sync()
|
||||
|
||||
// This can improve the performance of Coder inside of a container.
|
||||
// See: https://github.com/uber-go/automaxprocs
|
||||
undoMacProcs, err := maxprocs.Set(maxprocs.Logger(func(format string, args ...interface{}) {
|
||||
logger.Debug(ctx, fmt.Sprintf(format, args...))
|
||||
}))
|
||||
undoMacProcs, err := limitGoMaxProcs(logger)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("set maxprocs: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue