Skip to content

fix: User events ci #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,21 @@ jobs:
- uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup-perf-decode
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
chmod +x scripts/setup_perf_decoder.sh
sudo ./scripts/setup_perf_decoder.sh
- name: Test (Windows)
if: ${{ matrix.os == 'windows-latest'}}
run: ./scripts/test.ps1
shell: pwsh
- name: Test (Unix)
if: ${{ matrix.os != 'windows-latest'}}
run: bash ./scripts/test.sh
- name: Test user_events
if: ${{ matrix.os == 'ubuntu-latest'}}
run: bash ./scripts/test_user_events.sh
lint:
strategy:
matrix:
Expand Down
33 changes: 13 additions & 20 deletions opentelemetry-user-events-logs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ mod tests {
#[test]
fn integration_test_basic() {
// Run using the below command
// sudo -E ~/.cargo/bin/cargo test integration_test_basic -- --nocapture --ignored
// sudo ./scripts/setup_perf_decoder.sh && sudo -E ~/.cargo/bin/cargo test integration_test_basic -- --nocapture --ignored

// Basic check if user_events are available
check_user_events_available().expect("Kernel does not support user_events. Verify your distribution/kernel supports user_events: https://docs.kernel.org/trace/user_events.html.");
Expand Down Expand Up @@ -135,7 +135,7 @@ mod tests {

// Start perf recording in a separate thread and emit logs in parallel.
let perf_thread =
std::thread::spawn(|| run_perf_and_decode(5, "user_events:myprovider_L2K1"));
std::thread::spawn(|| run_perf_and_decode(20, "user_events:myprovider_L2K1"));

// Give a little time for perf to start recording
std::thread::sleep(std::time::Duration::from_millis(1000));
Expand Down Expand Up @@ -180,6 +180,9 @@ mod tests {
.as_array()
.expect("Events for perf.data is not an array");

// display the events for debugging
println!("Events: {:#?}", events);

// Find the specific event. Its named providername:eventname format.
let event = events
.iter()
Expand Down Expand Up @@ -385,14 +388,15 @@ mod tests {
// Run perf record for duration_secs seconds
let perf_status = Command::new("sudo")
.args([
"timeout",
"-s",
"SIGINT",
&duration_secs.to_string(),
"perf",
"record",
"-o",
"/tmp/perf.data",
"-e",
event,
"--",
"sleep",
&duration_secs.to_string(),
])
.status()?;

Expand All @@ -407,21 +411,10 @@ mod tests {
}
}

// Change permissions on perf.data (which is the default file perf records to) to allow reading
let chmod_status = Command::new("sudo")
.args(["chmod", "uog+r", "./perf.data"])
.status()?;

if !chmod_status.success() {
panic!("chmod failed with exit code: {:?}", chmod_status.code());
}

// Decode the performance data and return it directly
// Note: This tool must be installed on the machine
// git clone https://github.com/microsoft/LinuxTracepoints &&
// cd LinuxTracepoints && mkdir build && cd build && cmake .. && make &&
// sudo cp bin/perf-decode /usr/local/bin &&
let decode_output = Command::new("perf-decode").args(["./perf.data"]).output()?;
let decode_output = Command::new("sudo")
.args(["perf-decode", "/tmp/perf.data"])
.output()?;

if !decode_output.status.success() {
panic!(
Expand Down
28 changes: 28 additions & 0 deletions scripts/setup_perf_decoder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e # Exit immediately if a command exits with a non-zero status
set -x # Print commands and their arguments as they are executed

# Update package lists
sudo apt-get update

# Install required dependencies
sudo apt-get install -y git build-essential cmake flex bison linux-tools-generic

# Clone and build LinuxTracepoints
git clone https://github.com/microsoft/LinuxTracepoints
cd LinuxTracepoints
mkdir build && cd build
cmake .. && make

# Install perf-decode
sudo cp bin/perf-decode /usr/local/bin

# Cleanup
cd ../..
rm -rf LinuxTracepoints

# Verify installation
perf --version
test -x /usr/local/bin/perf-decode && echo "perf-decode is executable"
exit 0
1 change: 1 addition & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ cargo test --workspace --all-features --tests

echo "Running doctests for all packages in workspace with --all-features"
cargo test --workspace --all-features --doc

4 changes: 4 additions & 0 deletions scripts/test_user_events.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set -eu

echo "Running user_events tests"
sudo -E ~/.cargo/bin/cargo test --manifest-path=opentelemetry-user-events-logs/Cargo.toml -- --nocapture --ignored
Loading