-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.go
47 lines (41 loc) · 1.38 KB
/
manage.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
package datasource
import (
"fmt"
"os"
"github.com/famarks/grafarg-plugin-sdk-go/backend"
"github.com/famarks/grafarg-plugin-sdk-go/backend/tracing"
"github.com/famarks/grafarg-plugin-sdk-go/internal/automanagement"
"github.com/famarks/grafarg-plugin-sdk-go/internal/buildinfo"
)
// ManageOpts can modify Manage behaviour.
type ManageOpts struct {
// GRPCSettings settings for gPRC.
GRPCSettings backend.GRPCSettings
// TracingOpts contains settings for tracing setup.
TracingOpts tracing.Opts
}
// Manage starts serving the data source over gPRC with automatic instance management.
// pluginID should match the one from plugin.json.
func Manage(pluginID string, instanceFactory InstanceFactoryFunc, opts ManageOpts) error {
// If we are running in build info mode, run that and exit
if buildinfo.InfoModeEnabled() {
if err := buildinfo.RunInfoMode(); err != nil {
os.Exit(1)
return err
}
os.Exit(0)
return nil
}
backend.SetupPluginEnvironment(pluginID)
if err := backend.SetupTracer(pluginID, opts.TracingOpts); err != nil {
return fmt.Errorf("setup tracer: %w", err)
}
handler := automanagement.NewManager(NewInstanceManager(instanceFactory))
return backend.Manage(pluginID, backend.ServeOpts{
CheckHealthHandler: handler,
CallResourceHandler: handler,
QueryDataHandler: handler,
StreamHandler: handler,
GRPCSettings: opts.GRPCSettings,
})
}