From 71b82c117b13c97dd1744a2bddb8f55d6035c294 Mon Sep 17 00:00:00 2001 From: whywaita Date: Mon, 5 Feb 2024 22:59:47 +0900 Subject: [PATCH] And more --- server/pkg/api/server.go | 3 +-- server/pkg/api/server_add_instance.go | 4 ++-- server/pkg/lxdclient/resource.go | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/server/pkg/api/server.go b/server/pkg/api/server.go index 4a26211..b9f6306 100644 --- a/server/pkg/api/server.go +++ b/server/pkg/api/server.go @@ -2,7 +2,6 @@ package api import ( "fmt" - "log" "log/slog" "net" "sync" @@ -42,7 +41,7 @@ func (s *ShoesLXDMultiServer) Run(listenPort int) error { if err != nil { return fmt.Errorf("failed to listen: %w", err) } - log.Printf("start listen :%d\n", listenPort) + slog.Info("start listen", "port", listenPort) grpcServer := grpc.NewServer() pb.RegisterShoesLXDMultiServer(grpcServer, s) diff --git a/server/pkg/api/server_add_instance.go b/server/pkg/api/server_add_instance.go index 1f59a18..3eaabb7 100644 --- a/server/pkg/api/server_add_instance.go +++ b/server/pkg/api/server_add_instance.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "log" "log/slog" "math/rand" "net/url" @@ -72,6 +71,7 @@ func (s *ShoesLXDMultiServer) AddInstance(ctx context.Context, req *pb.AddInstan } else { client = host.Client } + l = l.With("host", host.HostConfig.LxdHost) reqState := api.InstanceStatePut{ Action: "start", @@ -89,7 +89,7 @@ func (s *ShoesLXDMultiServer) AddInstance(ctx context.Context, req *pb.AddInstan if err != nil { return nil, status.Errorf(codes.Internal, "failed to retrieve instance information: %+v", err) } - log.Printf("Success AddInstance host: %s, runnerName: %s\n", host.HostConfig.LxdHost, i.Name) + l.Info("Success AddInstance", "host", host.HostConfig.LxdHost, "runnerName", i.Name) return &pb.AddInstanceResponse{ CloudId: i.Name, diff --git a/server/pkg/lxdclient/resource.go b/server/pkg/lxdclient/resource.go index e4b0caa..d18e688 100644 --- a/server/pkg/lxdclient/resource.go +++ b/server/pkg/lxdclient/resource.go @@ -3,7 +3,6 @@ package lxdclient import ( "errors" "fmt" - "log" "log/slog" "strconv" @@ -113,7 +112,7 @@ func ScrapeLXDHostAllocatedResources(instances []api.Instance) (uint64, uint64, } allocatedCPU += uint64(cpu) } else { - log.Printf("%s hasn't limits.cpu\n", instance.Name) + slog.Warn("instance hasn't limits.cpu", "instance", instance.Name) } instanceMemory := instance.Config["limits.memory"] @@ -124,7 +123,7 @@ func ScrapeLXDHostAllocatedResources(instances []api.Instance) (uint64, uint64, } allocatedMemory += uint64(memory) } else { - log.Printf("%s hasn't limits.memory\n", instance.Name) + slog.Warn("instance hasn't limits.memory", "instance", instance.Name) } }