From e288f72d2070ee26e99074d4c66880e067ea4c6c Mon Sep 17 00:00:00 2001 From: Yuxuan Li Date: Thu, 11 Oct 2018 11:02:20 -0700 Subject: [PATCH 1/2] channelz: remove init logging --- internal/channelz/types_nonlinux.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/channelz/types_nonlinux.go b/internal/channelz/types_nonlinux.go index 884910c4e02c..11b1f267ba22 100644 --- a/internal/channelz/types_nonlinux.go +++ b/internal/channelz/types_nonlinux.go @@ -22,10 +22,6 @@ package channelz import "google.golang.org/grpc/grpclog" -func init() { - grpclog.Infof("Channelz: socket options are not supported on non-linux os and appengine.") -} - // SocketOptionData defines the struct to hold socket option data, and related // getter function to obtain info from fd. // Windows OS doesn't support Socket Option @@ -35,4 +31,6 @@ type SocketOptionData struct { // Getsockopt defines the function to get socket options requested by channelz. // It is to be passed to syscall.RawConn.Control(). // Windows OS doesn't support Socket Option -func (s *SocketOptionData) Getsockopt(fd uintptr) {} +func (s *SocketOptionData) Getsockopt(fd uintptr) { + grpclog.Infof("Channelz: socket options are not supported on non-linux os and appengine.") +} From 176f1e055ea6cf0a93145b2083236cb7df3b54ef Mon Sep 17 00:00:00 2001 From: Yuxuan Li Date: Thu, 11 Oct 2018 15:19:05 -0700 Subject: [PATCH 2/2] sync.once + warning --- internal/channelz/types_nonlinux.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/channelz/types_nonlinux.go b/internal/channelz/types_nonlinux.go index 11b1f267ba22..b24600480c34 100644 --- a/internal/channelz/types_nonlinux.go +++ b/internal/channelz/types_nonlinux.go @@ -20,7 +20,13 @@ package channelz -import "google.golang.org/grpc/grpclog" +import ( + "sync" + + "google.golang.org/grpc/grpclog" +) + +var once sync.Once // SocketOptionData defines the struct to hold socket option data, and related // getter function to obtain info from fd. @@ -32,5 +38,7 @@ type SocketOptionData struct { // It is to be passed to syscall.RawConn.Control(). // Windows OS doesn't support Socket Option func (s *SocketOptionData) Getsockopt(fd uintptr) { - grpclog.Infof("Channelz: socket options are not supported on non-linux os and appengine.") + once.Do(func() { + grpclog.Warningln("Channelz: socket options are not supported on non-linux os and appengine.") + }) }