Skip to content

Commit 320e7cb

Browse files
authored
feat(render): add parsed messages and decode code (#458)
Rename RustWireMessageGenerator.xtend -> RustMessageGenerator.xtend. Add code generation for parsed_message.rs that has a struct for each message with fields, including String for the strings sent in the message. Add a decode() method to instantiate each message struct from a buffer containing a message of that type. Also fix warning in Cargo Generator due to having profile.release in internal crates. We should have removed it when we started compiling from the root workspace, since that config belongs there. (cherry picked from commit a976cab)
1 parent 2a54240 commit 320e7cb

File tree

7 files changed

+332
-150
lines changed

7 files changed

+332
-150
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[workspace]
2+
resolver = "2"
23
members = [
34
"crates/kernel-collector-sys",
45
"crates/kernel-collector-bin",

cmake/render.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ function(render_compile INPUT_DIR)
8888
"${OUTPUT_DIR}/${PACKAGE}/${APP}/bpf.h"
8989
# Rust per-app crate files live under src/
9090
"${OUTPUT_DIR}/${PACKAGE}/${APP}/src/wire_messages.rs"
91+
"${OUTPUT_DIR}/${PACKAGE}/${APP}/src/parsed_message.rs"
9192
"${OUTPUT_DIR}/${PACKAGE}/${APP}/src/encoder.rs"
9293
"${OUTPUT_DIR}/${PACKAGE}/${APP}/src/hash.rs"
9394
"${OUTPUT_DIR}/${PACKAGE}/${APP}/Cargo.toml"
@@ -283,6 +284,7 @@ function(render_compile INPUT_DIR)
283284
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_src_dir}/src/lib.rs" "${_dest_dir}/src/lib.rs"
284285
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_src_dir}/src/encoder.rs" "${_dest_dir}/src/encoder.rs"
285286
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_src_dir}/src/wire_messages.rs" "${_dest_dir}/src/wire_messages.rs"
287+
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_src_dir}/src/parsed_message.rs" "${_dest_dir}/src/parsed_message.rs"
286288
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${_src_dir}/src/hash.rs" "${_dest_dir}/src/hash.rs"
287289
DEPENDS render_compile_${PACKAGE}
288290
VERBATIM

renderc/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ add_custom_command(
101101
./io.opentelemetry.render/src/io/opentelemetry/render/generator/TransformBuilderGenerator.xtend
102102
./io.opentelemetry.render/src/io/opentelemetry/render/generator/BpfGenerator.xtend
103103
./io.opentelemetry.render/src/io/opentelemetry/render/generator/RustEncoderGenerator.xtend
104-
./io.opentelemetry.render/src/io/opentelemetry/render/generator/RustWireMessageGenerator.xtend
104+
./io.opentelemetry.render/src/io/opentelemetry/render/generator/RustMessageGenerator.xtend
105105
./io.opentelemetry.render/src/io/opentelemetry/render/generator/RustCargoGenerator.xtend
106106
./io.opentelemetry.render/src/io/opentelemetry/render/generator/WriterGenerator.xtend
107107
./io.opentelemetry.render/src/io/opentelemetry/render/generator/SpanGenerator.xtend

renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/AppGenerator.xtend

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppGenerator {
1414
SpanGenerator spanGenerator = new SpanGenerator()
1515
HashGenerator hashGenerator = new HashGenerator()
1616
WriterGenerator writerGenerator = new WriterGenerator()
17-
RustWireMessageGenerator rustWireMessageGenerator = new RustWireMessageGenerator()
17+
RustMessageGenerator rustMessageGenerator = new RustMessageGenerator()
1818
RustEncoderGenerator rustEncoderGenerator = new RustEncoderGenerator()
1919
RustCargoGenerator rustCargoGenerator = new RustCargoGenerator()
2020
MessageGenerator messageGenerator = new MessageGenerator()
@@ -27,7 +27,7 @@ class AppGenerator {
2727
spanGenerator.doGenerate(app, fsa)
2828
hashGenerator.doGenerate(app, fsa)
2929
writerGenerator.doGenerate(app, fsa)
30-
rustWireMessageGenerator.doGenerate(app, fsa)
30+
rustMessageGenerator.doGenerate(app, fsa)
3131
rustEncoderGenerator.doGenerate(app, fsa)
3232
rustCargoGenerator.doGenerateApp(app, fsa)
3333
messageGenerator.doGenerate(app, fsa)

renderc/io.opentelemetry.render/src/io/opentelemetry/render/generator/RustCargoGenerator.xtend

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,6 @@ class RustCargoGenerator {
5656
# - staticlib: keeps support for direct C/C++ linking where needed.
5757
crate-type = ["rlib", "staticlib"]
5858
59-
[profile.release]
60-
opt-level = 3
61-
lto = true
62-
codegen-units = 1
63-
6459
[dependencies]
6560
render_parser = { workspace = true }
6661
'''
@@ -80,20 +75,14 @@ class RustCargoGenerator {
8075
pub len: u16,
8176
}
8277
83-
// Include generated modules from src/
78+
// Modules use the standard Rust module system; files live under src/
8479
#[allow(dead_code)]
85-
pub mod wire_messages {
86-
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/wire_messages.rs"));
87-
}
88-
89-
pub mod encoder {
90-
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/encoder.rs"));
91-
}
92-
80+
pub mod wire_messages;
9381
#[allow(dead_code)]
94-
pub mod hash {
95-
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/hash.rs"));
96-
}
82+
pub mod parsed_message;
83+
pub mod encoder;
84+
#[allow(dead_code)]
85+
pub mod hash;
9786
'''
9887
}
9988

@@ -110,11 +99,6 @@ class RustCargoGenerator {
11099
# link per-app crates directly via rlib dependencies.
111100
crate-type = ["staticlib"]
112101
113-
[profile.release]
114-
opt-level = 3
115-
lto = true
116-
codegen-units = 1
117-
118102
[dependencies]
119103
«FOR a : apps»encoder_«pkg»_«a.name» = { path = "«a.name»" }
120104
«ENDFOR»

0 commit comments

Comments
 (0)