engine

package
v0.17.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2020 License: Apache-2.0 Imports: 64 Imported by: 0

README

Engine Design Doc

Engine is primarily a for loop that takes inputs from a variety of sources, updates state, and makes a decision based off of that state. The rough shape of the for loop is as follows:

state := &state{}
for {
    select {
        // sources like local filesystem, kubernetes, ui, etc
        case ev := <- fsCh:
            e.handleFsEvent(ev)
        case ev := <- k8sCh:
            e.handleK8sEvent(ev)
    }
    // decide what to do: start a pipeline, stop a pipeline
    actions := handle(state)
    // tell subscribers what we took
    updateSubscribers(actions, state.copy())
}

When state changes, and only when state changes, can we make decisions about what to do. Only after actions have been taken do we tell subscribers.

Rules

  • No blocking I/O in the for loop
  • No long operations in the for loop
  • Actions taken in handle shouldn’t directly send to channels that this for selects on.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ImageBuildCount = &view.View{
	Name:        "image_build_count",
	Measure:     ImageBuildDuration,
	Aggregation: view.Count(),
	Description: "Image build count",
	TagKeys:     []tag.Key{KeyImageRef, KeyBuildError},
}
View Source
var ImageBuildDuration = stats.Float64(
	"image_build_duration",
	"Image build duration",
	stats.UnitMilliseconds)

Loosely adapted from how opencensus does HTTP aggregations: https://github.com/census-instrumentation/opencensus-specs/blob/master/stats/HTTP.md#http-stats https://pkg.go.dev/go.opencensus.io/plugin/ochttp

View Source
var ImageBuildDurationDistribution = view.Distribution(
	10, 100, 500, 1000, 2000, 5000,
	10000, 15000, 20000, 30000, 45000, 60000, 120000,
	240000, 480000, 1000000, 2000000, 5000000)
View Source
var ImageBuildDurationView = &view.View{
	Name:        "image_build_duration_dist",
	Measure:     ImageBuildDuration,
	Aggregation: ImageBuildDurationDistribution,
	Description: "Image build time, by image ref",
	TagKeys:     []tag.Key{KeyImageRef, KeyBuildError},
}
View Source
var KeyBuildError = tag.MustNewKey("build_error")
View Source
var KeyImageRef = tag.MustNewKey("image_ref")

Metric and label names must match the following rules: https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels

View Source
var UpperReducer = store.Reducer(upperReducerFn)

Functions

func NewErrorAction

func NewErrorAction(err error) store.ErrorAction

func NewImageBuilder added in v0.14.1

func NewImageBuilder(db build.DockerBuilder, custb build.CustomBuilder, updateMode buildcontrol.UpdateMode) *imageBuilder

func ParseYAMLFromManifests

func ParseYAMLFromManifests(manifests ...model.Manifest) ([]k8s.K8sEntity, error)

func SpanIDForBuildLog added in v0.10.24

func SpanIDForBuildLog(buildCount int) logstore.SpanID

Types

type BuildAndDeployer

type BuildAndDeployer interface {

	// Returns a BuildResultSet containing output (build result and associated
	// file changes) for each target built in this call. The BuildResultSet only
	// contains results for newly built targets--if a target was clean and didn't
	// need to be built, it doesn't appear in the result set.
	//
	// BuildResult can be used to construct a set of BuildStates, which contain
	// the last successful builds of each target and the files changed since that
	// build.
	BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, currentState store.BuildStateSet) (store.BuildResultSet, error)
}

type BuildController

type BuildController struct {
	// contains filtered or unexported fields
}

func NewBuildController

func NewBuildController(b BuildAndDeployer) *BuildController

func (*BuildController) DisableForTesting added in v0.1.0

func (c *BuildController) DisableForTesting()

func (*BuildController) OnChange

func (c *BuildController) OnChange(ctx context.Context, st store.RStore)

type BuildLogActionWriter added in v0.2.0

type BuildLogActionWriter struct {
	// contains filtered or unexported fields
}

func (BuildLogActionWriter) Write added in v0.2.0

func (w BuildLogActionWriter) Write(level logger.Level, fields logger.Fields, p []byte) error

type BuildOrder

type BuildOrder []BuildAndDeployer

func (BuildOrder) String added in v0.7.11

func (bo BuildOrder) String() string

type CompositeBuildAndDeployer

type CompositeBuildAndDeployer struct {
	// contains filtered or unexported fields
}

CompositeBuildAndDeployer tries to run each builder in order. If a builder emits an error, it uses the FallbackTester to determine whether the error is critical enough to stop the whole pipeline, or to fallback to the next builder.

func NewCompositeBuildAndDeployer

func NewCompositeBuildAndDeployer(builders BuildOrder, tracer trace.Tracer) *CompositeBuildAndDeployer

func (*CompositeBuildAndDeployer) BuildAndDeploy

func (composite *CompositeBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, currentState store.BuildStateSet) (store.BuildResultSet, error)

type DockerComposeBuildAndDeployer added in v0.4.1

type DockerComposeBuildAndDeployer struct {
	// contains filtered or unexported fields
}

func NewDockerComposeBuildAndDeployer added in v0.4.1

func NewDockerComposeBuildAndDeployer(dcc dockercompose.DockerComposeClient, dc docker.Client,
	ib *imageBuilder, c build.Clock) *DockerComposeBuildAndDeployer

func (*DockerComposeBuildAndDeployer) BuildAndDeploy added in v0.4.1

func (bd *DockerComposeBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, currentState store.BuildStateSet) (res store.BuildResultSet, err error)

