Skip to content

Commit

Permalink
lightswitch-metadata: Rename crate and add hostname
Browse files Browse the repository at this point in the history
Just to make the name a bit more concise. Also add hostname and make
some other small changes to few metadata keys.

Test Plan
=========

Updated tests and added a new one.
  • Loading branch information
javierhonduco committed Nov 12, 2024
1 parent 2e7bc6a commit 66215c9
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 36 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
members = [
"lightswitch-proto",
"lightswitch-capabilities",
"lightswitch-metadata-provider",
"lightswitch-metadata",
"lightswitch-object"
]

Expand Down Expand Up @@ -45,7 +45,7 @@ ctrlc = "3.4.5"
crossbeam-channel = "0.5.13"
libbpf-sys = "1.5.0"
itertools = "0.13.0"
lightswitch-metadata-provider = {path = "lightswitch-metadata-provider"}
lightswitch-metadata = {path = "lightswitch-metadata"}
lightswitch-proto = { path = "lightswitch-proto"}
lightswitch-capabilities = {path = "lightswitch-capabilities"}
lightswitch-object = {path = "lightswitch-object"}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "lightswitch-metadata-provider"
name = "lightswitch-metadata"
version = "0.1.0"
edition = "2021"

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ impl GlobalMetadataProvider {
let pid = task_key.pid;
let mut task_metadata = vec![
MetadataLabel::from_number_value("pid".into(), task_key.tid.into(), "task-id".into()),
MetadataLabel::from_string_value("thread-name".into(), task_name.current_thread),
MetadataLabel::from_string_value("process-name".into(), task_name.main_thread),
MetadataLabel::from_string_value("thread.name".into(), task_name.current_thread),
MetadataLabel::from_string_value("process.name".into(), task_name.main_thread),
MetadataLabel::from_number_value("pid".into(), pid.into(), "task-tgid".into()),
];

Expand Down Expand Up @@ -119,12 +119,12 @@ mod tests {
labels[0].value,
MetadataLabelValue::Number(tid.into(), "task-id".into())
);
assert_eq!(labels[1].key, "thread-name");
assert_eq!(labels[1].key, "thread.name");
assert_eq!(
labels[1].value,
MetadataLabelValue::String(expected.current_thread)
);
assert_eq!(labels[2].key, "process-name");
assert_eq!(labels[2].key, "process.name");
assert_eq!(
labels[2].value,
MetadataLabelValue::String(expected.main_thread)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,27 @@ pub enum SystemMetadataError {
ErrorRetrievingSystemInfo(String),
}

fn get_kernel_release(uname: &utsname::UtsName) -> String {
format!(
"{}:{}",
uname.sysname().to_string_lossy(),
uname.release().to_string_lossy()
)
}

impl SystemMetadata {
pub fn get_metadata(&self) -> Result<Vec<MetadataLabel>, SystemMetadataError> {
let uname = utsname::uname()
.map_err(|e| SystemMetadataError::ErrorRetrievingSystemInfo(e.desc().to_string()))?;
let kernel_release_label =
MetadataLabel::from_string_value("kernel_release".into(), get_kernel_release(&uname));
let machine_label = MetadataLabel::from_string_value(
"machine".into(),
let kernel_release_label = MetadataLabel::from_string_value(
"kernel.release".into(),
uname.release().to_string_lossy().to_string(),
);
let architecture_label = MetadataLabel::from_string_value(
"kernel.architecture".into(),
uname.machine().to_string_lossy().to_string(),
);
Ok(vec![kernel_release_label, machine_label])
let hostname_label = MetadataLabel::from_string_value(
"hostname".into(),
uname.nodename().to_string_lossy().to_string(),
);
Ok(vec![
kernel_release_label,
architecture_label,
hostname_label,
])
}
}

Expand All @@ -52,24 +54,27 @@ mod tests {
assert!(result.is_ok());
let labels = result.unwrap();

assert_eq!(labels.len(), 2);
assert_eq!(labels.len(), 3);
let kernel_release = &labels[0];
let machine = &labels[1];
let hostname = &labels[2];

assert_eq!(kernel_release.key, "kernel_release");
assert_eq!(kernel_release.key, "kernel.release");
assert_eq!(
kernel_release.value,
MetadataLabelValue::String(format!(
"{}:{}",
expected.sysname().to_string_lossy(),
expected.release().to_string_lossy()
))
MetadataLabelValue::String(expected.release().to_string_lossy().to_string())
);

assert_eq!(machine.key, "machine");
assert_eq!(machine.key, "kernel.architecture");
assert_eq!(
machine.value,
MetadataLabelValue::String(expected.machine().to_string_lossy().to_string())
);

assert_eq!(hostname.key, "hostname");
assert_eq!(
hostname.value,
MetadataLabelValue::String(expected.nodename().to_string_lossy().to_string())
);
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use clap::Parser;
use crossbeam_channel::bounded;
use inferno::flamegraph;
use lightswitch::collector::{AggregatorCollector, Collector, NullCollector, StreamingCollector};
use lightswitch_metadata_provider::metadata_provider::GlobalMetadataProvider;
use lightswitch_metadata::metadata_provider::GlobalMetadataProvider;
use nix::unistd::Uid;
use prost::Message;
use tracing::{error, info, Level};
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::FmtSubscriber;

use lightswitch_capabilities::system_info::SystemInfo;
use lightswitch_metadata_provider::metadata_provider::ThreadSafeGlobalMetadataProvider;
use lightswitch_metadata::metadata_provider::ThreadSafeGlobalMetadataProvider;

use lightswitch::profile::symbolize_profile;
use lightswitch::profile::{fold_profile, to_pprof};
Expand Down
2 changes: 1 addition & 1 deletion src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::profile::RawAggregatedProfile;
use crate::profile::{symbolize_profile, to_pprof};
use lightswitch_object::ExecutableId;

use lightswitch_metadata_provider::metadata_provider::ThreadSafeGlobalMetadataProvider;
use lightswitch_metadata::metadata_provider::ThreadSafeGlobalMetadataProvider;

pub trait Collector {
fn collect(
Expand Down
6 changes: 3 additions & 3 deletions src/profile/convert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lightswitch_metadata_provider::metadata_label::MetadataLabelValue;
use lightswitch_metadata_provider::metadata_provider::{TaskKey, ThreadSafeGlobalMetadataProvider};
use lightswitch_metadata_provider::taskname::TaskName;
use lightswitch_metadata::metadata_label::MetadataLabelValue;
use lightswitch_metadata::metadata_provider::{TaskKey, ThreadSafeGlobalMetadataProvider};
use lightswitch_metadata::taskname::TaskName;

use lightswitch_proto::profile::pprof::Label;
use lightswitch_proto::profile::{pprof, LabelStringOrNumber, PprofBuilder};
Expand Down

0 comments on commit 66215c9

Please sign in to comment.