Skip to content

Commit d0420ed

Browse files
committed
Create metrics library skeleton and simple daemon for collecting system metrics
This code (1) Creates a skeleton for a base metrics library, and handles standard initialization in the init_metrics(). A dependency from the launcher client is removed (2) Creates a systemd service which registers the base library, and adds its own system metrics to the provided meter Change-Id: Ie9c67ae8593f227db5b9f204b1aa8a82dcbe76e1
1 parent 65465a3 commit d0420ed

File tree

23 files changed

+220
-23
lines changed

23 files changed

+220
-23
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
- buildconfigs/oak_containers_orchestrator.sh
2323
- buildconfigs/oak_containers_stage1.sh
2424
- buildconfigs/oak_containers_syslogd.sh
25+
- buildconfigs/oak_containers_agent.sh
2526
- buildconfigs/oak_containers_system_image.sh
2627
- buildconfigs/oak_echo_enclave_app.sh
2728
- buildconfigs/oak_echo_raw_enclave_app.sh

.github/workflows/provenance.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- buildconfigs/oak_containers_orchestrator.toml
3131
- buildconfigs/oak_containers_stage1.toml
3232
- buildconfigs/oak_containers_syslogd.toml
33+
- buildconfigs/oak_containers_agent.toml
3334
- buildconfigs/oak_containers_system_image.toml
3435
- buildconfigs/oak_echo_enclave_app.toml
3536
- buildconfigs/oak_echo_raw_enclave_app.toml

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"oak_attestation_verification_test_utils",
1616
"oak_channel",
1717
"oak_client",
18+
"oak_containers_agent",
1819
"oak_containers_hello_world_trusted_app",
1920
"oak_containers_hello_world_untrusted_app",
2021
"oak_containers_launcher",
@@ -109,6 +110,7 @@ oak_attestation_verification = { path = "./oak_attestation_verification" }
109110
oak_attestation_verification_test_utils = { path = "./oak_attestation_verification_test_utils" }
110111
oak_channel = { path = "./oak_channel" }
111112
oak_client = { path = "./oak_client" }
113+
oak_containers_agent = { path = "./oak_containers_agent" }
112114
oak_containers_orchestrator = { path = "./oak_containers_orchestrator" }
113115
oak_containers_launcher = { path = "./oak_containers_launcher" }
114116
oak_containers_sdk = { path = "./oak_containers_sdk" }

FORCE_CI

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
34
1+
35

