Skip to content

Commit

Permalink
fix: plugin logging
Browse files Browse the repository at this point in the history
With go-plugin it is hard to debug the plugins, therefore this change
should allow for more robust logging. We should in the future make this
more confiurable and aligined with the internal logging system

Signed-off-by: Spazzy <brendankamp757@gmail.com>
  • Loading branch information
Spazzy757 committed May 29, 2024
1 parent 6b11ce5 commit 5aca204
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
setLogLevel(lvl, config.AppConfig().LogLevel)

// Load exporter plugins
logger.Info("loading plugins")
logger.Info("loading exporters", "dir", config.AppConfig().Plugins.ExporterDir)
pluginsystem := &plugin.ExportPluginSystem{
Dir: config.AppConfig().Plugins.ExporterDir,
}
Expand All @@ -84,9 +84,11 @@ func main() {
logger.Error("failed to load exporter plugin system", "error", err)
os.Exit(1)
}
logger.Info("finished loading exporters", "output",
fmt.Sprintf("%d loaded", len(pluginsystem.Plugins)))

// Load source plugins
logger.Info("loading sources")
logger.Info("loading sources", "dir", config.AppConfig().Plugins.SourceDir)
sourcePluginSystem := &plugin.SourcePluginSystem{
Dir: config.AppConfig().Plugins.SourceDir,
}
Expand All @@ -96,6 +98,8 @@ func main() {
logger.Error("failed to load exporter plugin system", "error", err)
os.Exit(1)
}
logger.Info("finished loading sources", "output",
fmt.Sprintf("%d loaded", len(sourcePluginSystem.Plugins)))

// Init the application bus
b := bus.New()
Expand Down
7 changes: 7 additions & 0 deletions pkg/plugin/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path/filepath"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

Expand Down Expand Up @@ -133,6 +134,12 @@ func (e *ExportPluginSystem) Load(ctx context.Context) error {
},
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Cmd: exec.Command(pluginPath),
Logger: hclog.New(&hclog.LoggerOptions{
Name: "exporter",
Output: os.Stdout,
Level: hclog.Debug,
JSONFormat: true,
}),
})

// Start the plugin process.
Expand Down
7 changes: 7 additions & 0 deletions pkg/plugin/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/exec"
"path/filepath"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

Expand Down Expand Up @@ -162,6 +163,12 @@ func (s *SourcePluginSystem) Load(ctx context.Context) error {
},
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Cmd: exec.Command(pluginPath),
Logger: hclog.New(&hclog.LoggerOptions{
Name: "source",
Output: os.Stdout,
Level: hclog.Debug,
JSONFormat: true,
}),
})

// Start the plugin process.
Expand Down

0 comments on commit 5aca204

Please sign in to comment.