Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/component/module/string/string.go
4095 views
1
package string
2
3
import (
4
"context"
5
"net/http"
6
7
"github.com/grafana/agent/component"
8
"github.com/grafana/agent/component/module"
9
"github.com/grafana/agent/pkg/river/rivertypes"
10
)
11
12
func init() {
13
component.Register(component.Registration{
14
Name: "module.string",
15
Args: Arguments{},
16
Exports: module.Exports{},
17
18
Build: func(opts component.Options, args component.Arguments) (component.Component, error) {
19
return New(opts, args.(Arguments))
20
},
21
})
22
}
23
24
// Arguments holds values which are used to configure the module.string
25
// component.
26
type Arguments struct {
27
// Content to load for the module.
28
Content rivertypes.OptionalSecret `river:"content,attr"`
29
30
// Arguments to pass into the module.
31
Arguments map[string]any `river:"arguments,block,optional"`
32
}
33
34
// Component implements the module.string component.
35
type Component struct {
36
mod *module.ModuleComponent
37
}
38
39
var (
40
_ component.Component = (*Component)(nil)
41
_ component.HealthComponent = (*Component)(nil)
42
_ component.HTTPComponent = (*Component)(nil)
43
)
44
45
// New creates a new module.string component.
46
func New(o component.Options, args Arguments) (*Component, error) {
47
c := &Component{
48
mod: module.NewModuleComponent(o),
49
}
50
51
if err := c.Update(args); err != nil {
52
return nil, err
53
}
54
return c, nil
55
}
56
57
// Run implements component.Component.
58
func (c *Component) Run(ctx context.Context) error {
59
c.mod.RunFlowController(ctx)
60
return nil
61
}
62
63
// Update implements component.Component.
64
func (c *Component) Update(args component.Arguments) error {
65
newArgs := args.(Arguments)
66
67
return c.mod.LoadFlowContent(newArgs.Arguments, newArgs.Content.Value)
68
}
69
70
// Handler implements component.HTTPComponent.
71
func (c *Component) Handler() http.Handler {
72
return c.mod.Handler()
73
}
74
75
// CurrentHealth implements component.HealthComponent.
76
func (c *Component) CurrentHealth() component.Health {
77
return c.mod.CurrentHealth()
78
}
79
80