e2e_testing

package module
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

opentelemetry-operations-e2e-testing

This project contains a test runner and configuration which are used for testing GCP's OpenTelemetry exporters, resource detectors, propagators, etc. These tests are run in pull requests to the other GoogleCloudPlatform/opentelemtry-operations-* repos.

The code in this repository is only for testing purposes! This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

Run locally

Build the docker image locally:

docker build . -t opentelemetry-operations-e2e-testing:local

Run the image with a test server, e.g. with the python instrumented test server from a recent build:

PROJECT_ID="opentelemetry-ops-e2e"
GOOGLE_APPLICATION_CREDENTIALS="${HOME}/.config/gcloud/application_default_credentials.json"

# Using a recent python build for example. Alternatively, use a locally built
# test server.
INSTRUMENTED_TEST_SERVER="gcr.io/opentelemetry-ops-e2e/opentelemetry-operations-python-e2e-test-server:45ccd1d"

# Pull the image if it doesn't exist locally
docker pull ${INSTRUMENTED_TEST_SERVER}
docker run \
    -e "GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}" \
    -v "${GOOGLE_APPLICATION_CREDENTIALS}:${GOOGLE_APPLICATION_CREDENTIALS}:ro" \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -e PROJECT_ID=${PROJECT_ID} \
    --rm \
    opentelemetry-operations-e2e-testing:local \
    local \
    --image=${INSTRUMENTED_TEST_SERVER}

Run locally (in Google Cloud Functions)

Since running in cloud functions require you to upload a zipped file containing the source code, steps to trigger test runs in a cloud function environment are slightly different from running in a local environment.

Build the docker image locally:

docker build . -t opentelemetry-operations-e2e-testing:local

Make sure you have the proper environment variables setup:

PROJECT_ID="opentelemetry-ops-e2e"
GOOGLE_APPLICATION_CREDENTIALS="${HOME}/.config/gcloud/application_default_credentials.json"

Run the image with a test server provided through the zip file. The following docker command makes the following assumptions:

  • You have the source code for your function zipped in a file named function-source.zip
  • You have this zip file placed in a folder called function-deployment within your current directory (from where you run this command)
  • Your function code is written for java11 environment.
    • The entrypoint for your java function is com.google.cloud.opentelemetry.endtoend.CloudFunctionHandler.
docker run \
    -e PROJECT_ID=${PROJECT_ID} \
    -e GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS} \
    -v "${GOOGLE_APPLICATION_CREDENTIALS}:${GOOGLE_APPLICATION_CREDENTIALS}:ro" \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v "$(pwd)/function-deployment/function-source.zip:/function-source.zip" \ 
    -it \
    --rm \
    opentelemetry-operations-e2e-testing:local \
    cloud-functions-gen2 \
    --runtime=java11 \
    --functionsource="/function-source.zip" \
    --entrypoint=com.google.cloud.opentelemetry.endtoend.CloudFunctionHandler

NOTE: If you are using Java, you can also use a generated JAR to deploy the function. However, you would still need zip the JAR and the JAR should be at the root of the zip. For more information look at the How to guides for Google Cloud Functions.

Matrix of implemented scenarios

Contributing

See docs/contributing.md for details.

License

Apache 2.0; see LICENSE for details.

Disclaimer

This project is not an official Google project. It is not supported by Google and Google specifically disclaims all warranties as to its quality, merchantability, or fitness for a particular purpose.

Documentation

Index

Constants

View Source
const BeginOutputArt = `` /* 908-byte string literal not displayed */
View Source
const EndOutputArt = `` /* 908-byte string literal not displayed */

Variables

This section is empty.

Functions

func NoopCleanup

func NoopCleanup()

Types

type ApplyPersistent

type ApplyPersistent struct {
	AutoApprove bool `arg:"--auto-approve" default:"false" help:"Approve without prompting. Default is false."`
}

type Args