buildconfigs/oak_containers_agent.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
#
3+
# Build configuration for oak_containers_agent.
4+
#
5+
export PACKAGE_NAME=oak_containers_agent
6+
7+
export BUILD_COMMAND=(
8+
nix
9+
develop
10+
.#systemImageProvenance
11+
--command
12+
just
13+
oak_containers_agent
14+
)
15+
16+
export SUBJECT_PATHS=(
17+
oak_containers_agent/target/oak_containers_agent_patched
18+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
command = [
2+
"nix",
3+
"develop",
4+
".#systemImageProvenance",
5+
"--command",
6+
"just",
7+
"oak_containers_agent",
8+
]
9+
artifact_path = "./oak_containers_agent/target/oak_containers_agent_patched"

justfile

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ oak_containers_kernel:
8888
oak_containers_launcher:
8989
env cargo build --release --package='oak_containers_launcher'
9090

91-
oak_containers_system_image: oak_containers_orchestrator oak_containers_syslogd
91+
oak_containers_system_image: oak_containers_agent oak_containers_orchestrator oak_containers_syslogd
9292
echo "Using bazel config flag: $BAZEL_CONFIG_FLAG"
9393
# Copy dependencies into bazel build.
9494
mkdir --parents oak_containers_system_image/target/image_binaries
@@ -98,6 +98,9 @@ oak_containers_system_image: oak_containers_orchestrator oak_containers_syslogd
9898
cp --preserve=timestamps \
9999
oak_containers_syslogd/target/oak_containers_syslogd_patched \
100100
oak_containers_system_image/target/image_binaries/oak_containers_syslogd
101+
cp --preserve=timestamps \
102+
oak_containers_agent/target/oak_containers_agent_patched \
103+
oak_containers_system_image/target/image_binaries/oak_containers_agent
101104
# Build and compress.
102105
bazel build $BAZEL_CONFIG_FLAG oak_containers_system_image --build_tag_filters=+noci
103106
cp --preserve=timestamps \
@@ -128,6 +131,17 @@ oak_containers_syslogd:
128131
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 --set-rpath "" \
129132
oak_containers_syslogd/target/oak_containers_syslogd_patched
130133

134+
oak_containers_agent:
135+
env --chdir=oak_containers_agent \
136+
cargo build --release -Z unstable-options --out-dir=target
137+
# We can't patch the binary in-place, as that would confuse cargo.
138+
# Therefore we copy it to a new location and patch there.
139+
cp \
140+
oak_containers_agent/target/oak_containers_agent \
141+
oak_containers_agent/target/oak_containers_agent_patched
142+
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 --set-rpath "" \
143+
oak_containers_agent/target/oak_containers_agent_patched
144+
131145
# Profile the Wasm execution and generate a flamegraph.
132146
profile_wasm:
133147
# If it fails with SIGSEGV, try running again.

kokoro/build_binaries_oak_containers.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ touch "${KOKORO_ARTIFACTS_DIR}/binaries/git_commit_${KOKORO_GIT_COMMIT_oak:?}"
2020
# Copy the generated binaries to Placer. The timestamps are used to convey
2121
# the creation time.
2222
#
23-
# System image deps (oak_containers_orchestrator, oak_containers_syslogd)
24-
# are tracked to monitor their reproducibility. They are expected to be
25-
# imported transiently into google3 for the sake of provenance verification
26-
# (i.e., do Kokoro and GitHub produce identical results).
23+
# System image deps (oak_containers_orchestrator, oak_containers_syslogd,
24+
# oak_containers_agent) are tracked to monitor their reproducibility. They are
25+
# expected to be imported transiently into google3 for the sake of provenance
26+
# verification (i.e., do Kokoro and GitHub produce identical results).
2727
readonly generated_binaries=(
2828
./target/stage1.cpio
2929
./oak_containers_kernel/target/bzImage
3030
./oak_containers_orchestrator/target/oak_containers_orchestrator
3131
./oak_containers_syslogd/target/oak_containers_syslogd_patched
32+
./oak_containers_agent/target/oak_containers_agent_patched
3233
./oak_containers_system_image/target/image.tar.xz
3334
./oak_containers_hello_world_container/target/oak_container_example_oci_filesystem_bundle.tar
3435
./oak_functions_containers_container/target/oak_functions_container_oci_filesystem_bundle.tar
@@ -39,6 +40,7 @@ readonly binary_names=(
3940
oak_containers_kernel
4041
oak_containers_orchestrator
4142
oak_containers_syslogd
43+
oak_containers_agent
4244
oak_containers_system_image
4345
oak_containers_hello_world_container
4446
oak_functions_container

oak_containers_agent/Cargo.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "oak_containers_agent"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "Apache-2.0"
6+
7+
[dependencies]
8+
anyhow = "*"
9+
clap = { version = "*", features = ["derive"] }
10+
opentelemetry = { version = "*", default-features = false, features = [
11+
"metrics",
12+
] }
13+
opentelemetry_sdk = { version = "*", default-features = false, features = [
14+
"metrics",
15+
"rt-tokio",
16+
] }
17+
opentelemetry-otlp = { version = "*", default-features = false, features = [
18+
"grpc-tonic",
19+
"metrics",
20+
] }
21+
procfs = "*"
22+
tokio = { version = "*", features = [
23+
"rt-multi-thread",
24+
"macros",
25+
"sync",
26+
"time",
27+
] }
28+
tokio-stream = { version = "*", features = ["net"] }
29+
30+
[build-dependencies]
31+
oak_grpc_utils = { workspace = true }

oak_containers_agent/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- Oak Logo Start -->
2+
<!-- An HTML element is intentionally used since GitHub recommends this approach to handle different images in dark/light modes. Ref: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to -->
3+
<!-- markdownlint-disable-next-line MD033 -->
4+
<h1><picture><source media="(prefers-color-scheme: dark)" srcset="/docs/oak-logo/svgs/oak-containers-negative-colour.svg?sanitize=true"><source media="(prefers-color-scheme: light)" srcset="/docs/oak-logo/svgs/oak-containers.svg?sanitize=true"><img alt="Project Oak Containers Logo" src="/docs/oak-logo/svgs/oak-containers.svg?sanitize=true"></picture></h1>
5+
<!-- Oak Logo End -->
6+
7+
# Oak Containers Metrics
8+
9+
This is a simple daemon that exports system-level metrics.
10+
11+
The crate includes a base library that wraps Opentelemtry to include standard
12+
process metrics for any application importing the library

0 commit comments

Comments
 (0)