Documentation ¶
Overview ¶
Package directorobs contains a pre-packaged observer set for the test director.
Index ¶
- Variables
- type Forward
- func ForwardAnalysisMessage(c director.Cycle, m analysis.Analysis) Forward
- func ForwardBuildMessage(c director.Cycle, m builder.Message) Forward
- func ForwardCompilerMessage(c director.Cycle, m compiler.Message) Forward
- func ForwardCopyMessage(c director.Cycle, m copier.Message) Forward
- func ForwardCycleMessage(m director.CycleMessage) Forward
- func ForwardInstanceMessage(c director.Cycle, m director.InstanceMessage) Forward
- func ForwardSaveMessage(c director.Cycle, m saver.ArchiveMessage) Forward
- type ForwardHandler
- type ForwardKind
- type ForwardObserver
- func (f *ForwardObserver) Instance(id.ID) (director.InstanceObserver, error)
- func (f *ForwardObserver) OnBuild(builder.Message)
- func (f *ForwardObserver) OnCompilerConfig(compiler.Message)
- func (f *ForwardObserver) OnMachines(m machine.Message)
- func (f *ForwardObserver) OnPlan(planner.Message)
- func (f *ForwardObserver) OnPrepare(p director.PrepareMessage)
- func (f *ForwardObserver) Run(ctx context.Context) error
- type ForwardReceiver
- type ForwardingInstanceObserver
- func (l *ForwardingInstanceObserver) OnAnalysis(c analysis.Analysis)
- func (l *ForwardingInstanceObserver) OnArchive(s saver.ArchiveMessage)
- func (l *ForwardingInstanceObserver) OnBuild(m builder.Message)
- func (l *ForwardingInstanceObserver) OnCompilerConfig(m compiler.Message)
- func (l *ForwardingInstanceObserver) OnCopy(m copier.Message)
- func (l *ForwardingInstanceObserver) OnCycle(r director.CycleMessage)
- func (l *ForwardingInstanceObserver) OnInstance(m director.InstanceMessage)
- func (l *ForwardingInstanceObserver) OnMachineNodeAction(observer.Message)
- func (l *ForwardingInstanceObserver) OnPerturb(perturber.Message)
- func (l *ForwardingInstanceObserver) OnPlan(planner.Message)
- type Logger
- func (j *Logger) Close() error
- func (j *Logger) OnBuild(builder.Message)
- func (j *Logger) OnCompilerConfig(compiler.Message)
- func (j *Logger) OnCycle(c director.CycleMessage)
- func (j *Logger) OnCycleAnalysis(s director.CycleAnalysis)
- func (j *Logger) OnCycleBuild(director.Cycle, builder.Message)
- func (j *Logger) OnCycleCompiler(c director.Cycle, m compiler.Message)
- func (j *Logger) OnCycleCopy(director.Cycle, copier.Message)
- func (j *Logger) OnCycleInstance(c director.Cycle, m director.InstanceMessage)
- func (j *Logger) OnCycleSave(c director.Cycle, s saver.ArchiveMessage)
- func (j *Logger) OnMachines(m machine.Message)
- func (j *Logger) OnPlan(planner.Message)
- func (j *Logger) OnPrepare(m director.PrepareMessage)
- type Obs
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrForwardHandlerNil = errors.New("forward handler is nil")
ErrForwardHandlerNil occurs when NewForwardObserver is given a nil ForwardHandler.
Functions ¶
This section is empty.
Types ¶
type Forward ¶
type Forward struct { // Cycle is the cycle message if the forward kind is ForwardCycle; // if not, only its cycle is defined, and it determines the cycle from which this forward originates. Cycle director.CycleMessage // Kind is the kind of message that has been forwarded. Kind ForwardKind // Instance is, when Kind is ForwardInstance, a forwarded instance message. Instance *director.InstanceMessage // Analysis is, when Kind is ForwardAnalysis, an analysis message. Analysis *analysis.Analysis // Compiler is, when Kind is ForwardCompilers, a forwarded compiler message. Compiler *compiler.Message // Save is, when Kind is ForwardSave, a forwarded save message. Save *saver.ArchiveMessage // Build is, when Kind is ForwardBuild, a forwarded build message. Build *builder.Message // Copy is, when Kind is ForwardCopy, a forwarded copy message. Copy *copier.Message }
Forward contains a director observation that has been forwarded from an instance to a 'main' observer, alongside disambiguating information.
This struct, and its sibling structs and interfaces,exist to solve the problem that many things in the director happen in instance threads, but then need to be observed by a single-threaded observer.
func ForwardAnalysisMessage ¶
ForwardAnalysisMessage constructs a forwarding message for m over cycle c.
func ForwardBuildMessage ¶
ForwardBuildMessage constructs a forwarding message for m over cycle c.
func ForwardCompilerMessage ¶
ForwardCompilerMessage constructs a forwarding message for m over cycle c.
func ForwardCopyMessage ¶
ForwardCopyMessage constructs a forwarding message for m over cycle c.
func ForwardCycleMessage ¶
func ForwardCycleMessage(m director.CycleMessage) Forward
ForwardCycleMessage constructs a forwarding message for m.
func ForwardInstanceMessage ¶
func ForwardInstanceMessage(c director.Cycle, m director.InstanceMessage) Forward
ForwardInstanceMessage constructs a forwarding message for m over cycle c.
func ForwardSaveMessage ¶
func ForwardSaveMessage(c director.Cycle, m saver.ArchiveMessage) Forward
ForwardSaveMessage constructs a forwarding message for m over cycle c.
type ForwardHandler ¶
type ForwardHandler interface { // CycleObserver captures that ForwardHandler can observe cycles in the same way that the forwarding observer can. director.CycleObserver // Observer captures that ForwardHandler instances can observe machines. machine.Observer // PrepareObserver captures that ForwardHandler instances can observe preparations. director.PrepareObserver // OnCycleInstance handles a message for the instance of a particular cycle. OnCycleInstance(director.Cycle, director.InstanceMessage) // OnCycleAnalysis should handle an analysis for a particular cycle. OnCycleAnalysis(director.CycleAnalysis) // OnCycleBuild should handle a corpus build for a particular cycle. OnCycleBuild(director.Cycle, builder.Message) // OnCycleCompiler should handle a compiler message for a particular cycle. OnCycleCompiler(director.Cycle, compiler.Message) // OnCycleCopy should handle a copy message for a particular cycle. OnCycleCopy(director.Cycle, copier.Message) // OnCycleSave should handle an archive message for a particular cycle. OnCycleSave(director.Cycle, saver.ArchiveMessage) }
ForwardHandler is the interface of observers that can handle observations forwarded from an instance.
These inject behaviour into a ForwardObserver.
type ForwardKind ¶
type ForwardKind uint8
ForwardKind is the enumeration of possible Forward messages.
const ( // ForwardCycle delimits a forwarding message where Cycle is populated. ForwardCycle ForwardKind = iota // ForwardInstance delimits a forwarding message where Instance is populated (Cycle contains the cycle structure). ForwardInstance // ForwardAnalysis delimits a forwarding message where Analysis is populated (Cycle contains the cycle structure). ForwardAnalysis // ForwardCompiler delimits a forwarding message where Compiler is populated (Cycle contains the cycle structure). ForwardCompiler // ForwardSave delimits a forwarding message where Save is populated (Cycle contains the cycle structure). ForwardSave // ForwardBuild delimits a forwarding message where Build is populated (Cycle contains the cycle structure). ForwardBuild // ForwardCopy delimits a forwarding message where Copy is populated (Cycle contains the cycle structure). ForwardCopy )
type ForwardObserver ¶
type ForwardObserver struct {
// contains filtered or unexported fields
}
ForwardObserver is an observer that uses a ForwardReceiver and a ForwardHandler to handle observations.
func NewForwardObserver ¶
func NewForwardObserver(cap int, hs ...ForwardHandler) (*ForwardObserver, error)
NewForwardObserver constructs a new ForwardObserver with the given handlers hs and message buffer capacity cap.
func (*ForwardObserver) Instance ¶
func (f *ForwardObserver) Instance(id.ID) (director.InstanceObserver, error)
Instance creates an instance observer that forwards to this logger.
func (*ForwardObserver) OnBuild ¶
func (f *ForwardObserver) OnBuild(builder.Message)
OnBuild does nothing, for now.
func (*ForwardObserver) OnCompilerConfig ¶
func (f *ForwardObserver) OnCompilerConfig(compiler.Message)
OnCompilerConfig does nothing, for now.
func (*ForwardObserver) OnMachines ¶
func (f *ForwardObserver) OnMachines(m machine.Message)
OnMachines delegates to the forward handlers.
func (*ForwardObserver) OnPlan ¶
func (f *ForwardObserver) OnPlan(planner.Message)
OnPlan does nothing, for now.
func (*ForwardObserver) OnPrepare ¶
func (f *ForwardObserver) OnPrepare(p director.PrepareMessage)
OnPrepare forwards prepare messages to the handlers.
type ForwardReceiver ¶
ForwardReceiver holds receive channels for Forward messages.
It is effectively a more type-safe form of observing.FanIn, and will usually be used inside a ForwardObserver.
func NewForwardReceiver ¶
func NewForwardReceiver(f func(m Forward) error, cap int) *ForwardReceiver
NewForwardReceiver constructs a new ForwardReceiver.
func (*ForwardReceiver) Add ¶
func (r *ForwardReceiver) Add(c <-chan Forward)
Add adds a channel to the forward receiver.
type ForwardingInstanceObserver ¶
type ForwardingInstanceObserver struct {
// contains filtered or unexported fields
}
ForwardingInstanceObserver is an instance observer that just forwards every observation to a director observer.
func (*ForwardingInstanceObserver) OnAnalysis ¶
func (l *ForwardingInstanceObserver) OnAnalysis(c analysis.Analysis)
OnAnalysis forwards a cycle analysis.
func (*ForwardingInstanceObserver) OnArchive ¶
func (l *ForwardingInstanceObserver) OnArchive(s saver.ArchiveMessage)
OnArchive forwards a cycle save message.
func (*ForwardingInstanceObserver) OnBuild ¶
func (l *ForwardingInstanceObserver) OnBuild(m builder.Message)
OnBuild forwards a cycle build message.
func (*ForwardingInstanceObserver) OnCompilerConfig ¶
func (l *ForwardingInstanceObserver) OnCompilerConfig(m compiler.Message)
func (*ForwardingInstanceObserver) OnCopy ¶
func (l *ForwardingInstanceObserver) OnCopy(m copier.Message)
OnCopy forwards a cycle copy message.
func (*ForwardingInstanceObserver) OnCycle ¶
func (l *ForwardingInstanceObserver) OnCycle(r director.CycleMessage)
OnCycle notes that the instance's iteration has changed.
func (*ForwardingInstanceObserver) OnInstance ¶
func (l *ForwardingInstanceObserver) OnInstance(m director.InstanceMessage)
OnInstance forwards an instance message, and closes the forwarding channel if the instance has closed.
func (*ForwardingInstanceObserver) OnMachineNodeAction ¶
func (l *ForwardingInstanceObserver) OnMachineNodeAction(observer.Message)
OnMachineNodeAction does nothing.
func (*ForwardingInstanceObserver) OnPerturb ¶
func (l *ForwardingInstanceObserver) OnPerturb(perturber.Message)
OnPerturb does nothing, at the moment.
func (*ForwardingInstanceObserver) OnPlan ¶
func (l *ForwardingInstanceObserver) OnPlan(planner.Message)
OnPlan does nothing, at the moment.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a ForwardHandler that emits logs to a writer when cycles finish up.
func NewLogger ¶
func NewLogger(w io.WriteCloser, lflag int) (*Logger, error)
NewLogger constructs a new Logger writing into w, using logger flags lflag when logging things. The logger takes ownership of w.
func (*Logger) OnCompilerConfig ¶
OnCompilerConfig (currently) does nothing.
func (*Logger) OnCycle ¶
func (j *Logger) OnCycle(c director.CycleMessage)
OnCycle logs a cycle event.
Example ¶
ExampleLogger_OnCycle is a runnable example indirectly exercising Logger.OnCycle.
package main import ( "context" "errors" "os" "time" "github.com/c4-project/c4t/internal/director" "github.com/c4-project/c4t/internal/ux/directorobs" "github.com/c4-project/c4t/internal/helper/iohelp" "github.com/c4-project/c4t/internal/id" ) func main() { l, _ := directorobs.NewLogger(iohelp.NopWriteCloser{Writer: os.Stdout}, 0) r, _ := directorobs.NewForwardObserver(0, l) i, _ := r.Instance(id.FromString("localhost")) c := director.Cycle{ Instance: 0, MachineID: id.FromString("localhost"), Iter: 10, Start: time.Time{}, } go func() { // These messages will arrive through l.OnCycle. director.OnCycle(director.CycleStartMessage(c), i) director.OnCycle(director.CycleErrorMessage(c, errors.New("the front fell off")), i) // Important, else the logger will keep waiting for the instance to provide observations. i.OnInstance(director.InstanceClosedMessage()) }() _ = r.Run(context.Background()) }
Output: * localhost starts cycle 10 * * localhost ERROR: the front fell off * [instance 0 has closed]
func (*Logger) OnCycleAnalysis ¶
func (j *Logger) OnCycleAnalysis(s director.CycleAnalysis)
OnCycleAnalysis logs s to this logger's file.
func (*Logger) OnCycleBuild ¶
OnCycleBuild does nothing, for now.
func (*Logger) OnCycleCompiler ¶
OnCycleCompiler handles a compiler message m coming from the director cycle c.
Example ¶
ExampleLogger_OnCycleCompiler is a runnable example indirectly exercising Logger.OnCycleCompiler.
package main import ( "context" "os" "github.com/c4-project/c4t/internal/director" "github.com/c4-project/c4t/internal/model/service/compiler" "github.com/c4-project/c4t/internal/model/service/compiler/optlevel" "github.com/c4-project/c4t/internal/ux/directorobs" "github.com/c4-project/c4t/internal/helper/iohelp" "github.com/c4-project/c4t/internal/id" ) func main() { l, _ := directorobs.NewLogger(iohelp.NopWriteCloser{Writer: os.Stdout}, 0) r, _ := directorobs.NewForwardObserver(0, l) i, _ := r.Instance(id.FromString("localhost")) go func() { // These messages will arrive through l.OnCycleCompiler. compiler.OnCompilerConfigStart(3, i) compiler.OnCompilerConfigStep(0, compiler.Named{ ID: id.FromString("gcc.4"), Instance: compiler.Instance{ SelectedMOpt: "arch=native", SelectedOpt: &optlevel.Named{Name: "3", Level: optlevel.Level{}}, Compiler: compiler.Compiler{Style: id.CStyleGCC, Arch: id.ArchArm7}, }, }, i) compiler.OnCompilerConfigStep(1, compiler.Named{ ID: id.FromString("gcc.9"), Instance: compiler.Instance{ SelectedMOpt: "arch=skylake", SelectedOpt: &optlevel.Named{Name: "2", Level: optlevel.Level{}}, Compiler: compiler.Compiler{Style: id.CStyleGCC, Arch: id.ArchArm8}, }, }, i) compiler.OnCompilerConfigStep(2, compiler.Named{ ID: id.FromString("msvc"), Instance: compiler.Instance{ Compiler: compiler.Compiler{Style: id.FromString("msvc"), Arch: id.ArchX8664}, }, }, i) compiler.OnCompilerConfigEnd(i) // Important, else the logger will keep waiting for the instance to provide observations. i.OnInstance(director.InstanceClosedMessage()) }() _ = r.Run(context.Background()) }
Output: [0: #0 (Jan 1 00:00:00)] compilers 3: - gcc.4: gcc@arm.7 opt "3" march "arch=native" - gcc.9: gcc@arm.8 opt "2" march "arch=skylake" - msvc: msvc@x86.64 [instance 0 has closed]
func (*Logger) OnCycleCopy ¶
OnCycleCopy does nothing, for now.
func (*Logger) OnCycleInstance ¶
func (j *Logger) OnCycleInstance(c director.Cycle, m director.InstanceMessage)
OnCycleInstance records a message about a cycle's instance.
func (*Logger) OnCycleSave ¶
func (j *Logger) OnCycleSave(c director.Cycle, s saver.ArchiveMessage)
OnCycleSave logs s to this logger's file.
Example ¶
ExampleLogger_OnCycleSave is a runnable example indirectly exercising Logger.OnCycleSave.
package main import ( "context" "os" "github.com/c4-project/c4t/internal/director" "github.com/c4-project/c4t/internal/ux/directorobs" "github.com/c4-project/c4t/internal/stage/analyser/saver" "github.com/c4-project/c4t/internal/helper/iohelp" "github.com/c4-project/c4t/internal/id" ) func main() { l, _ := directorobs.NewLogger(iohelp.NopWriteCloser{Writer: os.Stdout}, 0) r, _ := directorobs.NewForwardObserver(0, l) i, _ := r.Instance(id.FromString("localhost")) go func() { // These messages will arrive through l.OnCycleSave. saver.OnArchiveStart("subj", "subj.tar.gz", 2, i) saver.OnArchiveFileAdded("subj", "a.out", 0, i) saver.OnArchiveFileMissing("subj", "compile.log", 1, i) saver.OnArchiveFinish("subj", i) // Important, else the logger will keep waiting for the instance to provide observations. i.OnInstance(director.InstanceClosedMessage()) }() _ = r.Run(context.Background()) }
Output: saving (cycle [0: #0 (Jan 1 00:00:00)]) subj to subj.tar.gz when saving (cycle [0: #0 (Jan 1 00:00:00)]) subj: missing file compile.log [instance 0 has closed]
func (*Logger) OnMachines ¶
OnMachines logs a machine block.
func (*Logger) OnPrepare ¶
func (j *Logger) OnPrepare(m director.PrepareMessage)
OnPrepare logs the preparation attempts of a director.
Example ¶
ExampleLogger_OnPrepare is a runnable example indirectly exercising Logger.OnPrepare.
package main import ( "os" "github.com/c4-project/c4t/internal/director" "github.com/c4-project/c4t/internal/ux/directorobs" "github.com/c4-project/c4t/internal/helper/iohelp" ) func main() { l, _ := directorobs.NewLogger(iohelp.NopWriteCloser{Writer: os.Stdout}, 0) r, _ := directorobs.NewForwardObserver(0, l) director.OnPrepare(director.PrepareInstancesMessage(5), r) }
Output: running on 5 instances