-
Notifications
You must be signed in to change notification settings - Fork 84
/
plugin.go
65 lines (51 loc) · 1.34 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package plugin
import (
"fmt"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad-autoscaler/plugins"
"github.com/hashicorp/nomad-autoscaler/plugins/apm"
"github.com/hashicorp/nomad-autoscaler/plugins/base"
"github.com/hashicorp/nomad-autoscaler/sdk"
nomadHelper "github.com/hashicorp/nomad-autoscaler/sdk/helper/nomad"
"github.com/hashicorp/nomad/api"
)
const (
// pluginName is the name of the plugin
pluginName = "nomad-apm"
)
var (
PluginID = plugins.PluginID{
Name: pluginName,
PluginType: sdk.PluginTypeAPM,
}
PluginConfig = &plugins.InternalPluginConfig{
Factory: func(l hclog.Logger) interface{} { return NewNomadPlugin(l) },
}
pluginInfo = &base.PluginInfo{
Name: pluginName,
PluginType: sdk.PluginTypeAPM,
}
)
type APMPlugin struct {
client *api.Client
logger hclog.Logger
}
func NewNomadPlugin(log hclog.Logger) apm.APM {
return &APMPlugin{
logger: log,
}
}
func (a *APMPlugin) SetConfig(config map[string]string) error {
cfg := nomadHelper.ConfigFromNamespacedMap(config)
client, err := api.NewClient(cfg)
if err != nil {
return fmt.Errorf("failed to instantiate Nomad client: %v", err)
}
a.client = client
return nil
}
func (a *APMPlugin) PluginInfo() (*base.PluginInfo, error) {
return pluginInfo, nil
}