Skip to content

feat: add function to materialize transport optimized parent ids #455

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

Merged
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
3 changes: 3 additions & 0 deletions go/pkg/otel/common/arrow/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@

func Equal(a, b *pcommon.Value) bool {
if a == nil || b == nil {
// TODO: in the future we may want to reconsider whether wo nil values
// are equal for purpose of delta encoding parent IDs.
// see https://github.com/open-telemetry/otel-arrow/issues/463

Check warning on line 318 in go/pkg/otel/common/arrow/attributes.go

View check run for this annotation

Codecov / codecov/patch

go/pkg/otel/common/arrow/attributes.go#L316-L318

Added lines #L316 - L318 were not covered by tests
return false
}

Expand Down
4 changes: 4 additions & 0 deletions rust/otel-arrow-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ tokio = { version = "1.43.0", features = ["rt", "time", "net", "io-util", "sync"
name = "otlp_bytes"
harness = false

[[bench]]
name = "materialize_parent_id"
harness = false

[dev-dependencies]
rand = "0.9"
nix = { version = "0.29.0", features = ["process", "signal"] }
Expand Down
115 changes: 115 additions & 0 deletions rust/otel-arrow-rust/benches/materialize_parent_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#![allow(missing_docs)]

use std::sync::Arc;

use arrow::array::{
BooleanArray, Float64Array, Int64Array, RecordBatch, StringBuilder, UInt8Array, UInt16Array,
};
use arrow::datatypes::{DataType, Field, Schema};
use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};

use otel_arrow_rust::otlp::attributes::{
decoder::materialize_parent_id, store::AttributeValueType,
};
use otel_arrow_rust::schema::consts;

fn create_bench_batch(num_attrs: usize) -> RecordBatch {
let mut types = UInt8Array::builder(num_attrs);
let mut keys = StringBuilder::new();
let mut str_values = StringBuilder::new();
let mut int_values = Int64Array::builder(num_attrs);
let mut double_values = Float64Array::builder(num_attrs);
let mut bool_values = BooleanArray::builder(num_attrs);
let mut parent_ids = UInt16Array::builder(num_attrs);

// Distribute value types: 40% string, 30% int, 20% double, 10% bool
let str_threshold = (num_attrs as f64 * 0.4) as usize;
let int_threshold = (num_attrs as f64 * 0.7) as usize;
let double_threshold = (num_attrs as f64 * 0.9) as usize;

for i in 0..num_attrs {
parent_ids.append_value(1);
let attr_name = format!("attr{}", (i as f64 / 50.0) as usize);
keys.append_value(attr_name);

if i < str_threshold {
types.append_value(AttributeValueType::Str as u8);
int_values.append_null();
bool_values.append_null();
double_values.append_null();
str_values.append_value(format!("str{}", (i as f64 / 10.0) as usize));
continue;
}

if i < int_threshold {
types.append_value(AttributeValueType::Int as u8);
bool_values.append_null();
double_values.append_null();
str_values.append_null();
int_values.append_value((i as f64 / 10.0) as i64);
continue;
}

if i < double_threshold {
types.append_value(AttributeValueType::Double as u8);
bool_values.append_null();
int_values.append_null();
str_values.append_null();
double_values.append_value((i as f64 / 10.0).floor());
continue;
}

types.append_value(AttributeValueType::Bool as u8);
str_values.append_null();
int_values.append_null();
double_values.append_null();
bool_values.append_value((i as f64 / 10.0) as usize % 2 == 0);
}

let schema = Schema::new(vec![
Field::new(consts::PARENT_ID, DataType::UInt16, false),
Field::new(consts::ATTRIBUTE_KEY, DataType::Utf8, false),
Field::new(consts::ATTRIBUTE_TYPE, DataType::UInt8, false),
Field::new(consts::ATTRIBUTE_STR, DataType::Utf8, true),
Field::new(consts::ATTRIBUTE_INT, DataType::Int64, true),
Field::new(consts::ATTRIBUTE_DOUBLE, DataType::Float64, true),
Field::new(consts::ATTRIBUTE_BOOL, DataType::Boolean, true),
]);

RecordBatch::try_new(Arc::new(schema), vec![
Arc::new(parent_ids.finish()),
Arc::new(keys.finish()),
Arc::new(types.finish()),
Arc::new(str_values.finish()),
Arc::new(int_values.finish()),
Arc::new(double_values.finish()),
Arc::new(bool_values.finish()),
])
.expect("expect can create this record batch")
}

fn bench_materialize_parent_ids(c: &mut Criterion) {
let mut group = c.benchmark_group("materialize_parent_ids");

for size in [0, 128, 1536, 8092] {
let input = create_bench_batch(size);
let _ = group.bench_with_input(
BenchmarkId::new("materialize_parent_ids", size),
&input,
|b, input| {
b.iter(|| {
let _ = materialize_parent_id::<u16>(input)
.expect("function should not error here");
});
},
);
}

group.finish()
}

criterion_group!(benches, bench_materialize_parent_ids);
criterion_main!(benches);
4 changes: 2 additions & 2 deletions rust/otel-arrow-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
pub(crate) mod arrays;
mod decode;
mod error;
mod otlp;
pub mod otlp;
#[allow(dead_code)]
mod schema;
pub mod schema;
#[cfg(test)]
mod test_util;
#[cfg(test)]
Expand Down
3 changes: 3 additions & 0 deletions rust/otel-arrow-rust/src/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// TODO write documentation for this crate
#![allow(missing_docs)]

pub mod attributes;
pub mod logs;
pub mod metrics;
Expand Down
Loading
Loading