Skip to content
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: 2 additions & 0 deletions cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func pollCollectorSetStatus(conn *grpc.ClientConn) (bool, error) {
case <-timeout:
return false, fmt.Errorf("Timeout waiting for collectors to become available")
case <-ticker.C:
log.Debugf("Checking collectors status")
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*500)
defer cancel()
req := &healthpb.HealthCheckRequest{
Expand All @@ -126,6 +127,7 @@ func pollCollectorSetStatus(conn *grpc.ClientConn) (bool, error) {
if healthCheckResponse.GetStatus() == healthpb.HealthCheckResponse_SERVING {
return true, nil
}
log.Debugf("The collectors are not ready: %d", healthCheckResponse.GetStatus())
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func buildDevice(c *config.Config, client api.CollectorSetControllerClient, opti

reply, err := client.CollectorID(context.Background(), &api.CollectorIDRequest{})
if err != nil {
log.Printf("Failed to get collector ID: %v", err)
log.Errorf("Failed to get collector ID: %v", err)
} else {
log.Printf("Using collector ID %d for %q", reply.Id, device.DisplayName)
log.Infof("Using collector ID %d for %q", reply.Id, device.DisplayName)
device.PreferredCollectorId = reply.Id
}

Expand Down Expand Up @@ -100,7 +100,7 @@ func (m *Manager) UpdateAndReplaceByDisplayName(name string, options ...types.De
}

if d == nil {
log.Printf("Could not find device %q", name)
log.Warnf("Could not find device %q", name)
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sync/initsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (i *InitSyncer) InitSync() {

// wait the init sync processes finishing
wg.Wait()
log.Infof("Finish syncing the resource devices")
}
log.Infof("Finished syncing the resource devices")
}

func (i *InitSyncer) intSyncNodes(parentGroupID int32) {
Expand Down
18 changes: 9 additions & 9 deletions pkg/utilities/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func GetLabelByPrefix(prefix string, labels map[string]string) (string, string)

// CheckAllErrors is a helper function to deal with the number of possible places that an API call can fail.
func CheckAllErrors(restResponse interface{}, apiResponse *logicmonitor.APIResponse, err error) error {
if err != nil {
return fmt.Errorf("[ERROR] %v", err)
}

if apiResponse.Response != nil && apiResponse.StatusCode != http.StatusOK {
metrics.APIError()
return fmt.Errorf("[API] [%d] %s", apiResponse.StatusCode, apiResponse.Message)
}

var restResponseMessage string
var restResponseStatus int64

Expand Down Expand Up @@ -62,14 +71,5 @@ func CheckAllErrors(restResponse interface{}, apiResponse *logicmonitor.APIRespo
return fmt.Errorf("[REST] [%d] %s", restResponseStatus, restResponseMessage)
}

if apiResponse.StatusCode != http.StatusOK {
metrics.APIError()
return fmt.Errorf("[API] [%d] %s", apiResponse.StatusCode, restResponseMessage)
}

if err != nil {
return fmt.Errorf("[ERROR] %v", err)
}

return nil
}
8 changes: 6 additions & 2 deletions pkg/watch/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func (w Watcher) ObjType() runtime.Object {
func (w Watcher) AddFunc() func(obj interface{}) {
return func(obj interface{}) {
namespace := obj.(*v1.Namespace)
log.Debugf("Handling add namespace event: %s", namespace.Name)
for name, parentID := range w.DeviceGroups {
var appliesTo devicegroup.AppliesToBuilder
// Ensure that we are creating namespaces for namespaced resources.
Expand Down Expand Up @@ -62,14 +63,15 @@ func (w Watcher) AddFunc() func(obj interface{}) {
return
}

log.Printf("Added namespace %q to %q", namespace.Name, name)
log.Infof("Added namespace %q to %q", namespace.Name, name)
}
}
}

// UpdateFunc is a function that implements the Watcher interface.
func (w Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
return func(oldObj, newObj interface{}) {
log.Debugf("Ignoring update namespace event")
// oldNamespace := oldObj.(*v1.Namespace)
// newNamespace := newObj.(*v1.Namespace)
}
Expand All @@ -79,10 +81,12 @@ func (w Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
func (w Watcher) DeleteFunc() func(obj interface{}) {
return func(obj interface{}) {
namespace := obj.(*v1.Namespace)
log.Debugf("Handle deleting namespace event: %s", namespace.Name)

for name, parentID := range w.DeviceGroups {
deviceGroup, err := devicegroup.Find(parentID, name, w.LMClient)
if err != nil {
log.Printf("Failed to find namespace %s: %v", name, err)
log.Warnf("Failed to find namespace %s: %v", name, err)
return
}
// We should only be returned a device group if it is namespaced.
Expand Down
8 changes: 4 additions & 4 deletions pkg/watch/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (w *Watcher) AddFunc() func(obj interface{}) {
return func(obj interface{}) {
node := obj.(*v1.Node)

log.Debugf("received ADD event: %s", node.Name)
log.Debugf("Handling add node event: %s", node.Name)

// Require an IP address.
if getInternalAddress(node.Status.Addresses) == nil {
Expand All @@ -59,7 +59,7 @@ func (w *Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
old := oldObj.(*v1.Node)
new := newObj.(*v1.Node)

log.Debugf("received UPDATE event: %s", old.Name)
log.Debugf("Handling update node event: %s", old.Name)

// If the old node does not have an IP, then there is no way we could
// have added it to LogicMonitor. Therefore, it must be a new device.
Expand All @@ -83,7 +83,7 @@ func (w *Watcher) DeleteFunc() func(obj interface{}) {
return func(obj interface{}) {
node := obj.(*v1.Node)

log.Debugf("received DELETE event: %s", node.Name)
log.Debugf("Handling delete node event: %s", node.Name)

// Delete the node.
if w.Config().DeleteDevices {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (w *Watcher) createRoleDeviceGroup(labels map[string]string) {
return
}

log.Printf("Added device group for node role %q", role)
log.Infof("Added device group for node role %q", role)
}

// GetNodesMap implements the getting nodes map info from k8s
Expand Down
6 changes: 3 additions & 3 deletions pkg/watch/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (w *Watcher) AddFunc() func(obj interface{}) {
return func(obj interface{}) {
pod := obj.(*v1.Pod)

log.Debugf("received ADD event: %s", pod.Name)
log.Debugf("Handling add pod event: %s", pod.Name)

// Require an IP address.
if pod.Status.PodIP == "" {
Expand All @@ -53,7 +53,7 @@ func (w *Watcher) UpdateFunc() func(oldObj, newObj interface{}) {
old := oldObj.(*v1.Pod)
new := newObj.(*v1.Pod)

log.Debugf("received UPDATE event: %s", old.Name)
log.Debugf("Handling update pod event: %s", old.Name)

// If the old pod does not have an IP, then there is no way we could
// have added it to LogicMonitor. Therefore, it must be a new w.
Expand Down Expand Up @@ -83,7 +83,7 @@ func (w *Watcher) DeleteFunc() func(obj interface{}) {
return func(obj interface{}) {
pod := obj.(*v1.Pod)

log.Debugf("received DELETE event: %s", pod.Name)
log.Debugf("Handling delete pod event: %s", pod.Name)

// Delete the pod.
if w.Config().DeleteDevices {
Expand Down