Skip to content

Commit 5403654

Browse files
drewhlicopybara-github
authored andcommitted
Initialize logger early in core plugin's initialization so that errors/timings with the plugin server initialization can be captured in logging.
PiperOrigin-RevId: 877643675
1 parent 3e11ba0 commit 5403654

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

cmd/core_plugin/core_plugin.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package main
1717

1818
import (
19+
"context"
1920
"flag"
2021
"fmt"
2122
"os"
@@ -121,6 +122,13 @@ func main() {
121122
// coming from user's configuration.
122123
setupFlags()
123124

125+
// Initialize the logger.
126+
logOpts.ProgramVersion = version
127+
if err := logger.Init(context.Background(), logOpts); err != nil {
128+
logAndExit(fmt.Sprintf("Failed to initialize logger: %v", err))
129+
}
130+
loggerInitialized.Store(true)
131+
124132
// List available modules and exit.
125133
if listModules {
126134
exitCode, err := displayModules()

cmd/core_plugin/service.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"github.com/GoogleCloudPlatform/google-guest-agent/internal/cfg"
3030
"github.com/GoogleCloudPlatform/google-guest-agent/internal/command"
3131
"github.com/GoogleCloudPlatform/google-guest-agent/internal/events"
32-
"github.com/GoogleCloudPlatform/google-guest-agent/internal/logger"
3332
"github.com/GoogleCloudPlatform/google-guest-agent/internal/metadata"
3433
"github.com/GoogleCloudPlatform/google-guest-agent/internal/plugin/manager"
3534
"google.golang.org/grpc"
@@ -50,11 +49,13 @@ var pluginServer *PluginServer
5049
// initPluginServer initializes the core plugin server and starts serving
5150
// requests from Guest Agent.
5251
func initPluginServer() error {
52+
galog.Infof("Initializing core plugin server...")
5353
listener, err := net.Listen(protocol, address)
5454
if err != nil {
5555
return fmt.Errorf("start listening on %q using %q: %v", address, protocol, err)
5656
}
5757
defer listener.Close()
58+
galog.Infof("Core plugin server listening on %q using %q", address, protocol)
5859

5960
// This is the grpc server in communication with the Guest Agent.
6061
server := grpc.NewServer()
@@ -64,6 +65,7 @@ func initPluginServer() error {
6465
// offered mean Guest Agent was successful in installing/launching the plugin
6566
// & will manage the lifecycle (start, stop, or revision change) here onwards.
6667
pb.RegisterGuestAgentPluginServer(server, pluginServer)
68+
galog.Infof("Core plugin server registered. Starting to serve requests...")
6769

6870
if err := server.Serve(listener); err != nil {
6971
return fmt.Errorf("cannot continue serving on %q: %v", address, err)
@@ -199,12 +201,6 @@ func (ps *PluginServer) Start(ctx context.Context, msg *pb.StartRequest) (*pb.St
199201
pCtx, cancel := context.WithCancel(context.Background())
200202
ps.cancel = cancel
201203

202-
logOpts.ProgramVersion = version
203-
if err := logger.Init(pCtx, logOpts); err != nil {
204-
return nil, status.Errorf(1, "failed to initialize logger: %v", err)
205-
}
206-
loggerInitialized.Store(true)
207-
208204
// Log the config read by the core plugin to debug.
209205
cfg.Log()
210206

0 commit comments

Comments
 (0)