Documentation
¶
Overview ¶
Draft is a light weight micro-services chassis used to sow a few runtime dependances together
Index ¶
- Constants
- func Unwrap(err error) error
- type BlueprintCluster
- type Broker
- type CloseChan
- type Config
- type ConsensusKind
- type ConsensusRegistrar
- type Consumer
- type Default
- type Error
- type Fields
- type LogLevel
- type Logger
- type PublishOptions
- type RPCHandlerKind
- type RPCRegistrar
- type RaftController
- type RaftRPCHandler
- type Reader
- type RegistrationOptions
- type Repository
- type Rpcer
- type Runtime
- func (c *Runtime) DisableMux() *Runtime
- func (c *Runtime) Register(options RegistrationOptions) *Runtime
- func (c *Runtime) Start()
- func (c *Runtime) WithBroker(plugin Broker) *Runtime
- func (c *Runtime) WithClientApplication(files embed.FS, rootDir string) *Runtime
- func (c *Runtime) WithConsensus(kind ConsensusKind, plugin ConsensusRegistrar) *Runtime
- func (c *Runtime) WithRPCHandler(plugin RPCRegistrar) *Runtime
- func (c *Runtime) WithRepository(plugin Repository) *Runtime
- func (c *Runtime) WithRoute(route *ntv1.Route) *Runtime
- func (c *Runtime) WithRunner(f func()) *Runtime
- func (c *Runtime) WithSecretStore(plugin SecretStore) *Runtime
- type SecretStore
- type SubscribeOptions
- type UnsubscribeOptions
- type Writer
Constants ¶
const ( SYNC_INTERVAL = 5 * time.Second INTITIALIZE_LIMIT = 5 )
const (
ErrProcessRegistrationFailed = "failed to connect to blueprint"
)
///////////////// System Functions /////////////////
const (
FuseAddressBlueprintKey = "fuse_address"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BlueprintCluster ¶
func (*BlueprintCluster) NodeCount ¶
func (b *BlueprintCluster) NodeCount() int
func (*BlueprintCluster) Pop ¶
func (b *BlueprintCluster) Pop() *sdv1.Node
remove the first item from the `Nodes` slice while returning the same value
type CloseChan ¶
CloseChan is used to signal to the runtime that all servers, and connections need to be closed down.
type Config ¶
type Config interface {
Name() string
Domain() string
NodeID() string
Title() string
Env() string
LogLevel() LogLevel
Reader
Writer
Entrypoint() string
}
func LoadConfig ¶
func LoadConfig() Config
TODO -> Read config from the key/value store and not from a local static file.
type ConsensusKind ¶
type ConsensusKind int
const ( NullConsensusKind ConsensusKind = iota Raft )
func (ConsensusKind) String ¶
func (ck ConsensusKind) String() string
String - get the human readable value for `ConsensusKind`
type ConsensusRegistrar ¶
type ConsensusRegistrar interface {
RegisterConsensus(interface{}) error
// LeadershipChange is a callback for the consensus system to notify when a leadership change is made. The
// leader parameter is true when the node becomes the leader, and false when it becomes a follower. The address
// parameter is the URL of this node and should be persisted to raft for other nodes to forward write requests to.
LeadershipChange(log Logger, leader bool, address string)
raft.FSM
}
type Consumer ¶
type Consumer interface {
Consume(ctx context.Context, event *events.CloudEvent) error
}
type Default ¶
type Default interface {
RPCRegistrar
ConsensusRegistrar
}
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is a custom error type that wraps a standard Go error with additional contextual information
func Wrap ¶
Wrap creates a customError from a given standard Go error and logger fields. It pulls out the caller function name, file name, and line number from the runtime.
func (Error) Error ¶
Error returns the error message as a string in the form of:
"[main.FunctionA]->[module/package1.FunctionB]->[module/package2.FunctionC]->[original error message]"
type LogLevel ¶
type LogLevel uint32
LogLevel type
const ( // PanicLevel level, highest level of severity. Logs and then calls panic with the // message passed to Debug, Info, ... PanicLevel LogLevel = iota // FatalLevel level. Logs and then calls `os.Exit(1)`. It will exit even if the // logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on inside the // application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose logging. DebugLevel // TraceLevel level. Designates finer-grained informational events than the Debug. TraceLevel )
func ParseLogLevel ¶
ParseLogLevel takes a string level and returns the log level constant.
type Logger ¶
type Logger interface {
// Start configures the logger for service startup
Start(config Config)
// SetLevel sets the logging level for the logger
SetLevel(level LogLevel)
// GetLevel gets the current logging level for the logger
GetLevel() LogLevel
// Wrap wraps an error with the additional context of current
// logger fields and call stack information.
Wrap(error) error
// WithError - Add an error as single field (using the key defined in ErrorKey) to the logger.
WithError(err error) Logger
// WithContext - Add a context to the logger.
WithContext(ctx context.Context) Logger
// WithField - Add a single field to the logger.
WithField(key string, value any) Logger
// WithFields - Add a map of fields to the logger.
WithFields(fields Fields) Logger
// WithCallDepth - Configures the number of frames to skip on the stack when determining the function name of the caller.
// Useful when wrapping the Logger interface for compatability with other logging interfaces.
WithCallDepth(depth int) Logger
// Trace - Definition:
// "Seriously, WTF is going on here?!?!
// I need to log every single statement I execute to find this @#$@ing memory corruption bug before I go insane"
Trace(msg string)
// Debug - Definition:
// Off by default, able to be turned on for debugging specific unexpected problems.
// This is where you might log detailed information about key method parameters or
// other information that is useful for finding likely problems in specific 'problematic' areas of the code.
Debug(msg string)
Debugf(format string, args ...any)
// Info - Definition:
// Normal logging that's part of the normal operation of the app;
// diagnostic stuff so you can go back and say 'how often did this broad-level operation happen?',
// or 'how did the user's data get into this state?'
Info(msg string)
Infof(format string, args ...any)
// Warn - Definition:
// something that's concerning but not causing the operation to abort;
// # of connections in the DB pool getting low, an unusual-but-expected timeout in an operation, etc.
// Think of 'WARN' as something that's useful in aggregate; e.g. grep, group,
// and count them to get a picture of what's affecting the system health
Warn(msg string)
Warnf(format string, args ...any)
// Error - Definition:
// something that the app's doing that it shouldn't.
// This isn't a user error ('invalid search query');
// it's an assertion failure, network problem, etc etc.,
// probably one that is going to abort the current operation
Error(msg string)
Errorf(format string, args ...any)
// WrappedError - Definition:
// this is a convenience method that calls Error() but makes sure to wrap the error a final time
// so that all current call context is included in the error. This has the same output as:
// logger.WithFields(logger.WrapError(err).Fields()).WithError(logger.WrapError(err)).Error("failed to process request")
// but instead has a much simpler oneliner of:
// logger.WrappedError(err, "failed to process request")
WrappedError(error, string)
// Fatal - Definition:
// the app (or at the very least a thread) is about to die horribly.
// This is where the info explaining why that's happening goes.
Fatal(msg string)
// Panic - Definition:
// Be careful about calling this vs Fatal:
// - For Fatal level, the log message goes to the configured log output, while panic is only going to write to stderr.
// - Panic will print a stack trace, which may not be relevant to the error at all.
// - Defers will be executed when a program panics, but calling os.Exit exits immediately, and deferred functions can't be run.
// In general, only use panic for programming errors, where the stack trace is important to the context of the error.
// If the message isn't targeted at the programmer, you're simply hiding the message in superfluous data.
Panic(msg string)
}
type PublishOptions ¶
type PublishOptions struct {
Event *events.CloudEvent
// Tags are an optional list of strings that can be used to contextualize the event. For example, a tag could be used in
// a blue/green deployment scenario to indicate which version of the application published the event. Keep in mind that tags
// are only *contextual* data and though they do affect the routing of the event, they do not affect the content of the event.
// For a consumer to receive an event, it must have a matching event type and all tags that were used when the event was published.
// Tags will be sorted alphabetically before being used to route the event so that the order of the tags does not matter.
Tags []string
}
type RPCHandlerKind ¶
type RPCHandlerKind int
const ( NullRPCHandlerKind RPCHandlerKind = iota Grpc )
type RPCRegistrar ¶
type RPCRegistrar interface {
RegisterRPC(server Rpcer)
}
type RaftController ¶
type RaftController interface {
Join(ctx context.Context, nodeID, raftAddress string) error
Stats(ctx context.Context) map[string]string
GetClusterDetails() raft.Configuration
}
func NewRaftController ¶
func NewRaftController(r *raft.Raft) RaftController
type RaftRPCHandler ¶
type RaftRPCHandler interface {
RPCRegistrar
rfConnect.RaftServiceHandler
}
func NewRaftRPCHandler ¶
func NewRaftRPCHandler(raftController RaftController) RaftRPCHandler
type Reader ¶
type Reader interface {
Get(key string) interface{}
GetString(key string) string
GetBool(key string) bool
GetInt(key string) int
GetInt32(key string) int32
GetInt64(key string) int64
GetUint(key string) uint
GetUint16(key string) uint16
GetUint32(key string) uint32
GetUint64(key string) uint64
GetFloat64(key string) float64
GetTime(key string) time.Time
GetDuration(key string) time.Duration
GetIntSlice(key string) []int
GetStringSlice(key string) []string
GetStringMap(key string) map[string]interface{}
GetStringMapString(key string) map[string]string
GetStringMapStringSlice(key string) map[string][]string
GetSizeInBytes(key string) uint
Unmarshal(rawVal interface{}, opts ...viper.DecoderConfigOption) error
UnmarshalKey(key string, rawVal interface{}, opts ...viper.DecoderConfigOption) error
}
type RegistrationOptions ¶
type Repository ¶
type Runtime ¶
type Runtime struct {
RaftController RaftController
// contains filtered or unexported fields
}
func (*Runtime) DisableMux ¶
func (*Runtime) Register ¶
func (c *Runtime) Register(options RegistrationOptions) *Runtime
func (*Runtime) Start ¶
func (c *Runtime) Start()
Start the runtime of the service. This will do things like run the grpc server and consumers and put them on a background goroutine
func (*Runtime) WithBroker ¶
func (*Runtime) WithClientApplication ¶
func (*Runtime) WithConsensus ¶
func (c *Runtime) WithConsensus(kind ConsensusKind, plugin ConsensusRegistrar) *Runtime
func (*Runtime) WithRPCHandler ¶
func (c *Runtime) WithRPCHandler(plugin RPCRegistrar) *Runtime
func (*Runtime) WithRepository ¶
func (c *Runtime) WithRepository(plugin Repository) *Runtime
func (*Runtime) WithRunner ¶
WithRunner adds a function to be called in a goroutine when Runtime.Start is called
func (*Runtime) WithSecretStore ¶
func (c *Runtime) WithSecretStore(plugin SecretStore) *Runtime
type SecretStore ¶
type SubscribeOptions ¶
type SubscribeOptions struct {
Event *events.CloudEvent
// Tags are an optional list of strings that can be used to filter the events that are received. For example, a tag could be used
// in a blue/green deployment scenario to filter out events that were published by the other version of the application. If no tags
// are provided, all events that match the provided Event will be received.
Tags []string
Consumer Consumer
// Group is the name of the group the consumer belongs to. If not empty, messages delivered to the group
// will be load-balanced across all consumers within the group. If empty, the consumer will receive all
// messages that match the provided Event and Tags.
//
// WARNING: Make sure that this value is globally unique across all other groups that are consuming the same event. Otherwise
// messages could be delivered to consumers unintentionally.
Group string
// IgnoreType states whether the subscribing consumer should ignore the event type when receiving messages. If true, the consumer
// will receive all events that match Event.Source and any provided Tags. If false, the consumer will only receive events that match
// Event.Source, Event.Type, and any provided Tags.
IgnoreType bool
}
type UnsubscribeOptions ¶
type UnsubscribeOptions struct {
Event *events.CloudEvent
Tags []string
IgnoreType bool
}