biscepter

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package biscepter provides a Go interface for creating and running bisection jobs.

Jobs can most easily be created by passing in a job config to GetJobFromConfig, but can also be created manually by populating a Job struct. For a manually created job to work, at least the following fields have to be populated:

  • ReplicaCount
  • GoodCommit & BadCommit
  • Dockerfile or DockerfilePath
  • Repository

Every replica represents one issue to be bisected, meaning that the ReplicaCount parameter symbolizes how many issues should be bisected concurrently.

After a job struct was acquired, the job can be started using Job.Run.

The Job.Run function returns two channels. The first of of these channels contains RunningSystem-s, which are to be used to determine whether a certain commit is good or bad using the RunningSystem.IsGood and RunningSystem.IsBad methods. The latter channel contains OffendingCommit-s, which represent a completed bisection and contain information about the offending commit of the bisected issue.

When all issues have been diagnosed and an OffendingCommit was received for each one of them, the job can be stopped using Job.Stop, which will shutdown all running docker containers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Healthcheck

type Healthcheck struct {
	Port      int             // The port on which the healthcheck should be performed
	CheckType HealthcheckType // The type of healthcheck to be performed

	Data   string            // Additional data for a given check type. Functionality depends on check type
	Config HealthcheckConfig // The config for this healthcheck
}

The Healthcheck struct represents a healthcheck performed by the replica on running systems before sending them out to be tested

type HealthcheckConfig

type HealthcheckConfig struct {
	Retries int // How many times this healthcheck should be retried until it is considered to have failed

	Backoff time.Duration // How long to wait between each healthcheck retry

	BackoffIncrement time.Duration // By how much to increment the backoff on each failed attempt
	MaxBackoff       time.Duration // The maximum duration the backoff may reach after incrementing. When the backoff has reached this value, it won't increase any further
}

HealthcheckConfig provides configurations for healthchecks being performed, such as the amount of retries or backoff duration

type HealthcheckType

type HealthcheckType int

HealthcheckType specifies the type of healthcheck to be performed

const (
	// Healthcheck consists of a single http GET request. Healthcheck data holds the path to which the request is sent
	HttpGet200 HealthcheckType = iota
	// Healthcheck consists of a custom script ran in bash. Healthcheck data holds the actual script.
	// The environment variable `$PORT<XXXX>` can be used within the script to get the port to which `<XXXX>` was mapped to on the host (e.g. `$PORT443`)
	Script
)

type Job

type Job struct {
	ReplicasCount int // How many replicas of itself this job should spawn simultaneously. Each replica is to be used for bisecting one issue.

	// The cost multiplier of building a commit compared to running an already built commit.
	// A build cost of 100 means building a commit is 100 times more expensive than running a built commit.
	// A build cost of less than 1 results in biscepter always building the middle commit (if it was not built yet) and not using nearby, cached, builds.
	BuildCost float64

	Ports        []int         // The ports which this job needs
	Healthchecks []Healthcheck // The healthchecks for this job

	GoodCommit string // The hash of the good commit, i.e. the commit which does not exhibit any issues
	BadCommit  string // The hash of the bad commit, i.e. the commit which exhibits the issue(s) to be bisected

	Dockerfile     string // The contents of the dockerfile.
	DockerfilePath string // The path to the dockerfile relative to the present working directory. Only gets used if Dockerfile is empty.

	Log *logrus.Logger // The log to which information gets printed to

	MaxConcurrentReplicas uint // The max amount of replicas that can run concurrently, or 0 if no limit

	Repository string // The repository URL

	// Path to the file where commit replacements are written to and stored for subsequent runs. Defaults to "$(PWD)/.biscepter-replacements~"
	CommitReplacementsBackup string
	// contains filtered or unexported fields
}

A job represents a blueprint for replicas, which are then used to bisect one issue. Jobs can create multiple replicas at once.

func GetJobFromConfig

func GetJobFromConfig(r io.Reader) (*Job, error)

GetJobFromConfig reads in a job config in yaml format from a reader and initializes the corresponding job struct

func (*Job) Run

func (job *Job) Run() (chan RunningSystem, chan OffendingCommit, error)

Run the job. This initializes all the replicas and starts them. This function returns a RunningSystem channel and an OffendingCommit channel. The RunningSystem channel should be used to get notified about systems which are ready to be tested. Once an OffendingCommit was received for a given replica index, no more RunningSystem structs for this replica will appear in the RunningSystem channel.

func (*Job) Stop

func (j *Job) Stop() error

Stop the job and all running replicas.

type OffendingCommit

type OffendingCommit struct {
	ReplicaIndex int // The index of the bisected replica

	Commit       string // The commit which introduced the issue. I.e. the oldest bad commit
	CommitOffset int    // The offset to the initial commit of the commit which introduced the issue. I.e. the offset of the oldest bad commit

	CommitMessage string // The message of the offending commit
	CommitDate    string // The date of the offending commit
	CommitAuthor  string // The author of the offending commit
}

An OffendingCommit represents the finished bisection of a replica.

type RunningSystem

type RunningSystem struct {
	ReplicaIndex int // The index of this system's parent replica

	Ports map[int]int // A mapping of the ports specified for the system under test to the ones they were mapped to locally
	// contains filtered or unexported fields
}

A RunningSystem is a running system that is ready to be tested

func (*RunningSystem) IsBad

func (r *RunningSystem) IsBad()

IsBad tells biscepter that this running system is bad. If IsBad is called after the running system was already rated by a previous IsGood or IsBad method invocation, it will panic.

func (*RunningSystem) IsGood

func (r *RunningSystem) IsGood()

IsGood tells biscepter that this running system is good. If IsGood is called after the running system was already rated by a previous IsGood or IsBad method invocation, it will panic.

Jump to

Keyboard shortcuts

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