Skip to content

Commit

Permalink
[MAINTAINER] Add devcontainer (#3123)
Browse files Browse the repository at this point in the history
  • Loading branch information
esigo authored Jan 15, 2025
1 parent 95baed7 commit 465cb4a
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .devcontainer/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

FROM otel/cpp_format_tools

ARG GRPC_VERSION=v1.55.0
ARG PROTOBUF_VERSION=23.4
ARG ABSEIL_CPP_VERSION=20240116.1

ENV PROTOBUF_VERSION=${PROTOBUF_VERSION}
ENV ABSEIL_CPP_VERSION=${ABSEIL_CPP_VERSION}

COPY ci /opt/ci

RUN apt update && apt install -y wget \
ninja-build \
libcurl4-openssl-dev \
markdownlint

RUN cd /opt/ci && bash setup_cmake.sh
RUN cd /opt/ci && bash setup_ci_environment.sh
RUN cd /opt && bash ci/setup_googletest.sh \
&& bash ci/setup_grpc.sh -r ${GRPC_VERSION}

ADD https://github.com/bazelbuild/bazelisk/releases/download/v1.22.1/bazelisk-linux-amd64 /usr/local/bin

RUN git config --global core.autocrlf input \
&& chmod +x /usr/local/bin/bazelisk-linux-amd64
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.162.0/containers/javascript-node
{
"name": "opentelemetry-cpp",
"build": {
"context": "..",
"dockerfile": "Dockerfile.dev",
"args": {
"GRPC_VERSION": "v1.55.0",
"PROTOBUF_VERSION": "23.4",
"ABSEIL_CPP_VERSION":"20240116.1"
}
},
"settings": {
"terminal.integrated.shell.linux": "/bin/sh"
},
"extensions": [
"ms-vscode.cpptools",
"ms-azuretools.vscode-docker",
"ms-vscode.cpptools-extension-pack"
],

"remoteUser": "root"
}
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ updates:
interval: "daily"
labels:
- "GHA"

- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: daily
85 changes: 85 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,91 @@ bazel build //examples/simple:example_simple
bazel-bin/examples/simple/example_simple
```

### DevContainer Setup for Project

This guide provides instructions on how to set up and use the development
container (`devcontainer`) environment to streamline testing and development
for this project. With the DevContainer, you can work in a consistent environment
configured with all the necessary dependencies and tools.

#### Prerequisites

Before getting started, ensure you have the following installed:

* **Docker**: DevContainers require Docker for containerization.
* **Visual Studio Code (VSCode)** with the **Remote - Containers** extension.

#### Getting Started

* **Open the Project in DevContainer**:

Open the project in VSCode. When prompted to "Reopen in Container," select
this option. If you’re not prompted, you can manually open the container by
selecting **Remote-Containers: Reopen in Container** from the command palette
(`F1` or `Ctrl+Shift+P`).

* **Container Setup**:

The DevContainer environment will automatically build based on the configuration
files provided (e.g., `.devcontainer/devcontainer.json`). This setup will install
required dependencies, tools, and environment variables needed for the project.

#### Available Commands

Once inside the DevContainer, you can use the following commands to run tests
and CI workflows.

##### 1. Run Tests with Bazelisk

To run tests with Bazelisk using specific compilation options, use:

```bash
bazelisk-linux-amd64 test --copt=-DENABLE_LOGS_PREVIEW
--test_output=errors --cache_test_results=no --copt=-DENABLE_TEST //exporters/otlp/...
```

###### Command Breakdown

* `--copt=-DENABLE_LOGS_PREVIEW`: Enables preview logs.
* `--test_output=errors`: Shows only the errors in the test output.
* `--cache_test_results=no`: Forces Bazel to re-run tests without caching.
* `--copt=-DENABLE_TEST`: Enables testing capabilities for the target code.
* `//exporters/otlp/...`: Specifies the test target path.

##### 2. Run CI Script

You can also run the CI script provided to perform testing with the
following command as an
example:

```bash
bash ci/do_ci.sh cmake.exporter.otprotocol.test
```

This command initiates the CI pipeline, executing tests specifically for the
**cmake.exporter.otprotocol** module.

#### Troubleshooting

If you encounter issues:

* **Rebuild the DevContainer**: From the command palette, run
**Remote-Containers: Rebuild Container** to reinitialize the environment.
* **Check Bazelisk and CI Script Logs**: Inspect logs for any configuration or
dependency issues.

#### Additional Notes

* You can adjust compiler options (`--copt`) as needed to test additional flags
or enable/disable specific features.
* The test results will be displayed in the terminal within the DevContainer for
easy debugging.

#### Resources

* **Bazelisk Documentation**: [https://github.com/bazelbuild/bazelisk](https://github.com/bazelbuild/bazelisk)
* **VSCode DevContainer Documentation**: [https://code.visualstudio.com/docs/remote/containers](https://code.visualstudio.com/docs/remote/containers)

## Pull Requests

### How to Send Pull Requests
Expand Down
5 changes: 4 additions & 1 deletion ci/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Building and running tests as a developer

CI tests can be run on docker by invoking the script `./ci/run_docker.sh
./ci/do_ci.sh {TARGET}` where the targets are:
./ci/do_ci.sh {TARGET}`or inside
[devcontainer](../CONTRIBUTING.md#devcontainer-setup-for-project)
by invoking the script
`./ci/do_ci.sh {TARGET}` where the targets are:

* `cmake.test`: build cmake targets and run tests.
* `cmake.maintainer.test`: build with cmake and test, in maintainer mode.
Expand Down
2 changes: 1 addition & 1 deletion ci/run_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set -e

BUILD_IMAGE=opentelemetry-cpp-build
docker image inspect "$BUILD_IMAGE" &> /dev/null || {
docker build -t "$BUILD_IMAGE" ci
docker build -t "$BUILD_IMAGE" -f .devcontainer/Dockerfile.dev .
}

if [[ $# -ge 1 ]]; then
Expand Down

1 comment on commit 465cb4a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'OpenTelemetry-cpp api Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 465cb4a Previous: 95baed7 Ratio
BM_SpinLockThrashing/1/process_time/real_time 0.19755893949440334 ms/iter 0.09870270024175229 ms/iter 2.00
BM_NaiveSpinLockThrashing/2/process_time/real_time 1.393269651975387 ms/iter 0.20091704243233122 ms/iter 6.93
BM_NaiveSpinLockThrashing/4/process_time/real_time 2.581954002380371 ms/iter 0.7088751001742923 ms/iter 3.64
BM_ThreadYieldSpinLockThrashing/1/process_time/real_time 16.385998044695175 ms/iter 7.966167786542107 ms/iter 2.06

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.