type FallbackTester

type FallbackTester func(error) bool

type HudStoppedAction added in v0.1.0

type HudStoppedAction struct {
	// contains filtered or unexported fields
}

func NewHudStoppedAction added in v0.1.0

func NewHudStoppedAction(err error) HudStoppedAction

func (HudStoppedAction) Action added in v0.1.0

func (HudStoppedAction) Action()

type ImageBuildAndDeployer

type ImageBuildAndDeployer struct {
	// contains filtered or unexported fields
}

func NewImageBuildAndDeployer

func NewImageBuildAndDeployer(
	db build.DockerBuilder,
	customBuilder build.CustomBuilder,
	k8sClient k8s.Client,
	env k8s.Env,
	analytics *analytics.TiltAnalytics,
	updMode buildcontrol.UpdateMode,
	c build.Clock,
	runtime container.Runtime,
	kl KINDLoader,
	syncletContainer sidecar.SyncletContainer,
) *ImageBuildAndDeployer

func (*ImageBuildAndDeployer) BuildAndDeploy

func (ibd *ImageBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, stateSet store.BuildStateSet) (resultSet store.BuildResultSet, err error)

func (*ImageBuildAndDeployer) SetInjectSynclet

func (ibd *ImageBuildAndDeployer) SetInjectSynclet(inject bool)

Turn on synclet injection. Should be called before any builds.

type InitAction

type InitAction struct {
	EngineMode   store.EngineMode
	TiltfilePath string
	ConfigFiles  []string
	UserArgs     []string

	TiltBuild model.TiltBuild
	StartTime time.Time

	AnalyticsUserOpt analytics.Opt

	CloudAddress string
	Token        token.Token
	TerminalMode store.TerminalMode
}

func (InitAction) Action

func (InitAction) Action()

type KINDLoader added in v0.14.0

type KINDLoader interface {
	LoadToKIND(ctx context.Context, ref reference.NamedTagged) error
}

func NewKINDLoader added in v0.14.0

func NewKINDLoader(env k8s.Env, clusterName k8s.ClusterName) KINDLoader

type LiveUpdateBuildAndDeployer added in v0.9.5

type LiveUpdateBuildAndDeployer struct {
	// contains filtered or unexported fields
}

func (*LiveUpdateBuildAndDeployer) BuildAndDeploy added in v0.9.5

func (lubad *LiveUpdateBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, stateSet store.BuildStateSet) (store.BuildResultSet, error)

type LocalTargetBuildAndDeployer added in v0.10.8

type LocalTargetBuildAndDeployer struct {
	// contains filtered or unexported fields
}

TODO(maia): CommandRunner interface for testability

func NewLocalTargetBuildAndDeployer added in v0.10.8

func NewLocalTargetBuildAndDeployer(c build.Clock) *LocalTargetBuildAndDeployer

func (*LocalTargetBuildAndDeployer) BuildAndDeploy added in v0.10.8

func (bd *LocalTargetBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RStore, specs []model.TargetSpec, stateSet store.BuildStateSet) (resultSet store.BuildResultSet, err error)

type ManifestReloadedAction

type ManifestReloadedAction struct {
	OldManifest model.Manifest
	NewManifest model.Manifest
	Error       error
}

func (ManifestReloadedAction) Action

func (ManifestReloadedAction) Action()

type PodWatcherMaker

type PodWatcherMaker func(context.Context, *store.Store) error

type ProfilerManager added in v0.4.2

type ProfilerManager struct {
	// contains filtered or unexported fields
}

func NewProfilerManager added in v0.4.2

func NewProfilerManager() *ProfilerManager

func (*ProfilerManager) OnChange added in v0.4.2

func (p *ProfilerManager) OnChange(ctx context.Context, st store.RStore)

func (*ProfilerManager) Start added in v0.4.2

func (p *ProfilerManager) Start(ctx context.Context, filename string) error

func (*ProfilerManager) Stop added in v0.4.2

func (p *ProfilerManager) Stop(ctx context.Context) error

type ServiceWatcherMaker

type ServiceWatcherMaker func(context.Context, *store.Store) error

type TelemetryScriptRanAction added in v0.10.25

type TelemetryScriptRanAction struct {
	At time.Time
}

func (TelemetryScriptRanAction) Action added in v0.10.25

func (TelemetryScriptRanAction) Action()

type UIDUpdateAction added in v0.8.9

type UIDUpdateAction struct {
	UID          types.UID
	EventType    watch.EventType
	ManifestName model.ManifestName
	Entity       k8s.K8sEntity
}

func (UIDUpdateAction) Action added in v0.8.9

func (UIDUpdateAction) Action()

type Upper

type Upper struct {
	// contains filtered or unexported fields
}

TODO(nick): maybe this should be called 'BuildEngine' or something? Upper seems like a poor and undescriptive name.

func NewUpper

func NewUpper(ctx context.Context, st *store.Store, subs []store.Subscriber) Upper

func (Upper) Dispatch added in v0.1.0

func (u Upper) Dispatch(action store.Action)

func (Upper) Init added in v0.4.1

func (u Upper) Init(ctx context.Context, action InitAction) error

func (Upper) Start added in v0.1.0

func (u Upper) Start(
	ctx context.Context,
	args []string,
	b model.TiltBuild,
	engineMode store.EngineMode,
	fileName string,
	initTerminalMode store.TerminalMode,
	analyticsUserOpt analytics.Opt,
	token token.Token,
	cloudAddress string,
) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL