Merge pull request #1 from google/master

catch up
This commit is contained in:
kevin.xu
2020-04-27 21:51:31 +08:00
committed by GitHub
1827 changed files with 129500 additions and 29026 deletions
+17 -20
View File
@@ -12,37 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# Build with C++17.
build --cxxopt=-std=c++17
# Display the current git revision in the info block.
build --stamp --workspace_status_command tools/workspace_status.sh
# Enable remote execution so actions are performed on the remote systems.
build:remote --remote_executor=grpcs://remotebuildexecution.googleapis.com
# Add a custom platform and toolchain that builds in a privileged docker
# container, which is required by our syscall tests.
build:remote --host_platform=//test:rbe_ubuntu1604
build:remote --extra_toolchains=//test:cc-toolchain-clang-x86_64-default
build:remote --extra_execution_platforms=//test:rbe_ubuntu1604
build:remote --platforms=//test:rbe_ubuntu1604
# Use default image for crosstool toolchain.
build:remote --crosstool_top=@rbe_default//cc:toolchain
# Default parallelism and timeout for remote jobs.
build:remote --jobs=50
build:remote --remote_timeout=3600
# RBE requires a strong hash function, such as SHA256.
startup --host_jvm_args=-Dbazel.DigestFunction=SHA256
build:remote --project_id=gvisor-rbe
build:remote --remote_instance_name=projects/gvisor-rbe/instances/default_instance
# Enable authentication. This will pick up application default credentials by
# default. You can use --google_credentials=some_file.json to use a service
# account credential instead.
build:remote --google_default_credentials=true
# Auth scope needed for authentication with RBE.
build:remote --auth_scope="https://www.googleapis.com/auth/cloud-source-tools"
# Add a custom platform and toolchain that builds in a privileged docker
# container, which is required by our syscall tests.
build:remote --host_platform=//:rbe_ubuntu1604
build:remote --extra_toolchains=//:cc-toolchain-clang-x86_64-default
build:remote --extra_execution_platforms=//:rbe_ubuntu1604
build:remote --platforms=//:rbe_ubuntu1604
build:remote --crosstool_top=@rbe_default//cc:toolchain
build:remote --jobs=50
build:remote --remote_timeout=3600
# RBE requires a strong hash function, such as SHA256.
startup --host_jvm_args=-Dbazel.DigestFunction=SHA256
# Set flags for uploading to BES in order to view results in the Bazel Build
# Results UI.
build:results --bes_backend="buildeventservice.googleapis.com"
+31
View File
@@ -0,0 +1,31 @@
---
name: Bug report
about: Create a bug report to help us improve
title:
labels:
- 'type: bug'
assignees: ''
---
**Description**
A clear description of what the bug is. If possible, explicitly indicate the
expected behavior vs. the observed behavior.
**Steps to reproduce**
If available, please include detailed reproduction steps.
If the bug requires software that is not publicly available, see if it can be
reproduced with software that is publicly available.
**Environment**
Please include the following details of your environment:
* `runsc -v`
* `docker version` or `docker info` (if available)
* `kubectl version` and `kubectl get nodes` (if using Kubernetes)
* `uname -a`
* `git describe` (if built from source)
* `runsc` debug logs (if available)
+11
View File
@@ -0,0 +1,11 @@
blank_issues_enabled: false
contact_links:
- name: gVisor Documentation (FAQ)
url: https://gvisor.dev/docs/user_guide/faq/
about: Please see our documentation for common questions and answers.
- name: gVisor Documentation (Debugging)
url: https://gvisor.dev/docs/user_guide/debugging/
about: Please see our documentation for debugging tips.
- name: gVisor User Forum
url: https://groups.google.com/g/gvisor-users
about: Ask and answer general questions here.
+21
View File
@@ -0,0 +1,21 @@
---
name: Feature request
about: Suggest an idea or improvement
title: ''
labels:
- 'type: enhancement'
assignees: ''
---
**Description**
A clear description of the feature or enhancement.
**Is this feature related to a specific bug?**
Please include a bug references if yes.
**Do you have a specific solution in mind?**
Please include any details about a solution that you have in mind, including any
alternatives considered.
-20
View File
@@ -1,20 +0,0 @@
Before filling an issue, please consult our FAQ:
https://gvisor.dev/docs/user_guide/faq/
Also check that the issue hasn't been reported before.
If you have a question, please email gvisor-users@googlegroups.com rather than filing a bug.
If you believe you've found a security issue, please email gvisor-security@googlegroups.com rather than filing a bug.
If this is your first time compiling or running gVisor, please make sure that your system meets the minimum requirements: https://github.com/google/gvisor#requirements
For all other issues, please attach debug logs. To get debug logs, follow the
instructions here: https://gvisor.dev/docs/user_guide/debugging/
Other useful information to include is:
* `runsc -v`
* `docker version` or `docker info` if more relevant
* `uname -a` - `git describe`
* Detailed reproduction steps
+42
View File
@@ -0,0 +1,42 @@
"arch: arm":
- "**/*_arm64.*"
- "**/*_aarch64.*"
"arch: x86_64":
- "**/*_amd64.*"
- "**/*_x86.*"
"area: bazel":
- "**/BUILD"
- "**/*.bzl"
"area: docs":
- "**/g3doc/**"
- "**/README.md"
"area: filesystem":
- "pkg/sentry/fs/**"
- "pkg/sentry/vfs/**"
- "pkg/sentry/fsimpl/**"
"area: hostinet":
- "pkg/sentry/socket/hostinet/**"
"area: networking":
- "pkg/tcpip/**"
- "pkg/sentry/socket/**"
"area: kernel":
- "pkg/sentry/arch/**"
- "pkg/sentry/kernel/**"
- "pkg/sentry/syscalls/**"
"area: mm":
- "pkg/sentry/mm/**"
"area: tests":
- "**/tests/**"
- "**/*_test.go"
- "**/test/**"
"area: tooling":
- "tools/**"
"dependencies":
- "WORKSPACE"
- "go.mod"
- "go.sum"
"platform: kvm":
- "pkg/sentry/platform/kvm/**"
- "pkg/sentry/platform/ring0/**"
"platform: ptrace":
- "pkg/sentry/platform/ptrace/**"
+5
View File
@@ -0,0 +1,5 @@
* [ ] Have you followed the guidelines in [CONTRIBUTING.md](../blob/master/CONTRIBUTING.md)?
* [ ] Have you formatted and linted your code?
* [ ] Have you added relevant tests?
* [ ] Have you added appropriate Fixes & Updates references?
* [ ] If yes, please erase all these lines!
+11
View File
@@ -0,0 +1,11 @@
name: "Labeler"
on:
- pull_request
jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: actions/labeler@v2
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
+20
View File
@@ -0,0 +1,20 @@
language: shell
dist: xenial
cache:
directories:
- /home/travis/.cache/bazel/
os: linux
services:
- docker
jobs:
include:
- os: linux
arch: amd64
- os: linux
arch: arm64
script:
- uname -a && make smoke-test
branches:
except:
# Skip copybara branches.
- /^test\/cl.*$/
+53 -11
View File
@@ -1,8 +1,8 @@
package(licenses = ["notice"]) # Apache 2.0
load("@io_bazel_rules_go//go:def.bzl", "go_path", "nogo")
load("@bazel_gazelle//:def.bzl", "gazelle")
package(licenses = ["notice"])
# The sandbox filegroup is used for sandbox-internal dependencies.
package_group(
name = "sandbox",
@@ -23,7 +23,18 @@ go_path(
"//runsc",
# Packages that are not dependencies of //runsc.
"//pkg/sentry/kernel/memevent",
"//pkg/tcpip/adapters/gonet",
"//pkg/tcpip/link/channel",
"//pkg/tcpip/link/muxed",
"//pkg/tcpip/link/sharedmem",
"//pkg/tcpip/link/sharedmem/pipe",
"//pkg/tcpip/link/sharedmem/queue",
"//pkg/tcpip/link/tun",
"//pkg/tcpip/link/waitable",
"//pkg/tcpip/sample/tun_tcp_connect",
"//pkg/tcpip/sample/tun_tcp_echo",
"//pkg/tcpip/transport/tcpconntrack",
],
)
@@ -33,14 +44,45 @@ go_path(
# bazel run //:gazelle -- update-repos -from_file=go.mod
gazelle(name = "gazelle")
# nogo applies checks to all Go source in this repository, enforcing code
# guidelines and restrictions. Note that the tool libraries themselves should
# live in the tools subdirectory (unless they are standard).
nogo(
name = "nogo",
config = "tools/nogo.js",
visibility = ["//visibility:public"],
deps = [
"//tools/checkunsafe",
# We need to define a bazel platform and toolchain to specify dockerPrivileged
# and dockerRunAsRoot options, they are required to run tests on the RBE
# cluster in Kokoro.
alias(
name = "rbe_ubuntu1604",
actual = ":rbe_ubuntu1604_r346485",
)
platform(
name = "rbe_ubuntu1604_r346485",
constraint_values = [
"@bazel_tools//platforms:x86_64",
"@bazel_tools//platforms:linux",
"@bazel_tools//tools/cpp:clang",
"@bazel_toolchains//constraints:xenial",
"@bazel_toolchains//constraints/sanitizers:support_msan",
],
remote_execution_properties = """
properties: {
name: "container-image"
value:"docker://gcr.io/cloud-marketplace/google/rbe-ubuntu16-04@sha256:93f7e127196b9b653d39830c50f8b05d49ef6fd8739a9b5b8ab16e1df5399e50"
}
properties: {
name: "dockerAddCapabilities"
value: "SYS_ADMIN"
}
properties: {
name: "dockerPrivileged"
value: "true"
}
""",
)
toolchain(
name = "cc-toolchain-clang-x86_64-default",
exec_compatible_with = [
],
target_compatible_with = [
],
toolchain = "@bazel_toolchains//configs/ubuntu16_04_clang/10.0.0/bazel_2.0.0/cc:cc-compiler-k8",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
+13 -26
View File
@@ -32,11 +32,15 @@ will need to be added to the appropriate `BUILD` files, and the `:gopath` target
will need to be re-run to generate appropriate symlinks in the `GOPATH`
directory tree.
Dependencies can be added by using `go mod get`. In order to keep the
`WORKSPACE` file in sync, run `tools/go_mod.sh` in place of `go mod`.
### Coding Guidelines
All Go code should conform to the [Go style guidelines][gostyle]. C++ code
should conform to the [Google C++ Style Guide][cppstyle] and the guidelines
described for [tests][teststyle].
described for [tests][teststyle]. Note that code may be automatically formatted
per the guidelines when merged.
As a secure runtime, we need to maintain the safety of all of code included in
gVisor. The following rules help mitigate issues.
@@ -46,7 +50,7 @@ Definitions for the rules below:
`core`:
* `//pkg/sentry/...`
* Transitive dependencies in `//pkg/...`, `//third_party/...`.
* Transitive dependencies in `//pkg/...`, etc.
`runsc`:
@@ -104,32 +108,15 @@ ignored.
### Build and test with Docker
`scripts/dev.sh` is a convenient script that builds and installs `runsc` as a
new Docker runtime for you. The scripts tries to extract the runtime name from
your local environment and will print it at the end. You can also customize it.
The script creates one regular runtime and another with debug flags enabled.
Here are a few examples:
Running `make dev` is a convenient way to build and install `runsc` as a Docker
runtime. The output of this command will show the runtimes installed.
You may use `make refresh` to refresh the binary after any changes. For example:
```bash
# Default case (inside branch my-branch)
$ scripts/dev.sh
...
Runtimes my-branch and my-branch-d (debug enabled) setup.
Use --runtime=my-branch with your Docker command.
docker run --rm --runtime=my-branch --rm hello-world
If you rebuild, use scripts/dev.sh --refresh.
Logs are in: /tmp/my-branch/logs
# --refresh just updates the runtime binary and doesn't restart docker.
$ git/my_branch> scripts/dev.sh --refresh
# Using a custom runtime name
$ git/my_branch> scripts/dev.sh my-runtime
...
Runtimes my-runtime and my-runtime-d (debug enabled) setup.
Use --runtime=my-runtime with your Docker command.
docker run --rm --runtime=my-runtime --rm hello-world
make dev
docker run --rm --runtime=my-branch --rm hello-world
make refresh
```
### The small print
-8
View File
@@ -1,8 +0,0 @@
FROM ubuntu:bionic
RUN apt-get update && apt-get install -y curl gnupg2 git python3
RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list && \
curl https://bazel.build/bazel-release.pub.gpg | apt-key add -
RUN apt-get update && apt-get install -y bazel && apt-get clean
WORKDIR /gvisor
+162 -36
View File
@@ -1,47 +1,173 @@
UID := $(shell id -u ${USER})
GID := $(shell id -g ${USER})
GVISOR_BAZEL_CACHE := $(shell readlink -f ~/.cache/bazel/)
#!/usr/bin/make -f
all: runsc
# Copyright 2019 The gVisor Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
docker-build:
docker build -t gvisor-bazel .
# Described below.
OPTIONS :=
TARGETS := //runsc
ARGS :=
bazel-shutdown:
docker exec -i gvisor-bazel bazel shutdown && \
docker kill gvisor-bazel
default: runsc
.PHONY: default
bazel-server-start: docker-build
mkdir -p "$(GVISOR_BAZEL_CACHE)" && \
docker run -d --rm --name gvisor-bazel \
--user 0:0 \
-v "$(GVISOR_BAZEL_CACHE):$(HOME)/.cache/bazel/" \
-v "$(CURDIR):$(CURDIR)" \
--workdir "$(CURDIR)" \
--tmpfs /tmp:rw,exec \
--privileged \
gvisor-bazel \
sh -c "while :; do sleep 100; done" && \
docker exec --user 0:0 -i gvisor-bazel sh -c "groupadd --gid $(GID) --non-unique gvisor && useradd --uid $(UID) --gid $(GID) -d $(HOME) gvisor"
## usage: make <target>
## or
## make <build|test|copy|run|sudo> OPTIONS="..." TARGETS="..." ARGS="..."
##
## Basic targets.
##
## This Makefile wraps basic build and test targets for ease-of-use. Bazel
## is run inside a canonical Docker container in order to simplify up-front
## requirements.
##
## There are common arguments that may be passed to targets. These are:
## OPTIONS - Build or test options.
## TARGETS - The bazel targets.
## ARGS - Arguments for run or sudo.
##
## Additionally, the copy target expects a DESTINATION to be provided.
##
## For example, to build runsc using this Makefile, you can run:
## make build OPTIONS="" TARGETS="//runsc"'
##
help: ## Shows all targets and help from the Makefile (this message).
@grep --no-filename -E '^([a-z.A-Z_-]+:.*?|)##' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = "(:.*?|)## ?"}; { \
if (length($$1) > 0) { \
printf " \033[36m%-20s\033[0m %s\n", $$1, $$2; \
} else { \
printf "%s\n", $$2; \
} \
}'
build: ## Builds the given $(TARGETS) with the given $(OPTIONS). E.g. make build TARGETS=runsc
test: ## Tests the given $(TARGETS) with the given $(OPTIONS). E.g. make test TARGETS=pkg/buffer:buffer_test
copy: ## Copies the given $(TARGETS) to the given $(DESTINATION). E.g. make copy TARGETS=runsc DESTINATION=/tmp
run: ## Runs the given $(TARGETS), built with $(OPTIONS), using $(ARGS). E.g. make run TARGETS=runsc ARGS=-version
sudo: ## Runs the given $(TARGETS) as per run, but using "sudo -E". E.g. make sudo TARGETS=test/root:root_test ARGS=-test.v
.PHONY: help build test copy run sudo
bazel-server:
docker exec gvisor-bazel true || \
$(MAKE) bazel-server-start
# Load all bazel wrappers.
#
# This file should define the basic "build", "test", "run" and "sudo" rules, in
# addition to the $(BRANCH_NAME) variable.
ifneq (,$(wildcard tools/google.mk))
include tools/google.mk
else
include tools/bazel.mk
endif
BAZEL_OPTIONS := build runsc
bazel: bazel-server
docker exec -u $(UID):$(GID) -i gvisor-bazel bazel $(BAZEL_OPTIONS)
##
## Docker image targets.
##
## Images used by the tests must also be built and available locally.
## The canonical test targets defined below will automatically load
## relevant images. These can be loaded or built manually via these
## targets.
##
## (*) Note that you may provide an ARCH parameter in order to build
## and load images from an alternate archiecture (using qemu). When
## bazel is run as a server, this has the effect of running an full
## cross-architecture chain, and can produce cross-compiled binaries.
##
define images
$(1)-%: ## Image tool: $(1) a given image (also may use 'all-images').
@$(MAKE) -C images $$@
endef
rebuild-...: ## Rebuild the given image. Also may use 'rebuild-all-images'.
$(eval $(call images,rebuild))
push-...: ## Push the given image. Also may use 'push-all-images'.
$(eval $(call images,pull))
pull-...: ## Pull the given image. Also may use 'pull-all-images'.
$(eval $(call images,push))
load-...: ## Load (pull or rebuild) the given image. Also may use 'load-all-images'.
$(eval $(call images,load))
list-images: ## List all available images.
@$(MAKE) -C images $$@
bazel-alias:
@echo "alias bazel='docker exec -u $(UID):$(GID) -i gvisor-bazel bazel'"
##
## Canonical build and test targets.
##
## These targets are used by continuous integration and provide
## convenient entrypoints for testing changes. If you're adding a
## new subsystem or workflow, consider adding a new target here.
##
runsc: ## Builds the runsc binary.
@$(MAKE) build TARGETS="//runsc"
.PHONY: runsc
runsc:
$(MAKE) BAZEL_OPTIONS="build runsc" bazel
smoke-test: ## Runs a simple smoke test after build runsc.
@$(MAKE) run DOCKER_RUN_OPTIONS="" ARGS="--alsologtostderr --network none --debug --TESTONLY-unsafe-nonroot=true --rootless do true"
.PHONY: smoke-tests
tests:
$(MAKE) BAZEL_OPTIONS="test --test_tag_filters runsc_ptrace //test/syscalls/..." bazel
unit-tests: ## Runs all unit tests in pkg runsc and tools.
@$(MAKE) test OPTIONS="pkg/... runsc/... tools/..."
.PHONY: unit-tests
unit-tests:
$(MAKE) BAZEL_OPTIONS="test //pkg/... //runsc/... //tools/..." bazel
tests: ## Runs all local ptrace system call tests.
@$(MAKE) test OPTIONS="--test_tag_filter runsc_ptrace test/syscalls/..."
.PHONY: tests
.PHONY: docker-build bazel-shutdown bazel-server-start bazel-server bazel runsc tests
##
## Development helpers and tooling.
##
## These targets faciliate local development by automatically
## installing and configuring a runtime. Several variables may
## be used here to tweak the installation:
## RUNTIME - The name of the installed runtime (default: branch).
## RUNTIME_DIR - Where the runtime will be installed (default: temporary directory with the $RUNTIME).
## RUNTIME_BIN - The runtime binary (default: $RUNTIME_DIR/runsc).
## RUNTIME_LOG_DIR - The logs directory (default: $RUNTIME_DIR/logs).
## RUNTIME_LOGS - The log pattern (default: $RUNTIME_LOG_DIR/runsc.log.%TEST%.%TIMESTAMP%.%COMMAND%).
##
ifeq (,$(BRANCH_NAME))
RUNTIME := runsc
RUNTIME_DIR := $(shell dirname $(shell mktemp -u))/runsc
else
RUNTIME := $(BRANCH_NAME)
RUNTIME_DIR := $(shell dirname $(shell mktemp -u))/$(BRANCH_NAME)
endif
RUNTIME_BIN := $(RUNTIME_DIR)/runsc
RUNTIME_LOG_DIR := $(RUNTIME_DIR)/logs
RUNTIME_LOGS := $(RUNTIME_LOG_DIR)/runsc.log.%TEST%.%TIMESTAMP%.%COMMAND%
dev: ## Installs a set of local runtimes. Requires sudo.
@$(MAKE) refresh ARGS="--net-raw"
@$(MAKE) configure RUNTIME="$(RUNTIME)" ARGS="--net-raw"
@$(MAKE) configure RUNTIME="$(RUNTIME)-d" ARGS="--net-raw --debug --strace --log-packets"
@$(MAKE) configure RUNTIME="$(RUNTIME)-p" ARGS="--net-raw --profile"
@sudo systemctl restart docker
.PHONY: dev
refresh: ## Refreshes the runtime binary (for development only). Must have called 'dev' or 'test-install' first.
@mkdir -p "$(RUNTIME_DIR)"
@$(MAKE) copy TARGETS=runsc DESTINATION="$(RUNTIME_BIN)" && chmod 0755 "$(RUNTIME_BIN)"
.PHONY: install
test-install: ## Installs the runtime for testing. Requires sudo.
@$(MAKE) refresh ARGS="--net-raw --TESTONLY-test-name-env=RUNSC_TEST_NAME --debug --strace --log-packets $(ARGS)"
@$(MAKE) configure
@sudo systemctl restart docker
.PHONY: install-test
configure: ## Configures a single runtime. Requires sudo. Typically called from dev or test-install.
@sudo sudo "$(RUNTIME_BIN)" install --experimental=true --runtime="$(RUNTIME)" -- --debug-log "$(RUNTIME_LOGS)" $(ARGS)
@echo "Installed runtime \"$(RUNTIME)\" @ $(RUNTIME_BIN)"
@echo "Logs are in: $(RUNTIME_LOG_DIR)"
@sudo rm -rf "$(RUNTIME_LOG_DIR)" && mkdir -p "$(RUNTIME_LOG_DIR)"
.PHONY: configure
test-runtime: ## A convenient wrapper around test that provides the runtime argument. Target must still be provided.
@$(MAKE) test OPTIONS="$(OPTIONS) --test_arg=--runtime=$(RUNTIME)"
.PHONY: runtime-test
+2 -1
View File
@@ -48,9 +48,10 @@ Make sure the following dependencies are installed:
* Linux 4.14.77+ ([older linux][old-linux])
* [git][git]
* [Bazel][bazel] 0.28.0+
* [Bazel][bazel] 1.2+
* [Python][python]
* [Docker version 17.09.0 or greater][docker]
* C++ toolchain supporting C++17 (GCC 7+, Clang 5+)
* Gold linker (e.g. `binutils-gold` package on Ubuntu)
### Building
+230 -44
View File
@@ -1,37 +1,57 @@
# Load go bazel rules and gazelle.
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# Load go bazel rules and gazelle.
#
# Note that this repository actually patches some other Go repositories as it
# loads it, in order to limit visibility. We hack this process by patching the
# patch used by the Go rules, turning the trick against itself.
http_archive(
name = "io_bazel_rules_go",
sha256 = "842ec0e6b4fbfdd3de6150b61af92901eeb73681fd4d185746644c338f51d4c0",
patch_args = ["-p1"],
patches = [
"//tools/nogo:io_bazel_rules_go-visibility.patch",
],
sha256 = "db2b2d35293f405430f553bc7a865a8749a8ef60c30287e90d2b278c32771afe",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.1/rules_go-v0.20.1.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.1/rules_go-v0.20.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.22.3/rules_go-v0.22.3.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/v0.22.3/rules_go-v0.22.3.tar.gz",
],
)
http_archive(
name = "bazel_gazelle",
sha256 = "41bff2a0b32b02f20c227d234aa25ef3783998e5453f7eade929704dcff7cd4b",
sha256 = "d8c45ee70ec39a57e7a05e5027c32b1576cc7f16d9dd37135b0eddde45cf1b10",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.0/bazel-gazelle-v0.19.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.0/bazel-gazelle-v0.19.0.tar.gz",
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gazelle-v0.20.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.20.0/bazel-gazelle-v0.20.0.tar.gz",
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
go_rules_dependencies()
go_register_toolchains(
go_version = "1.13.3",
nogo = "@//:nogo",
)
go_register_toolchains(go_version = "1.14.2")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
gazelle_dependencies()
# TODO(gvisor.dev/issue/1876): Move the statement to "External repositories"
# block below once 1876 is fixed.
#
# The com_google_protobuf repository below would trigger downloading a older
# version of org_golang_x_sys. If putting this repository statment in a place
# after that of the com_google_protobuf, this statement will not work as
# expectd to download a new version of org_golang_x_sys.
go_repository(
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=",
version = "v0.0.0-20200302150141-5c8b2ff67527",
)
# Load C++ rules.
http_archive(
name = "rules_cc",
@@ -45,28 +65,50 @@ http_archive(
# Load protobuf dependencies.
http_archive(
name = "com_google_protobuf",
sha256 = "532d2575d8c0992065bb19ec5fba13aa3683499726f6055c11b474f91a00bb0c",
strip_prefix = "protobuf-7f520092d9050d96fb4b707ad11a51701af4ce49",
name = "rules_proto",
sha256 = "602e7161d9195e50246177e7c55b2f39950a9cf7366f74ed5f22fd45750cd208",
strip_prefix = "rules_proto-97d8af4dc474595af3900dd85cb3a29ad28cc313",
urls = [
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/7f520092d9050d96fb4b707ad11a51701af4ce49.zip",
"https://github.com/protocolbuffers/protobuf/archive/7f520092d9050d96fb4b707ad11a51701af4ce49.zip",
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/97d8af4dc474595af3900dd85cb3a29ad28cc313.tar.gz",
],
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
protobuf_deps()
rules_proto_dependencies()
rules_proto_toolchains()
# Load python dependencies.
git_repository(
name = "rules_python",
commit = "abc4869e02fe9b3866942e89f07b7341f830e805",
remote = "https://github.com/bazelbuild/rules_python.git",
shallow_since = "1583341286 -0500",
)
load("@rules_python//python:pip.bzl", "pip_import")
pip_import(
name = "pydeps",
python_interpreter = "python3",
requirements = "//benchmarks:requirements.txt",
)
load("@pydeps//:requirements.bzl", "pip_install")
pip_install()
# Load bazel_toolchain to support Remote Build Execution.
# See releases at https://releases.bazel.build/bazel-toolchains.html
http_archive(
name = "bazel_toolchains",
sha256 = "a019fbd579ce5aed0239de865b2d8281dbb809efd537bf42e0d366783e8dec65",
strip_prefix = "bazel-toolchains-0.29.2",
sha256 = "239a1a673861eabf988e9804f45da3b94da28d1aff05c373b013193c315d9d9e",
strip_prefix = "bazel-toolchains-3.0.1",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/0.29.2.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/0.29.2.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/releases/download/3.0.1/bazel-toolchains-3.0.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/releases/download/3.0.1/bazel-toolchains-3.0.1.tar.gz",
],
)
@@ -85,6 +127,24 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies")
rules_pkg_dependencies()
# Load C++ grpc rules.
http_archive(
name = "com_github_grpc_grpc",
sha256 = "2fcb7f1ab160d6fd3aaade64520be3e5446fc4c6fa7ba6581afdc4e26094bd81",
strip_prefix = "grpc-1.26.0",
urls = [
"https://github.com/grpc/grpc/archive/v1.26.0.tar.gz",
],
)
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
grpc_deps()
load("@com_github_grpc_grpc//bazel:grpc_extra_deps.bzl", "grpc_extra_deps")
grpc_extra_deps()
# External repositories, in sorted order.
go_repository(
name = "com_github_cenkalti_backoff",
@@ -128,6 +188,13 @@ go_repository(
version = "v0.0.0-20171129191014-dec09d789f3d",
)
go_repository(
name = "com_github_kr_pretty",
importpath = "github.com/kr/pretty",
sum = "h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=",
version = "v0.2.0",
)
go_repository(
name = "com_github_kr_pty",
importpath = "github.com/kr/pty",
@@ -135,6 +202,19 @@ go_repository(
version = "v1.1.1",
)
go_repository(
name = "com_github_kr_text",
importpath = "github.com/kr/text",
sum = "h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=",
version = "v0.1.0",
)
go_repository(
name = "com_github_mohae_deepcopy",
commit = "c48cc78d482608239f6c4c92a4abd87eb8761c90",
importpath = "github.com/mohae/deepcopy",
)
go_repository(
name = "com_github_opencontainers_runtime-spec",
importpath = "github.com/opencontainers/runtime-spec",
@@ -163,6 +243,21 @@ go_repository(
version = "v0.0.0-20171111001504-be1fbeda1936",
)
go_repository(
name = "org_golang_google_grpc",
build_file_proto_mode = "disable",
importpath = "google.golang.org/grpc",
sum = "h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=",
version = "v1.27.1",
)
go_repository(
name = "in_gopkg_check_v1",
importpath = "gopkg.in/check.v1",
sum = "h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=",
version = "v1.0.0-20190902080502-41f04d3bba15",
)
go_repository(
name = "org_golang_x_crypto",
importpath = "golang.org/x/crypto",
@@ -170,24 +265,18 @@ go_repository(
version = "v0.0.0-20190308221718-c2843e01d9a2",
)
go_repository(
name = "org_golang_x_mod",
importpath = "golang.org/x/mod",
sum = "h1:p1YOIz9H/mGN8k1XkaV5VFAq9+zhN9Obefv439UwRhI=",
version = "v0.2.1-0.20200224194123-e5e73c1b9c72",
)
go_repository(
name = "org_golang_x_net",
importpath = "golang.org/x/net",
sum = "h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=",
version = "v0.0.0-20190311183353-d8887717615a",
)
go_repository(
name = "org_golang_x_text",
importpath = "golang.org/x/text",
sum = "h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=",
version = "v0.3.0",
)
go_repository(
name = "org_golang_x_tools",
commit = "36563e24a262",
importpath = "golang.org/x/tools",
sum = "h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=",
version = "v0.0.0-20190620200207-3b0461eec859",
)
go_repository(
@@ -198,22 +287,31 @@ go_repository(
)
go_repository(
name = "org_golang_x_sys",
importpath = "golang.org/x/sys",
sum = "h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=",
version = "v0.0.0-20190215142949-d0b11bdaac8a",
name = "org_golang_x_text",
importpath = "golang.org/x/text",
sum = "h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=",
version = "v0.3.0",
)
go_repository(
name = "org_golang_x_time",
commit = "c4c64cad1fd0a1a8dab2523e04e61d35308e131e",
importpath = "golang.org/x/time",
sum = "h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=",
version = "v0.0.0-20191024005414-555d28b269f0",
)
go_repository(
name = "org_golang_x_tools",
commit = "aa82965741a9fecd12b026fbb3d3c6ed3231b8f8",
importpath = "golang.org/x/tools",
sum = "h1:Uglradbb4KfUWaYasZhlsDsGRwHHvRsHoNAEONef0W8=",
version = "v0.0.0-20200131233409-575de47986ce",
)
go_repository(
name = "org_golang_x_xerrors",
importpath = "golang.org/x/xerrors",
sum = "h1:9zdDQZ7Thm29KFXgAX/+yaf3eVbP7djjWp/dXAppNCc=",
version = "v0.0.0-20190717185122-a985d3407aa7",
)
go_repository(
@@ -230,6 +328,84 @@ go_repository(
version = "v1.3.1",
)
go_repository(
name = "com_github_google_go-github",
importpath = "github.com/google/go-github",
sum = "h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=",
version = "v17.0.0",
)
go_repository(
name = "org_golang_x_oauth2",
importpath = "golang.org/x/oauth2",
sum = "h1:pE8b58s1HRDMi8RDc79m0HISf9D4TzseP40cEA6IGfs=",
version = "v0.0.0-20191202225959-858c2ad4c8b6",
)
go_repository(
name = "com_github_google_go-querystring",
importpath = "github.com/google/go-querystring",
sum = "h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=",
version = "v1.0.0",
)
go_repository(
name = "com_google_cloud_go_bigquery",
importpath = "cloud.google.com/go/bigquery",
sum = "h1:K2NyuHRuv15ku6eUpe0DQk5ZykPMnSOnvuVf6IHcjaE=",
version = "v1.5.0",
)
go_repository(
name = "org_golang_google_api",
importpath = "google.golang.org/api",
sum = "h1:jz2KixHX7EcCPiQrySzPdnYT7DbINAypCqKZ1Z7GM40=",
version = "v0.20.0",
)
go_repository(
name = "org_uber_go_atomic",
importpath = "go.uber.org/atomic",
version = "v1.6.0",
sum = "h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=",
)
go_repository(
name = "org_uber_go_multierr",
importpath = "go.uber.org/multierr",
version = "v1.5.0",
sum = "h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=",
)
# BigQuery Dependencies for Benchmarks
go_repository(
name = "com_google_cloud_go",
importpath = "cloud.google.com/go",
sum = "h1:eoz/lYxKSL4CNAiaUJ0ZfD1J3bfMYbU5B3rwM1C1EIU=",
version = "v0.55.0",
)
go_repository(
name = "com_github_googleapis_gax_go_v2",
importpath = "github.com/googleapis/gax-go/v2",
sum = "h1:sjZBwGj9Jlw33ImPtvFviGYvseOtDM7hkSKB7+Tv3SM=",
version = "v2.0.5",
)
go_repository(
name = "io_opencensus_go",
importpath = "go.opencensus.io",
sum = "h1:8sGtKOrtQqkN1bp2AtX+misvLIlOmsEsNd+9NIcPEm8=",
version = "v0.22.3",
)
go_repository(
name = "com_github_golang_groupcache",
importpath = "github.com/golang/groupcache",
sum = "h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY=",
version = "v0.0.0-20200121045136-8c9f03a8e57e",
)
# System Call test dependencies.
http_archive(
name = "com_google_absl",
@@ -250,3 +426,13 @@ http_archive(
"https://github.com/google/googletest/archive/565f1b848215b77c3732bca345fe76a0431d8b34.tar.gz",
],
)
http_archive(
name = "com_google_benchmark",
sha256 = "3c6a165b6ecc948967a1ead710d4a181d7b0fbcaa183ef7ea84604994966221a",
strip_prefix = "benchmark-1.5.0",
urls = [
"https://mirror.bazel.build/github.com/google/benchmark/archive/v1.5.0.tar.gz",
"https://github.com/google/benchmark/archive/v1.5.0.tar.gz",
],
)
+28
View File
@@ -0,0 +1,28 @@
package(licenses = ["notice"])
config_setting(
name = "gcloud_rule",
values = {
"define": "gcloud=off",
},
)
py_binary(
name = "benchmarks",
srcs = ["run.py"],
data = select({
":gcloud_rule": [],
"//conditions:default": [
"//tools/vm:ubuntu1604",
"//tools/vm:zone",
],
}),
main = "run.py",
python_version = "PY3",
srcs_version = "PY3",
tags = [
"local",
"manual",
],
deps = ["//benchmarks/runner"],
)
+186
View File
@@ -0,0 +1,186 @@
# Benchmark tools
These scripts are tools for collecting performance data for Docker-based tests.
## Setup
The scripts assume the following:
* There are two sets of machines: one where the scripts will be run
(controller) and one or more machines on which docker containers will be run
(environment).
* The controller machine must have bazel installed along with this source
code. You should be able to run a command like `bazel run //benchmarks --
--list`
* Environment machines must have docker and the required runtimes installed.
More specifically, you should be able to run a command like: `docker run
--runtime=$RUNTIME your/image`.
* The controller has ssh private key which can be used to login to environment
machines and run docker commands without using `sudo`. This is not required
if running locally via the `run-local` command.
* The docker daemon on each of your environment machines is listening on
`unix:///var/run/docker.sock` (docker's default).
For configuring the environment manually, consult the
[dockerd documentation][dockerd].
## Running benchmarks
### Locally
The tool is built to, by default, use Google Cloud Platform to run benchmarks,
but it does support GCP workflows. To run locally, run the following from the
benchmarks directory:
```bash
bazel run --define gcloud=off //benchmarks -- run-local startup
...
method,metric,result
startup.empty,startup_time_ms,652.5772
startup.node,startup_time_ms,1654.4042000000002
startup.ruby,startup_time_ms,1429.835
```
The above command ran the startup benchmark locally, which consists of three
benchmarks (empty, node, and ruby). Benchmark tools ran it on the default
runtime, runc. Running on another installed runtime, like say runsc, is as
simple as:
```bash
bazel run --define gcloud=off //benchmarks -- run-local startup --runtime=runsc
```
There is help:
```bash
bazel run --define gcloud=off //benchmarks -- --help
bazel run --define gcloud=off //benchmarks -- run-local --help
```
To list available benchmarks, use the `list` commmand:
```bash
bazel --define gcloud=off run //benchmarks -- list
...
Benchmark: sysbench.cpu
Metrics: events_per_second
Run sysbench CPU test. Additional arguments can be provided for sysbench.
:param max_prime: The maximum prime number to search.
```
You can choose benchmarks by name or regex like:
```bash
bazel run --define gcloud=off //benchmarks -- run-local startup.node
...
metric,result
startup_time_ms,1671.7178000000001
```
or
```bash
bazel run --define gcloud=off //benchmarks -- run-local s
...
method,metric,result
startup.empty,startup_time_ms,1792.8292
startup.node,startup_time_ms,3113.5274
startup.ruby,startup_time_ms,3025.2424
sysbench.cpu,cpu_events_per_second,12661.47
sysbench.memory,memory_ops_per_second,7228268.44
sysbench.mutex,mutex_time,17.4835
sysbench.mutex,mutex_latency,3496.7
sysbench.mutex,mutex_deviation,0.04
syscall.syscall,syscall_time_ns,2065.0
```
You can run parameterized benchmarks, for example to run with different
runtimes:
```bash
bazel run --define gcloud=off //benchmarks -- run-local --runtime=runc --runtime=runsc sysbench.cpu
```
Or with different parameters:
```bash
bazel run --define gcloud=off //benchmarks -- run-local --max_prime=10 --max_prime=100 sysbench.cpu
```
### On Google Compute Engine (GCE)
Benchmarks may be run on GCE in an automated way. The default project configured
for `gcloud` will be used.
An additional parameter `installers` may be provided to ensure that the latest
runtime is installed from the workspace. See the files in `tools/installers` for
supported install targets.
```bash
bazel run //benchmarks -- run-gcp --installers=head --runtime=runsc sysbench.cpu
```
When running on GCE, the scripts generate a per run SSH key, which is added to
your project. The key is set to expire in GCE after 60 minutes and is stored in
a temporary directory on the local machine running the scripts.
## Writing benchmarks
To write new benchmarks, you should familiarize yourself with the structure of
the repository. There are three key components.
## Harness
The harness makes use of the [docker py SDK][docker-py]. It is advisable that
you familiarize yourself with that API when making changes, specifically:
* clients
* containers
* images
In general, benchmarks need only interact with the `Machine` objects provided to
the benchmark function, which are the machines defined in the environment. These
objects allow the benchmark to define the relationships between different
containers, and parse the output.
## Workloads
The harness requires workloads to run. These are all available in the
`workloads` directory.
In general, a workload consists of a Dockerfile to build it (while these are not
hermetic, in general they should be as fixed and isolated as possible), some
parsers for output if required, parser tests and sample data. Provided the test
is named after the workload package and contains a function named `sample`, this
variable will be used to automatically mock workload output when the `--mock`
flag is provided to the main tool.
## Writing benchmarks
Benchmarks define the tests themselves. All benchmarks have the following
function signature:
```python
def my_func(output) -> float:
return float(output)
@benchmark(metrics = my_func, machines = 1)
def my_benchmark(machine: machine.Machine, arg: str):
return "3.4432"
```
Each benchmark takes a variable amount of position arguments as
`harness.Machine` objects and some set of keyword arguments. It is recommended
that you accept arbitrary keyword arguments and pass them through when
constructing the container under test.
To write a new benchmark, open a module in the `suites` directory and use the
above signature. You should add a descriptive doc string to describe what your
benchmark is and any test centric arguments.
[dockerd]: https://docs.docker.com/engine/reference/commandline/dockerd/
[docker-py]: https://docker-py.readthedocs.io/en/stable/
+14
View File
@@ -0,0 +1,14 @@
"""Provides attributes common to many workload tests."""
load("//tools:defs.bzl", "py_requirement")
test_deps = [
py_requirement("attrs", direct = False),
py_requirement("atomicwrites", direct = False),
py_requirement("more-itertools", direct = False),
py_requirement("pathlib2", direct = False),
py_requirement("pluggy", direct = False),
py_requirement("py", direct = False),
py_requirement("pytest"),
py_requirement("six", direct = False),
]
+2
View File
@@ -0,0 +1,2 @@
client: localhost
server: localhost
+202
View File
@@ -0,0 +1,202 @@
load("//tools:defs.bzl", "pkg_tar", "py_library", "py_requirement")
package(
default_visibility = ["//benchmarks:__subpackages__"],
licenses = ["notice"],
)
pkg_tar(
name = "installers",
srcs = [
"//tools/installers:head",
"//tools/installers:master",
"//tools/installers:runsc",
],
mode = "0755",
)
filegroup(
name = "files",
srcs = [
":installers",
],
)
py_library(
name = "harness",
srcs = ["__init__.py"],
data = [
":files",
],
)
py_library(
name = "benchmark_driver",
srcs = ["benchmark_driver.py"],
deps = [
"//benchmarks/harness/machine_mocks",
"//benchmarks/harness/machine_producers:machine_producer",
"//benchmarks/suites",
],
)
py_library(
name = "container",
srcs = ["container.py"],
deps = [
"//benchmarks/workloads",
py_requirement(
"asn1crypto",
direct = False,
),
py_requirement(
"chardet",
direct = False,
),
py_requirement(
"certifi",
direct = False,
),
py_requirement("docker"),
py_requirement(
"docker-pycreds",
direct = False,
),
py_requirement(
"idna",
direct = False,
),
py_requirement(
"ptyprocess",
direct = False,
),
py_requirement(
"requests",
direct = False,
),
py_requirement(
"urllib3",
direct = False,
),
py_requirement(
"websocket-client",
direct = False,
),
],
)
py_library(
name = "machine",
srcs = ["machine.py"],
deps = [
"//benchmarks/harness",
"//benchmarks/harness:container",
"//benchmarks/harness:ssh_connection",
"//benchmarks/harness:tunnel_dispatcher",
"//benchmarks/harness/machine_mocks",
py_requirement(
"asn1crypto",
direct = False,
),
py_requirement(
"chardet",
direct = False,
),
py_requirement(
"certifi",
direct = False,
),
py_requirement("docker"),
py_requirement(
"docker-pycreds",
direct = False,
),
py_requirement(
"idna",
direct = False,
),
py_requirement(
"ptyprocess",
direct = False,
),
py_requirement(
"requests",
direct = False,
),
py_requirement(
"six",
direct = False,
),
py_requirement(
"urllib3",
direct = False,
),
py_requirement(
"websocket-client",
direct = False,
),
],
)
py_library(
name = "ssh_connection",
srcs = ["ssh_connection.py"],
deps = [
"//benchmarks/harness",
py_requirement(
"bcrypt",
direct = False,
),
py_requirement("cffi"),
py_requirement("paramiko"),
py_requirement(
"cryptography",
direct = False,
),
],
)
py_library(
name = "tunnel_dispatcher",
srcs = ["tunnel_dispatcher.py"],
deps = [
py_requirement(
"asn1crypto",
direct = False,
),
py_requirement(
"chardet",
direct = False,
),
py_requirement(
"certifi",
direct = False,
),
py_requirement("docker"),
py_requirement(
"docker-pycreds",
direct = False,
),
py_requirement(
"idna",
direct = False,
),
py_requirement("pexpect"),
py_requirement(
"ptyprocess",
direct = False,
),
py_requirement(
"requests",
direct = False,
),
py_requirement(
"urllib3",
direct = False,
),
py_requirement(
"websocket-client",
direct = False,
),
],
)

Some files were not shown because too many files have changed in this diff Show More