forked from hashicorp/nomad-autoscaler
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plugins: improve external plugin development UX and mimic Nomad. (has…
…hicorp#82) The UX for developing external plugins was OK, but required some knowledge of the go-plugin library in order to correctly setup and serve the plugin. This change aims to lower the barrier to entry on writing plugins by making the required code simpler and also mimicking the Nomad plugin interface. PluginInfo has been moved into the base package as part of this work. This seems a better logic location for the definition as it is the response object of a defined interface function inside this package. Co-Authored-By: Chris Baker <[email protected]>
- Loading branch information
Showing
15 changed files
with
109 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/go-plugin" | ||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/nomad-autoscaler/plugins" | ||
"github.com/hashicorp/nomad-autoscaler/plugins/apm" | ||
nomadapm "github.com/hashicorp/nomad-autoscaler/plugins/builtin/apm/nomad/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: plugins.Handshake, | ||
Plugins: map[string]plugin.Plugin{ | ||
plugins.PluginTypeAPM: &apm.Plugin{Impl: &nomadapm.APMPlugin{}}, | ||
}, | ||
}) | ||
plugins.Serve(factory) | ||
} | ||
|
||
// factory returns a new instance of the Nomad APM plugin. | ||
func factory(log hclog.Logger) interface{} { | ||
return nomadapm.NewNomadPlugin(log) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
plugin "github.com/hashicorp/go-plugin" | ||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/nomad-autoscaler/plugins" | ||
"github.com/hashicorp/nomad-autoscaler/plugins/apm" | ||
prometheus "github.com/hashicorp/nomad-autoscaler/plugins/builtin/apm/prometheus/plugin" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: plugins.Handshake, | ||
Plugins: map[string]plugin.Plugin{ | ||
plugins.PluginTypeAPM: &apm.Plugin{Impl: &prometheus.APMPlugin{}}, | ||
}, | ||
}) | ||
plugins.Serve(factory) | ||
} | ||
|
||
// factory returns a new instance of the Prometheus APM plugin. | ||
func factory(log hclog.Logger) interface{} { | ||
return prometheus.NewPrometheusPlugin(log) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/go-plugin" | ||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/nomad-autoscaler/plugins" | ||
targetvalue "github.com/hashicorp/nomad-autoscaler/plugins/builtin/strategy/target-value/plugin" | ||
"github.com/hashicorp/nomad-autoscaler/plugins/strategy" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: plugins.Handshake, | ||
Plugins: map[string]plugin.Plugin{ | ||
plugins.PluginTypeStrategy: &strategy.Plugin{Impl: &targetvalue.StrategyPlugin{}}, | ||
}, | ||
}) | ||
plugins.Serve(factory) | ||
} | ||
|
||
// factory returns a new instance of the TargetValue Strategy plugin. | ||
func factory(log hclog.Logger) interface{} { | ||
return targetvalue.NewTargetValuePlugin(log) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/go-plugin" | ||
hclog "github.com/hashicorp/go-hclog" | ||
"github.com/hashicorp/nomad-autoscaler/plugins" | ||
nomadtarget "github.com/hashicorp/nomad-autoscaler/plugins/builtin/target/nomad/plugin" | ||
"github.com/hashicorp/nomad-autoscaler/plugins/target" | ||
) | ||
|
||
func main() { | ||
plugin.Serve(&plugin.ServeConfig{ | ||
HandshakeConfig: plugins.Handshake, | ||
Plugins: map[string]plugin.Plugin{ | ||
plugins.PluginTypeTarget: &target.Plugin{Impl: &nomadtarget.TargetPlugin{}}, | ||
}, | ||
}) | ||
plugins.Serve(factory) | ||
} | ||
|
||
// factory returns a new instance of the Nomad Target plugin. | ||
func factory(log hclog.Logger) interface{} { | ||
return nomadtarget.NewNomadPlugin(log) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.