Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Show error for JS plugin watcher (#2776)
Browse files Browse the repository at this point in the history
* Show error for JS plugin watcher

Signed-off-by: Vikram Yadav <yvikram@vmware.com>

#1273

* log plugin startup errors and resume octant startup

- Do not error out from octant when plugin startup fails

Signed-off-by: Vikram Yadav <yvikram@vmware.com>

#2796
  • Loading branch information
Vikram Yadav authored Aug 27, 2021
1 parent 12b3e72 commit d01da3d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 28 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/2776-xtreme-vikram-yadav
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logged better errors for JS plugin watcher
60 changes: 32 additions & 28 deletions pkg/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,18 @@ func (m *Manager) watchJS(ctx context.Context) {
}
}()

watchedDirs := []string{}
for _, dir := range dirs {
if err := watcher.Add(dir); err != nil {
logger.Warnf("unable to add %s to JavaScript plugin watcher", dir)
logger.Warnf("Unable to add %s to JavaScript plugin watcher. Error: %s\n", dir, err)
} else {
watchedDirs = append(watchedDirs, dir)
}
}

logger.Infof("watching for new JavaScript plugins in %q", dirs)
if len(watchedDirs) > 0 {
logger.Infof("Watching for new JavaScript plugins in %q\n", dirs)
}

writeEvents := make(map[string]bool)
updatePlugin := func(name string) {
Expand All @@ -392,26 +397,26 @@ func (m *Manager) watchJS(ctx context.Context) {
case <-ctx.Done():
logger.Infof("context cancelled shutting down JavaScript plugin watcher.")
return
case event, ok := <-watcher.Events:
case ev, ok := <-watcher.Events:
if !ok {
logger.Errorf("bad event returned from JavaScript plugin watcher")
return
}
if event.Op&(fsnotify.Chmod|fsnotify.Write|fsnotify.Create) == fsnotify.Chmod {
if ev.Op&(fsnotify.Chmod|fsnotify.Write|fsnotify.Create) == fsnotify.Chmod {
continue
}
if IsJavaScriptPlugin(event.Name) {
if event.Op&fsnotify.Remove == fsnotify.Remove {
jsPlugin, ok := m.store.GetJS(event.Name)
if IsJavaScriptPlugin(ev.Name) {
if ev.Op&fsnotify.Remove == fsnotify.Remove {
jsPlugin, ok := m.store.GetJS(ev.Name)
if ok {
if err := m.unregisterJSPlugin(ctx, jsPlugin); err != nil {
logger.Errorf("unregistering: %w", err)
}
m.store.RemoveJS(event.Name)
logger.Infof("removing: JavaScript plugin: %s", event.Name)
m.store.RemoveJS(ev.Name)
logger.Infof("removing: JavaScript plugin: %s", ev.Name)
}
} else if event.Op&fsnotify.Write == fsnotify.Write {
writeEvents[event.Name] = true
} else if ev.Op&fsnotify.Write == fsnotify.Write {
writeEvents[ev.Name] = true
}
}
case err, ok := <-watcher.Errors:
Expand Down Expand Up @@ -496,21 +501,9 @@ func (m *Manager) registerJSPlugin(ctx context.Context, pluginPath string) error
return nil
}

func (m *Manager) startJS(ctx context.Context) error {
pluginList, err := AvailablePlugins(DefaultConfig)
if err != nil {
return err
}

for _, pluginPath := range pluginList {
if IsJavaScriptPlugin(pluginPath) {
logger := log.From(ctx)
logger.Debugf("creating ts plugin client")

if err := m.registerJSPlugin(ctx, pluginPath); err != nil {
return fmt.Errorf("javascript plugin: %w", err)
}
}
func (m *Manager) startJS(ctx context.Context, pluginPath string) error {
if err := m.registerJSPlugin(ctx, pluginPath); err != nil {
return fmt.Errorf("javascript plugin: %w", err)
}

return nil
Expand All @@ -536,17 +529,28 @@ func (m *Manager) Start(ctx context.Context) error {
m.lock.Lock()
defer m.lock.Unlock()

if err := m.startJS(ctx); err != nil {
pluginList, err := AvailablePlugins(DefaultConfig)
if err != nil {
return err
}
for _, pluginPath := range pluginList {
if IsJavaScriptPlugin(pluginPath) {
logger := log.From(ctx)
logger.Debugf("creating ts plugin client")

if err := m.startJS(ctx, pluginPath); err != nil {
logger.Warnf("start JS plugin: %s\n", err)
}
}
}

go m.watchJS(ctx)

for i := range m.configs {
c := m.configs[i]

if err := m.start(ctx, c); err != nil {
return err
logger.Warnf("start plugin: %s\n", err)
}
}

Expand Down

0 comments on commit d01da3d

Please sign in to comment.