engine

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: Apache-2.0 Imports: 63 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 DeployerWireSet = wire.NewSet(
	DeployerBaseWireSet,
)
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 K8sDeployCount = &view.View{
	Name:        "k8s_deploy_count",
	Measure:     K8sDeployDuration,
	Aggregation: view.Count(),
	Description: "K8s deploy count",
	TagKeys:     []octag.Key{keyResourceName, keyHasError},
}
View Source
var K8sDeployDuration = stats.Float64(
	"k8s_deploy_duration",
	"K8s Deploy duration",
	stats.UnitMilliseconds)
View Source
var K8sDeployDurationDistribution = view.Distribution(
	10, 100, 500, 1000, 2000, 5000,
	10000, 15000, 20000, 30000, 45000, 60000)
View Source
var K8sDeployDurationView = &view.View{
	Name:        "k8s_deploy_duration_dist",
	Measure:     K8sDeployDuration,
	Aggregation: K8sDeployDurationDistribution,
	Description: "K8s Deploy time",
	TagKeys:     []octag.Key{keyResourceName, keyHasError},
}
View Source
var K8sDeployObjects = stats.Int64("objects", "The number of objects deployed", "1")
View Source
var K8sDeployObjectsCount = &view.View{
	Name:        "k8s_deploy_objects_count",
	Measure:     K8sDeployObjects,
	Aggregation: view.LastValue(),
	Description: "K8s objects per resource",
	TagKeys:     []octag.Key{keyResourceName, keyHasError},
}
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 ProvideSubscribersAPIOnly added in v0.19.0

Subscribers that only read from the new Tilt API, and run the API server.

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, _ store.ChangeSummary)

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,
) *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)

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 NewLiveUpdateBuildAndDeployer added in v0.9.5

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 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, error)

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

Directories

Path Synopsis
Package analytics handles reporting of anonymized usage statistics about what features of Tilt are in use.
Package analytics handles reporting of anonymized usage statistics about what features of Tilt are in use.
Package metrics handles reporting of identifable metrics about user code for personal and team consumption.
Package metrics handles reporting of identifable metrics about user code for personal and team consumption.

Jump to

Keyboard shortcuts

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