generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engineoption.go
127 lines (108 loc) · 3.66 KB
/
engineoption.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package veracity
import (
"log/slog"
"github.com/dogmatiq/enginekit/protobuf/uuidpb"
"github.com/dogmatiq/persistencekit/journal"
"github.com/dogmatiq/persistencekit/kv"
"github.com/dogmatiq/veracity/internal/engineconfig"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"google.golang.org/grpc"
)
// FerriteRegistry is a registry of the environment variables used by Veracity.
//
// It can be used with the [ferrite] package.
var FerriteRegistry = engineconfig.FerriteRegistry
// An EngineOption configures the behavior of an [Engine].
type EngineOption func(*engineconfig.Config)
// WithOptionsFromEnvironment is an engine option that configures the engine
// using options specified via environment variables.
//
// Any explicit options passed to [New] take precedence over options from the
// environment.
func WithOptionsFromEnvironment() EngineOption {
return func(cfg *engineconfig.Config) {
cfg.UseEnv = true
}
}
// WithNodeID is an [EngineOption] that sets the node ID of the engine.
func WithNodeID(id *uuidpb.UUID) EngineOption {
if err := id.Validate(); err != nil {
panic(err)
}
return func(cfg *engineconfig.Config) {
cfg.NodeID = id
}
}
// WithTracerProvider is an [EngineOption] that sets the OpenTelemetry tracer
// provider used by the engine.
func WithTracerProvider(p trace.TracerProvider) EngineOption {
if p == nil {
panic("tracer provider must not be nil")
}
return func(cfg *engineconfig.Config) {
cfg.Telemetry.TracerProvider = p
}
}
// WithMetricProvider is an [EngineOption] that sets the OpenTelemetry meter
// provider used by the engine.
func WithMetricProvider(p metric.MeterProvider) EngineOption {
if p == nil {
panic("metric provider must not be nil")
}
return func(cfg *engineconfig.Config) {
cfg.Telemetry.MeterProvider = p
}
}
// WithLogger is an [EngineOption] that setes the logger used by the engine.
func WithLogger(l *slog.Logger) EngineOption {
if l == nil {
panic("logger must not be nil")
}
return func(cfg *engineconfig.Config) {
cfg.Telemetry.Logger = l
}
}
// WithJournalStore is an [EngineOption] that sets the journal store used by the
// engine.
func WithJournalStore(s journal.BinaryStore) EngineOption {
return func(cfg *engineconfig.Config) {
cfg.Persistence.Journals = s
}
}
// WithKeyValueStore is an [EngineOption] that sets the key/value store used by
// the engine.
func WithKeyValueStore(s kv.BinaryStore) EngineOption {
return func(cfg *engineconfig.Config) {
cfg.Persistence.Keyspaces = s
}
}
// WithGRPCListenAddress is an [EngineOption] that sets the network address for
// the engine's internal gRPC server.
func WithGRPCListenAddress(addr string) EngineOption {
return func(cfg *engineconfig.Config) {
cfg.GRPC.ListenAddress = addr
}
}
// WithGRPCAdvertiseAddresses is an [EngineOption] that sets the network
// addresses at which the engine's internal gRPC server can be reached by other
// nodes in the cluster.
func WithGRPCAdvertiseAddresses(addresses ...string) EngineOption {
return func(cfg *engineconfig.Config) {
cfg.GRPC.AdvertiseAddresses = addresses
}
}
// WithGRPCDialOptions is an [EngineOption] that sets the gRPC options to use
// when connecting to other nodes in the cluster.
func WithGRPCDialOptions(options ...grpc.DialOption) EngineOption {
return func(cfg *engineconfig.Config) {
cfg.GRPC.DialOptions = append(cfg.GRPC.DialOptions, options...)
}
}
// WithGRPCServerOptions is an [EngineOption] that sets
// the gRPC options to use when starting the internal gRPC server.
func WithGRPCServerOptions(options ...grpc.ServerOption) EngineOption {
return func(cfg *engineconfig.Config) {
cfg.GRPC.ServerOptions = append(cfg.GRPC.ServerOptions, options...)
}
}