proftest

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BaseStartupTmpl = template.Must(template.New("startupScript").Parse(`
{{ define "prologue" -}}
#! /bin/bash
(
# Signal any unexpected error.
trap 'echo "{{.ErrorString}}"' ERR

# Shut down the VM in 5 minutes after this script exits
# to stop accounting the VM for billing and cores quota.
trap "sleep 300 && poweroff" EXIT

retry() {
  for i in {1..3}; do
    [ $i == 1 ] || sleep 10  # Backing off after a failed attempt.
    "${@}" && return 0
  done
  return 1
}

# Fail on any error.
set -eo pipefail

# Display commands being run
set -x
{{- end }}

{{ define "epilogue" -}}
# Write output to serial port 2 with timestamp.
) 2>&1 | while read line; do echo "$(date): ${line}"; done >/dev/ttyS1
{{- end }}
`))

BaseStartupTmpl is the common part of the startup script that can be shared by multiple tests.

Functions

func CheckSerialOutputForBackoffs

func CheckSerialOutputForBackoffs(output string, numBenchmarks int, serverBackoffSubstring, createProfileSubstring, benchmarkNumPrefix string) error

CheckSerialOutputForBackoffs parses serial port output, and validates that server-specified backoffs were respected by the agent.

Types

type ClusterConfig

type ClusterConfig struct {
	ProjectID       string
	Zone            string
	ClusterName     string
	PodName         string
	ImageSourceName string
	ImageName       string
	Bucket          string
	Dockerfile      string
}

ClusterConfig is configuration for starting single GKE cluster for profiling agent test case.

type GCETestRunner

type GCETestRunner struct {
	TestRunner
	ComputeService *compute.Service
}

GCETestRunner supports testing a profiling agent on GCE.

func (*GCETestRunner) DeleteInstance

func (tr *GCETestRunner) DeleteInstance(ctx context.Context, inst *InstanceConfig) error

DeleteInstance deletes an instance with project id, name, and zone matched by inst.

func (*GCETestRunner) PollAndLogSerialPort

func (tr *GCETestRunner) PollAndLogSerialPort(ctx context.Context, inst *InstanceConfig, finishString, errorString string, logf func(string, ...interface{})) (string, error)

PollAndLogSerialPort polls serial port 2 of the given GCE instance and returns when the finishString appears in the serial output of the instance, or when the context times out. It logs the serial output of the instance using the specified log function and returns the serial output in the first return value.

func (*GCETestRunner) StartInstance

func (tr *GCETestRunner) StartInstance(ctx context.Context, inst *InstanceConfig) error

StartInstance starts a GCE Instance with configs specified by inst, and which runs the startup script specified in inst. If image project is not specified, it defaults to "debian-cloud". If image family is not specified, it defaults to "debian-10".

type GKETestRunner

type GKETestRunner struct {
	TestRunner
	ContainerService *container.Service
	StorageClient    *storage.Client
	Dockerfile       string
}

GKETestRunner supports testing a profiling agent on GKE.

func (*GKETestRunner) DeleteClusterAndImage

func (tr *GKETestRunner) DeleteClusterAndImage(ctx context.Context, cfg *ClusterConfig) []error

DeleteClusterAndImage deletes cluster and images used to create cluster.

type InstanceConfig

type InstanceConfig struct {
	ProjectID     string
	Zone          string
	Name          string
	StartupScript string
	MachineType   string
	ImageProject  string
	ImageFamily   string
	Scopes        []string
}

InstanceConfig is configuration for starting single GCE instance for profiling agent test case.

type ProfileData

type ProfileData struct {
	Samples           []int32         `json:"samples"`
	SampleMetrics     interface{}     `json:"sampleMetrics"`
	DefaultMetricType string          `json:"defaultMetricType"`
	TreeNodes         interface{}     `json:"treeNodes"`
	Functions         functionArray   `json:"functions"`
	SourceFiles       sourceFileArray `json:"sourceFiles"`
}

ProfileData has data of a single profile.

type ProfileResponse

type ProfileResponse struct {
	Profile     ProfileData   `json:"profile"`
	NumProfiles int32         `json:"numProfiles"`
	Deployments []interface{} `json:"deployments"`
}

ProfileResponse contains the response produced when querying profile server.

func (*ProfileResponse) CheckNonEmpty

func (pr *ProfileResponse) CheckNonEmpty() error

CheckNonEmpty returns nil if the profile has a profiles and deployments associated. Otherwise, returns a desciptive error.

func (*ProfileResponse) HasFunction

func (pr *ProfileResponse) HasFunction(functionName string) error

HasFunction returns nil if the function is present, or, if the function is not present, and error providing more details why the function is not present.

func (*ProfileResponse) HasFunctionInFile

func (pr *ProfileResponse) HasFunctionInFile(functionName string, filename string) error

HasFunctionInFile returns nil if function is present in the specified file, and an error if the function/file combination is not present in the profile.

func (*ProfileResponse) HasSourceFile

func (pr *ProfileResponse) HasSourceFile(filename string) error

HasSourceFile returns nil if the file (or file where the end of the file path matches the filename) is present in the profile. Or, if the filename is not present, an error is returned.

type TestRunner

type TestRunner struct {
	Client *http.Client
}

TestRunner has common elements used for testing profiling agents on a range of environments.

func (*TestRunner) QueryProfiles

func (tr *TestRunner) QueryProfiles(projectID, service, startTime, endTime, profileType string) (ProfileResponse, error)

QueryProfiles retrieves profiles of a specific type, from a specific time range, associated with a particular service and project.

func (*TestRunner) QueryProfilesWithZone

func (tr *TestRunner) QueryProfilesWithZone(projectID, service, startTime, endTime, profileType, zone string) (ProfileResponse, error)

QueryProfilesWithZone retrieves profiles of a specific type, from a specific time range, in a specified zone, associated with a particular service and project.

Jump to

Keyboard shortcuts

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