types

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package types contains data types that are shared across the different packages of testctrl.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component struct {
	// Name uniquely identifies a component.
	Name string

	// ContainerImage is the docker image name and tag of the
	// component.
	ContainerImage string

	// Kind is the type of component.
	Kind ComponentKind

	// PoolName is the optional name of a node pool where the
	// component should be scheduled. If no name is provided, the
	// system will choose a pool.
	PoolName string

	// Env is the map of environment variables that should be set
	// when the component is started.
	Env map[string]string
}

Component represents a dependency that must be provisioned and managed during a session. For example, benchmarks tend to have a driver, server and a set of client components. Prefer creating components with the NewComponent constructor, because it assigns a unique name.

func NewComponent

func NewComponent(containerImage string, kind ComponentKind) *Component

NewComponent creates a Component instance, given a container image and kind.

The container image string should contain the path to a docker image in a registry, versioned by an explicit tag or hash.

For example:

// Container uses "nginx" image with explicit tag "latest" from docker hub
a := NewComponent("nginx:latest", ServerComponent)

// Container uses "java_worker" image with explicit tag "v3.2.2" from GCR
b := NewComponent("gcr.io/grpc-testing/java_worker:v3.2.2", ClientComponent)

// Container uses "driver" image with hash from GCR
c := NewComponent("gcr.io/grpc-testing/driver@sha256:e4ff8efd7eb62d3a3bb0990f6ff1e9df20da24ebf908d08f49cb83422a232862", DriverComponent)

func (*Component) ResourceName

func (c *Component) ResourceName() string

ResourceName returns the name the component prefixed with `components/`. This value should be displayed to a consumer of the API.

type ComponentKind

type ComponentKind int32

ComponentKind specifies the type of component the test requires.

const (

	// DriverComponent is a test component that orchestrates
	// workers, such as clients and servers.
	DriverComponent ComponentKind

	// ClientComponent feeds traffic to a server component.
	ClientComponent

	// ServerComponent accepts traffic from a client component.
	ServerComponent
)

func ComponentKindFromProto

func ComponentKindFromProto(p pb.Component_Kind) ComponentKind

ComponentKindFromProto takes the generated protobuf enum type and safely converts it into a ComponentKind. It ensures the string representations are equivalent, even if values change.

func (ComponentKind) Proto

func (k ComponentKind) Proto() pb.Component_Kind

Proto converts the ComponentKind enum into the generated protobuf enum. It ensures the string representations are equivalent, even if values change.

func (ComponentKind) String

func (k ComponentKind) String() string

String returns the string representation of the ComponentKind.

type Event

type Event struct {
	// SubjectName is the string representation of the object this event describes. For example, a
	// specific session "xyz" may have the subject name of "testSessions/xyz". The format of the
	// string is implementation specific.
	SubjectName string

	// Kind is the type of event.
	Kind EventKind

	// Time is the point in time when the event was noticed.
	Time time.Time

	// Description is additional, unstructured information in a string. For example, it may describe
	// inputs and and the error message with a ErrorEvent.
	Description string

	// DriverLogs contains a slice of bytes with the logs of the driver component. These logs
	// contain a legible form of the results.
	//
	// This field will be nil unless Kind is a ErrorEvent, InternalErrorEvent, or DoneEvent).
	DriverLogs []byte
}

Event represents an action at a specific point in time on a subject. Likely, the subject is a Session or Component. Events are designed to be chained together, creating a log of all significant points in time.

Event instances can be created through the constructor or through a literal. The constructor, NewEvent, provides several conveniences. First, it sets the Time to time.Now. Second, it accepts a ResourceNamer for the subject. This allows events to be created using the syntactic sugar of subject objects themselves.

func NewEvent

func NewEvent(subject ResourceNamer, k EventKind, messageFmt string, args ...interface{}) *Event

NewEvent instantiates an Event struct, setting its Timestamp to now and its SubjectName to the result of Name method on the ResourceNamer. It expects a message, since supplying one can provide more context in an unstructured format.

type EventKind

type EventKind int32

EventKind specifies the type of event. For example, an event could be created for a fatal error or a session is waiting in the queue.

const (

	// InternalErrorEvent represents a problem in the infrastructure, service or controller itself. It
	// does not pertain to a session or component. If encountered, file a bug with its particular message.
	InternalErrorEvent EventKind

	// QueueEvent signals that a session is waiting for resources to run.
	QueueEvent

	// AcceptEvent indicates that an executor has been assigned to provision and monitor the session;
	// however, work has not yet begun on the event's subject.
	AcceptEvent

	// ProvisionEvent means executors have begun reserving and configuring the subject. This may take
	// a while to complete.
	ProvisionEvent

	// RunEvent indicates the subject is responding with a healthy signal. However, this does not
	// verify that it is running the tests.
	RunEvent

	// DoneEvent conveys the subject has terminated as expected. It does not indicate that the tests
	// were successful or results were recorded.
	DoneEvent

	// ErrorEvent means something has gone irrecoverably wrong with the event's subject.
	ErrorEvent
)

func EventKindFromProto

func EventKindFromProto(p pb.Event_Kind) EventKind

EventKindFromProto takes the generated protobuf enum type and safely converts it into an EventKind. It ensures the string representations are equivalent, even if values change.

func (EventKind) Proto

func (k EventKind) Proto() pb.Event_Kind

Proto converts the EventKind enum into the generated protobuf enum. It ensures the string representations are equivalent, even if values change.

func (EventKind) String

func (k EventKind) String() string

String returns the string representation of the EventKind.

type EventRecorder

type EventRecorder interface {
	// Record saves an event.
	Record(e Event)
}

EventRecorder implementations save events to a storage medium.

type ResourceNamer

type ResourceNamer interface {
	// ResourceName returns a string with a name for its receiver.
	ResourceName() string
}

ResourceNamer is any type that can assign a string that identifies a specific resource.

type Session

type Session struct {
	// Name is a unique string that identifies a session.
	Name string

	// Driver is the single component that is responsible for orchestrating
	// the tests. By design, it should communicate with the worker
	// components.
	Driver *Component

	// Workers is the slice of components that do not orchestrate the tests.
	// For example, the server and client components which accept and
	// provide traffic.
	Workers []*Component

	// Scenario is the configuration of the benchmarks.
	Scenario *pb.Scenario

	// CreateTime is the time the session was created.
	CreateTime time.Time
}

Session is a test scenario, its components and metdata.

func NewSession

func NewSession(driver *Component, workers []*Component, scenario *pb.Scenario) *Session

NewSession creates a Session, assigning it a unique name.

func (*Session) ClientWorkers

func (s *Session) ClientWorkers() []*Component

ClientWorkers returns the slice of all the workers with a kind of ClientComponents.

func (*Session) ResourceName

func (s *Session) ResourceName() string

ResourceName returns the name the session prefixed with `sessions/`. This value should be the name that is shared with a consumer of the API.

func (*Session) ServerWorkers

func (s *Session) ServerWorkers() []*Component

ServerWorkers returns the slice of all the workers with a kind of ServerComponents.

Jump to

Keyboard shortcuts

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