Skip to content

Commit

Permalink
unifying logging library to klog
Browse files Browse the repository at this point in the history
Signed-off-by: zhangjie <[email protected]>
  • Loading branch information
kadisi committed Aug 13, 2019
1 parent 10b2667 commit dc2f3a0
Show file tree
Hide file tree
Showing 128 changed files with 1,304 additions and 1,265 deletions.
6 changes: 6 additions & 0 deletions cloud/cmd/cloudcore/cloudcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ package main
import (
"os"

"k8s.io/klog"

"github.com/kubeedge/kubeedge/cloud/cmd/cloudcore/app"
)

func init() {
klog.InitFlags(nil)
}

func main() {
command := app.NewCloudCoreCommand()

Expand Down
13 changes: 7 additions & 6 deletions cloud/pkg/cloudhub/channelq/channelq.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"strings"
"sync"

"github.com/kubeedge/beehive/pkg/common/log"
"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/core/context"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/common/model"
)
Expand Down Expand Up @@ -66,7 +67,7 @@ func (q *ChannelEventQueue) DispatchMessage() {
for {
msg, err := q.ctx.Receive(model.SrcCloudHub)
if err != nil {
log.LOGGER.Infof("receive not Message format message")
klog.Info("receive not Message format message")
continue
}
resource := msg.Router.Resource
Expand All @@ -80,12 +81,12 @@ func (q *ChannelEventQueue) DispatchMessage() {
}
}
if nodeID == "" {
log.LOGGER.Warnf("node id is not found in the message")
klog.Warning("node id is not found in the message")
continue
}
rChannel, err := q.getRChannel(nodeID)
if err != nil {
log.LOGGER.Infof("fail to get dispatch channel for %s", nodeID)
klog.Infof("fail to get dispatch channel for %s", nodeID)
continue
}
event := model.MessageToEvent(&msg)
Expand All @@ -98,7 +99,7 @@ func (q *ChannelEventQueue) DispatchMessage() {
func (q *ChannelEventQueue) getRChannel(nodeID string) (chan model.Event, error) {
channels, ok := q.channelPool.Load(nodeID)
if !ok {
log.LOGGER.Errorf("rChannel for edge node %s is removed", nodeID)
klog.Errorf("rChannel for edge node %s is removed", nodeID)
return nil, fmt.Errorf("rChannel not found")
}
rChannel := channels.(chan model.Event)
Expand All @@ -125,7 +126,7 @@ func (q *ChannelEventQueue) Connect(info *model.HubInfo) error {
func (q *ChannelEventQueue) Close(info *model.HubInfo) error {
channels, ok := q.channelPool.Load(info.NodeID)
if !ok {
log.LOGGER.Warnf("rChannel for edge node %s is already removed", info.NodeID)
klog.Warningf("rChannel for edge node %s is already removed", info.NodeID)
return nil
}
rChannel := channels.(chan model.Event)
Expand Down
11 changes: 6 additions & 5 deletions cloud/pkg/cloudhub/cloudhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"io/ioutil"
"os"

"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/common/config"
"github.com/kubeedge/beehive/pkg/common/log"
"github.com/kubeedge/beehive/pkg/core"
"github.com/kubeedge/beehive/pkg/core/context"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/channelq"
Expand Down Expand Up @@ -62,19 +63,19 @@ func (a *cloudHub) Cleanup() {
func initHubConfig() {
cafile, err := config.CONFIG.GetValue("cloudhub.ca").ToString()
if err != nil {
log.LOGGER.Info("missing cloudhub.ca configuration key, loading default path and filename ./" + chconfig.DefaultCAFile)
klog.Infof("missing cloudhub.ca configuration key, loading default path and filename ./%s", chconfig.DefaultCAFile)
cafile = chconfig.DefaultCAFile
}

certfile, err := config.CONFIG.GetValue("cloudhub.cert").ToString()
if err != nil {
log.LOGGER.Info("missing cloudhub.cert configuration key, loading default path and filename ./" + chconfig.DefaultCertFile)
klog.Infof("missing cloudhub.cert configuration key, loading default path and filename ./%s", chconfig.DefaultCertFile)
certfile = chconfig.DefaultCertFile
}

keyfile, err := config.CONFIG.GetValue("cloudhub.key").ToString()
if err != nil {
log.LOGGER.Info("missing cloudhub.key configuration key, loading default path and filename ./" + chconfig.DefaultKeyFile)
klog.Infof("missing cloudhub.key configuration key, loading default path and filename ./%s", chconfig.DefaultKeyFile)
keyfile = chconfig.DefaultKeyFile
}

Expand Down Expand Up @@ -109,7 +110,7 @@ func initHubConfig() {
}

if len(errs) > 0 {
log.LOGGER.Errorf("cloudhub failed with errors : %v", errs)
klog.Errorf("cloudhub failed with errors : %v", errs)
os.Exit(1)
}
}
5 changes: 3 additions & 2 deletions cloud/pkg/cloudhub/common/model/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"fmt"
"strings"

"github.com/kubeedge/beehive/pkg/common/log"
"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/core/model"
)

Expand Down Expand Up @@ -127,7 +128,7 @@ func (event *Event) IsNodeStopped() bool {
}
body, ok := event.Content.(map[string]interface{})
if !ok {
log.LOGGER.Errorf("fail to decode node update message: %s, type is %T", event.GetContent(), event.Content)
klog.Errorf("fail to decode node update message: %s, type is %T", event.GetContent(), event.Content)
// it can't be determined if the node has stopped
return false
}
Expand Down
53 changes: 27 additions & 26 deletions cloud/pkg/cloudhub/handler/eventhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import (
"sync"
"time"

bhLog "github.com/kubeedge/beehive/pkg/common/log"
"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/core/context"
"github.com/kubeedge/beehive/pkg/core/model"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/channelq"
Expand Down Expand Up @@ -83,20 +84,20 @@ func (eh *EventHandle) HandleServer(container *mux.MessageContainer, writer mux.
projectID := container.Header.Get("project_id")

if eh.GetNodeCount() >= eh.NodeLimit {
bhLog.LOGGER.Errorf("Fail to serve node %s, reach node limit", nodeID)
klog.Errorf("Fail to serve node %s, reach node limit", nodeID)
return
}

if container.Message.GetOperation() == emodel.OpKeepalive {
bhLog.LOGGER.Infof("Keepalive message received from node: %s", nodeID)
klog.Infof("Keepalive message received from node: %s", nodeID)
eh.KeepaliveChannel[nodeID] <- struct{}{}
return
}

err := eh.Pub2Controller(&emodel.HubInfo{ProjectID: projectID, NodeID: nodeID}, container.Message)
if err != nil {
// if err, we should stop node, write data to edgehub, stop nodify
bhLog.LOGGER.Errorf("Failed to serve handle with error: %s", err.Error())
klog.Errorf("Failed to serve handle with error: %s", err.Error())
}
}

Expand All @@ -119,10 +120,10 @@ func (eh *EventHandle) KeepaliveCheckLoop(hi hubio.CloudHubIO, info *emodel.HubI
keepaliveTimer := time.NewTimer(time.Duration(eh.KeepaliveInterval) * time.Second)
select {
case <-eh.KeepaliveChannel[info.NodeID]:
bhLog.LOGGER.Infof("Node %s is still alive", info.NodeID)
klog.Infof("Node %s is still alive", info.NodeID)
keepaliveTimer.Stop()
case <-keepaliveTimer.C:
bhLog.LOGGER.Warnf("Timeout to receive heart beat from edge node %s for project %s",
klog.Warningf("Timeout to receive heart beat from edge node %s for project %s",
info.NodeID, info.ProjectID)
stop <- nodeStop
return
Expand All @@ -140,7 +141,7 @@ func trimMessage(msg *model.Message) {
if strings.HasPrefix(resource, emodel.ResNode) {
tokens := strings.Split(resource, "/")
if len(tokens) < 3 {
bhLog.LOGGER.Warnf("event resource %s starts with node but length less than 3", resource)
klog.Warningf("event resource %s starts with node but length less than 3", resource)
} else {
msg.SetResourceOperation(strings.Join(tokens[2:], "/"), msg.GetOperation())
}
Expand All @@ -152,7 +153,7 @@ func notifyEventQueueError(hi hubio.CloudHubIO, code ExitCode, nodeID string) {
msg := model.NewMessage("").BuildRouter(emodel.GpResource, emodel.SrcCloudHub, emodel.NewResource(emodel.ResNode, nodeID, nil), emodel.OpDisConnect)
err := hi.WriteData(msg)
if err != nil {
bhLog.LOGGER.Errorf("fail to notify node %s event queue disconnected, reason: %s", nodeID, err.Error())
klog.Errorf("fail to notify node %s event queue disconnected, reason: %s", nodeID, err.Error())
}
}
}
Expand Down Expand Up @@ -185,12 +186,12 @@ func constructConnectEvent(info *emodel.HubInfo, isConnected bool) *emodel.Event
func (eh *EventHandle) Pub2Controller(info *emodel.HubInfo, msg *model.Message) error {
msg.SetResourceOperation(fmt.Sprintf("node/%s/%s", info.NodeID, msg.GetResource()), msg.GetOperation())
event := emodel.MessageToEvent(msg)
bhLog.LOGGER.Infof("event received for node %s %s, content: %s", info.NodeID, dumpEventMetadata(&event), event.Content)
klog.Infof("event received for node %s %s, content: %s", info.NodeID, dumpEventMetadata(&event), event.Content)
if event.IsFromEdge() {
err := eh.EventQueue.Publish(info, &event)
if err != nil {
// content is not logged since it may contain sensitive information
bhLog.LOGGER.Errorf("fail to publish event for node %s, %s, reason: %s",
klog.Errorf("fail to publish event for node %s, %s, reason: %s",
info.NodeID, dumpEventMetadata(&event), err.Error())
return err
}
Expand Down Expand Up @@ -227,11 +228,11 @@ func (eh *EventHandle) hubIoWrite(hi hubio.CloudHubIO, nodeID string, v interfac
func (eh *EventHandle) ServeConn(hi hubio.CloudHubIO, info *emodel.HubInfo) {
err := eh.EnrollNode(hi, info)
if err != nil {
bhLog.LOGGER.Errorf("fail to enroll node %s, reason %s", info.NodeID, err.Error())
klog.Errorf("fail to enroll node %s, reason %s", info.NodeID, err.Error())
return
}

bhLog.LOGGER.Infof("edge node %s for project %s connected", info.NodeID, info.ProjectID)
klog.Infof("edge node %s for project %s connected", info.NodeID, info.ProjectID)
stop := make(chan ExitCode, 2)

for _, handle := range eh.Handlers {
Expand All @@ -253,22 +254,22 @@ func (eh *EventHandle) EnrollNode(hi hubio.CloudHubIO, info *emodel.HubInfo) err
time.Sleep(time.Duration(1) * time.Second)
}
if err != nil {
bhLog.LOGGER.Errorf("fail to connect to event queue for node %s, reason %s", info.NodeID, err.Error())
klog.Errorf("fail to connect to event queue for node %s, reason %s", info.NodeID, err.Error())
notifyEventQueueError(hi, eventQueueDisconnect, info.NodeID)
err = hi.Close()
if err != nil {
bhLog.LOGGER.Errorf("fail to close connection, reason: %s", err.Error())
klog.Errorf("fail to close connection, reason: %s", err.Error())
}
return err
}

err = eh.EventQueue.Publish(info, constructConnectEvent(info, true))
if err != nil {
bhLog.LOGGER.Errorf("fail to publish node connect event for node %s, reason %s", info.NodeID, err.Error())
klog.Errorf("fail to publish node connect event for node %s, reason %s", info.NodeID, err.Error())
notifyEventQueueError(hi, eventQueueDisconnect, info.NodeID)
err = hi.Close()
if err != nil {
bhLog.LOGGER.Errorf("fail to close connection, reason: %s", err.Error())
klog.Errorf("fail to close connection, reason: %s", err.Error())
}
eh.EventQueue.Close(info)
return err
Expand All @@ -286,13 +287,13 @@ func (eh *EventHandle) CancelNode(hi hubio.CloudHubIO, info *emodel.HubInfo, cod

err := eh.EventQueue.Publish(info, constructConnectEvent(info, false))
if err != nil {
bhLog.LOGGER.Errorf("fail to publish node disconnect event for node %s, reason %s", info.NodeID, err.Error())
klog.Errorf("fail to publish node disconnect event for node %s, reason %s", info.NodeID, err.Error())
}
notifyEventQueueError(hi, code, info.NodeID)
eh.Nodes.Delete(info.NodeID)
err = hi.Close()
if err != nil {
bhLog.LOGGER.Errorf("fail to close connection, reason: %s", err.Error())
klog.Errorf("fail to close connection, reason: %s", err.Error())
}
eh.EventQueue.Close(info)
}
Expand All @@ -317,14 +318,14 @@ func (eh *EventHandle) GetWorkload() (float64, error) {
func (eh *EventHandle) EventWriteLoop(hi hubio.CloudHubIO, info *emodel.HubInfo, stop chan ExitCode) {
events, err := eh.EventQueue.Consume(info)
if err != nil {
bhLog.LOGGER.Errorf("failed to consume event for node %s, reason: %s", info.NodeID, err.Error())
klog.Errorf("failed to consume event for node %s, reason: %s", info.NodeID, err.Error())
stop <- eventQueueDisconnect
return
}
for {
event, err := events.Get()
if err != nil {
bhLog.LOGGER.Errorf("failed to consume event for node %s, reason: %s", info.NodeID, err.Error())
klog.Errorf("failed to consume event for node %s, reason: %s", info.NodeID, err.Error())
if err.Error() == MsgFormatError {
// error format message should not impact other message
events.Ack()
Expand All @@ -335,37 +336,37 @@ func (eh *EventHandle) EventWriteLoop(hi hubio.CloudHubIO, info *emodel.HubInfo,
}
isQuery, err := eh.handleNodeQuery(info, event)
if err != nil {
bhLog.LOGGER.Errorf("failed to process node query event for node %s, reason %s", info.NodeID, err.Error())
klog.Errorf("failed to process node query event for node %s, reason %s", info.NodeID, err.Error())
}
if isQuery {
events.Ack()
continue
}

if event.IsNodeStopped() {
bhLog.LOGGER.Infof("node %s is stopped, will disconnect", info.NodeID)
klog.Infof("node %s is stopped, will disconnect", info.NodeID)
events.Ack()
stop <- nodeStop
return
}
if !event.IsToEdge() {
bhLog.LOGGER.Infof("skip only to cloud event for node %s, %s, content %s", info.NodeID, dumpEventMetadata(event), event.Content)
klog.Infof("skip only to cloud event for node %s, %s, content %s", info.NodeID, dumpEventMetadata(event), event.Content)
events.Ack()
continue
}
bhLog.LOGGER.Infof("event to send for node %s, %s, content %s", info.NodeID, dumpEventMetadata(event), event.Content)
klog.Infof("event to send for node %s, %s, content %s", info.NodeID, dumpEventMetadata(event), event.Content)

msg := emodel.EventToMessage(event)
trimMessage(&msg)
err = hi.SetWriteDeadline(time.Now().Add(time.Duration(eh.WriteTimeout) * time.Second))
if err != nil {
bhLog.LOGGER.Errorf("SetWriteDeadline error, %s", err.Error())
klog.Errorf("SetWriteDeadline error, %s", err.Error())
stop <- hubioWriteFail
return
}
err = eh.hubIoWrite(hi, info.NodeID, &msg)
if err != nil {
bhLog.LOGGER.Errorf("write error, connection for node %s will be closed, affected event %s, reason %s",
klog.Errorf("write error, connection for node %s will be closed, affected event %s, reason %s",
info.NodeID, dumpEventMetadata(event), err.Error())
stop <- hubioWriteFail
return
Expand Down
5 changes: 3 additions & 2 deletions cloud/pkg/cloudhub/servers/quicserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"crypto/x509"
"fmt"

bhLog "github.com/kubeedge/beehive/pkg/common/log"
"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/core/context"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/channelq"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/common/util"
Expand Down Expand Up @@ -44,6 +45,6 @@ func StartCloudHub(config *util.Config, eventq *channelq.ChannelEventQueue, c *c
ConnNotify: handler.CloudhubHandler.OnRegister,
ExOpts: api.QuicServerOption{MaxIncomingStreams: config.MaxIncomingStreams},
}
bhLog.LOGGER.Infof("Start cloud hub quic server")
klog.Info("Start cloud hub quic server")
svc.ListenAndServeTLS("", "")
}
5 changes: 3 additions & 2 deletions cloud/pkg/cloudhub/servers/wsserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"crypto/x509"
"fmt"

bhLog "github.com/kubeedge/beehive/pkg/common/log"
"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/core/context"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/channelq"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/common/model"
Expand Down Expand Up @@ -51,7 +52,7 @@ func StartCloudHub(config *util.Config, eventq *channelq.ChannelEventQueue, c *c
ExOpts: api.WSServerOption{Path: "/"},
}

bhLog.LOGGER.Infof("Start cloud hub websocket server")
klog.Info("Start cloud hub websocket server")
go s.ListenAndServeTLS("", "")

return nil
Expand Down
9 changes: 5 additions & 4 deletions cloud/pkg/devicecontroller/config/buffer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config

import (
"k8s.io/klog"

"github.com/kubeedge/beehive/pkg/common/config"
"github.com/kubeedge/beehive/pkg/common/log"
"github.com/kubeedge/kubeedge/cloud/pkg/devicecontroller/constants"
)

Expand All @@ -21,20 +22,20 @@ func InitBufferConfig() {
} else {
UpdateDeviceStatusBuffer = psb
}
log.LOGGER.Infof("Update devicecontroller.buffer.update-device-status: %d", UpdateDeviceStatusBuffer)
klog.Infof("Update devicecontroller.buffer.update-device-status: %d", UpdateDeviceStatusBuffer)

if deb, err := config.CONFIG.GetValue("devicecontroller.buffer.device-event").ToInt(); err != nil {
DeviceEventBuffer = constants.DefaultDeviceEventBuffer
} else {
DeviceEventBuffer = deb
}
log.LOGGER.Infof("Update devicecontroller.buffer.device-event: %d", DeviceEventBuffer)
klog.Infof("Update devicecontroller.buffer.device-event: %d", DeviceEventBuffer)

if dmeb, err := config.CONFIG.GetValue("devicecontroller.buffer.device-model-event").ToInt(); err != nil {
DeviceModelEventBuffer = constants.DefaultDeviceModelEventBuffer
} else {
DeviceModelEventBuffer = dmeb
}
log.LOGGER.Infof("Update devicecontroller.buffer.device-model-event: %d", DeviceModelEventBuffer)
klog.Infof("Update devicecontroller.buffer.device-model-event: %d", DeviceModelEventBuffer)

}
Loading

0 comments on commit dc2f3a0

Please sign in to comment.