type Args struct {
	// This subcommand is a special case, it doesn't run any tests. It just
	// applies the persistent resources which are used across tests. See
	// tf/persistent/README.md for details on what is in there.
	ApplyPersistent *ApplyPersistent `arg:"subcommand:apply-persistent" help:"Terraform apply the resources in tf/persistent and exit (does not run tests)."`

	Local              *LocalCmd              `arg:"subcommand:local" help:"Deploy the test server locally with docker and execute tests"`
	Gke                *GkeCmd                `arg:"subcommand:gke" help:"Deploy the test server on GKE and execute tests"`
	Gce                *GceCmd                `arg:"subcommand:gce" help:"Deploy the test server on GCE and execute tests"`
	Gae                *GaeCmd                `arg:"subcommand:gae" help:"Deploy the test server on GAE and execute tests"`
	CloudRun           *CloudRunCmd           `arg:"subcommand:cloud-run" help:"Deploy the test server on Cloud Run and execute tests"`
	CloudFunctionsGen2 *CloudFunctionsGen2Cmd `arg:"subcommand:cloud-functions-gen2" help:"Deploy the test server on Cloud Function (2nd Gen) and execute tests"`

	CmdWithProjectId
	GoTestFlags        string        `help:"go test flags to pass through, e.g. --gotestflags='-test.v'"`
	HealthCheckTimeout time.Duration `` /* 126-byte string literal not displayed */

	// This is used in a new terraform workspace's name and in the GCP resources
	// we create. Pass the GCB build ID in CI to get the build id formatted into
	// resources created for debugging. If not provided, we generate a hex
	// string.
	TestRunID string `arg:"--test-run-id,env:TEST_RUN_ID" help:"Optional test run id to use to partition terraform resources"`
}

type Cleanup

type Cleanup func()

func SetupCloudFunctionsGen2 added in v0.14.0

func SetupCloudFunctionsGen2(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error)

SetupCloudFunctionsGen2 sets up the instrumented test server to run in Cloud Functions (2nd Gen). Creates a new Cloud Function and runs the specified source zip containing the code that needs to be run. The returned cleanup function tears down everything.

func SetupCloudRun

func SetupCloudRun(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error)

SetupCloudRun sets up the instrumented test server to run in Cloud Run. Creates a new service and runs the specified container image as a revision. The returned cleanup function tears down everything.

func SetupGae added in v0.15.0

func SetupGae(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error)

func SetupGce

func SetupGce(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error)

Set up the instrumented test server to run in GCE container. Creates a new GCE VM + pubsub resources, and runs the specified container image. The returned cleanup function tears down the VM.

func SetupGke

func SetupGke(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error)

Set up the instrumented test server to run in GKE. Creates a new GKE cluster and runs the specified container image in a pod. The returned cleanup function tears down the whole cluster.

func SetupLocal

func SetupLocal(
	ctx context.Context,
	args *Args,
	logger *log.Logger,
) (*testclient.Client, Cleanup, error)

Set up the instrumented test server for a local run by running in a docker container on the local host

type CloudFunctionsGen2Cmd added in v0.14.0

type CloudFunctionsGen2Cmd struct {
	// Needed to configure which language will the function instance support
	Runtime string `arg:"required" help:"Configure the language runtime environment for CloudFunction"`

	EntryPoint string `arg:"required" help:"The entry point for the code that will run in this CloudFunction"`

	FunctionSource string `arg:"required" help:"The full path of the zip file that contains the code source that needs to run within the CloudFunction"`
}

type CloudRunCmd

type CloudRunCmd struct {
	CmdWithImage
}

type CmdWithImage

type CmdWithImage struct {
	Image string `arg:"required" help:"docker container image to deploy and test"`
}

type CmdWithProjectId

type CmdWithProjectId struct {
	ProjectID string `arg:"required,--project-id,env:PROJECT_ID" help:"GCP project id/name"`
}

type GaeCmd added in v0.15.0

type GaeCmd struct {
	CmdWithImage

	Runtime string `arg:"required" help:"The language runtime for the instrumented test server, used in naming the service"`
}

type GceCmd

type GceCmd struct {
	CmdWithImage
}

type GkeCmd

type GkeCmd struct {
	CmdWithImage
}

type LocalCmd

type LocalCmd struct {
	CmdWithImage

	Port string `default:"8000"`

	// Needed when running without a metadata server for credentials
	GoogleApplicationCredentials string `` /* 152-byte string literal not displayed */

	// May be needed when running this binary in a container
	Network string `help:"Docker network to use when starting the container, optional"`

	ContainerUser string `arg:"--container-user" help:"Optional user to use when running the container"`
}

type SetupFunc

type SetupFunc func(
	context.Context,
	*Args,
	*log.Logger,
) (*testclient.Client, Cleanup, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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