-
Notifications
You must be signed in to change notification settings - Fork 25
/
provide.go
42 lines (35 loc) · 1.03 KB
/
provide.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
package alerts
import (
"go.uber.org/fx"
"github.com/fluxninja/aperture/v2/pkg/config"
"github.com/fluxninja/aperture/v2/pkg/log"
)
const configKey = "alerter"
// AlerterConfig for alerter.
// swagger:model
// +kubebuilder:object:generate=true
type AlerterConfig struct {
// ChannelSize size of the alerts channel in the alerter. Alerts should be
// consumed from it quickly, so no big sizes are needed.
ChannelSize int `json:"channel_size" validate:"gt=0" default:"100"`
}
// Module is a fx module that constructs annotated instance of alerts.Alerter.
func Module() fx.Option {
return fx.Options(
fx.Provide(
fx.Annotate(
ProvideAlerter,
fx.ResultTags(AlertsFxTag),
),
),
)
}
// ProvideAlerter creates an alerter.
func ProvideAlerter(unmarshaller config.Unmarshaller) (Alerter, error) {
var cfg AlerterConfig
if err := unmarshaller.UnmarshalKey(configKey, &cfg); err != nil {
log.Error().Err(err).Msg("Unable to deserialize alerter configuration!")
return nil, err
}
return NewSimpleAlerter(cfg.ChannelSize), nil
}