Skip to content

[ws-manager-mk2] Use common-go/log #16921

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 1 commit into from
Mar 21, 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
2 changes: 1 addition & 1 deletion components/ws-manager-mk2/BUILD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ packages:
- components/image-builder-api/go:lib
config:
packaging: app
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'github.com/gitpod-io/gitpod/ws-manager-mk2/cmd.Version=commit-${__git_commit}'"]
buildCommand: ["go", "build", "-trimpath", "-ldflags", "-buildid= -w -s -X 'main.Version=commit-${__git_commit}'"]
- name: docker
type: docker
deps:
Expand Down
1 change: 1 addition & 0 deletions components/ws-manager-mk2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ require (
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bombsimon/logrusr/v2 v2.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
Expand Down
4 changes: 4 additions & 0 deletions components/ws-manager-mk2/go.sum

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

24 changes: 17 additions & 7 deletions components/ws-manager-mk2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import (
"google.golang.org/grpc/credentials/insecure"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/bombsimon/logrusr/v2"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics"

common_grpc "github.com/gitpod-io/gitpod/common-go/grpc"
Expand All @@ -50,6 +51,11 @@ import (
)

var (
// ServiceName is the name we use for tracing/logging
ServiceName = "ws-manager-mk2"
// Version of this service - set during build
Version = ""

scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
)
Expand All @@ -64,17 +70,21 @@ func init() {
func main() {
var enableLeaderElection bool
var configFN string
var jsonLog bool
var verbose bool
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.StringVar(&configFN, "config", "", "Path to the config file")
opts := zap.Options{
Development: true,
}
opts.BindFlags(flag.CommandLine)
flag.BoolVar(&jsonLog, "json-log", true, "produce JSON log output on verbose level")
flag.BoolVar(&verbose, "verbose", false, "Enable verbose logging")
flag.Parse()

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
log.Init(ServiceName, Version, jsonLog, verbose)
baseLogger := logrusr.New(log.Log)
ctrl.SetLogger(baseLogger)
// Set the logger used by k8s (e.g. client-go).
klog.SetLogger(baseLogger)
promrep := &tracing.PromReporter{
Operations: map[string]tracing.SpanMetricMapping{
"StartWorkspace": {
Expand All @@ -84,7 +94,7 @@ func main() {
},
},
}
closer := tracing.Init("ws-manager-mk2", tracing.WithPrometheusReporter(promrep))
closer := tracing.Init(ServiceName, tracing.WithPrometheusReporter(promrep))
if closer != nil {
defer closer.Close()
}
Expand Down