Skip to content

Commit a9f5109

Browse files
committed
cleanup
1 parent da60dea commit a9f5109

5 files changed

Lines changed: 39 additions & 77 deletions

File tree

lib/saluki-components/src/encoders/datadog/metrics/v2/constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub const SERIES_V2_UNCOMPRESSED_SIZE_LIMIT: usize = 5_242_880; // 5 MiB
55

66
// Protocol Buffers field numbers for series and sketch payload messages in the V2 format.
77
//
8-
// These field numbers come from the Protocol Buffers definitions in `lib/datadog-protos/proto/agent_payload.proto`.
8+
// These field numbers come from the Protocol Buffers definitions in `lib/protos/datadog/proto/agent-payload/agent_payload.proto`.
99
pub const RESOURCES_TYPE_FIELD_NUMBER: u32 = 1;
1010
pub const RESOURCES_NAME_FIELD_NUMBER: u32 = 2;
1111

lib/saluki-components/src/encoders/datadog/metrics/v3/interner.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
//! Generic interning for dictionary deduplication.
22
3-
use std::{borrow::Borrow, collections::HashMap, hash::Hash};
3+
use std::{borrow::Borrow, hash::Hash};
4+
5+
use saluki_common::collections::FastHashMap;
46

57
/// Generic interning structure for dictionary deduplication.
68
///
79
/// Assigns unique 1-based IDs to values, returning the same ID for duplicate values.
810
/// ID 0 is reserved for "empty/none" in the V3 format.
911
#[derive(Debug)]
1012
pub struct Interner<K: Eq + Hash> {
11-
index: HashMap<K, i64>,
13+
index: FastHashMap<K, i64>,
1214
last_id: i64,
1315
}
1416

@@ -22,7 +24,7 @@ impl<K: Eq + Hash> Interner<K> {
2224
/// Creates a new empty interner.
2325
pub fn new() -> Self {
2426
Self {
25-
index: HashMap::new(),
27+
index: FastHashMap::default(),
2628
last_id: 0,
2729
}
2830
}
@@ -46,16 +48,10 @@ impl<K: Eq + Hash> Interner<K> {
4648
}
4749

4850
/// Returns the number of interned values.
49-
#[allow(dead_code)]
51+
#[cfg(test)]
5052
pub fn len(&self) -> usize {
5153
self.index.len()
5254
}
53-
54-
/// Returns true if no values have been interned.
55-
#[allow(dead_code)]
56-
pub fn is_empty(&self) -> bool {
57-
self.index.is_empty()
58-
}
5955
}
6056

6157
#[cfg(test)]

lib/saluki-components/src/encoders/datadog/metrics/v3/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//! - Batch encoding - all metrics must be collected before serialization
1111
//! - Separate value columns for different numeric types (sint64, float32, float64)
1212
13+
mod constants;
1314
mod interner;
1415
mod types;
1516
mod writer;

lib/saluki-components/src/encoders/datadog/metrics/v3/types.rs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,8 @@
11
//! V3 payload type definitions and protocol buffer field numbers.
22
3-
/// Protocol buffer field numbers for MetricData message.
4-
///
5-
/// These correspond to the field numbers in `payload_v3.proto`.
6-
pub mod field_numbers {
7-
// Dictionary fields
8-
pub const DICT_NAME_STR: u32 = 1;
9-
pub const DICT_TAGS_STR: u32 = 2;
10-
pub const DICT_TAGSETS: u32 = 3;
11-
pub const DICT_RESOURCE_STR: u32 = 4;
12-
pub const DICT_RESOURCE_LEN: u32 = 5;
13-
pub const DICT_RESOURCE_TYPE: u32 = 6;
14-
pub const DICT_RESOURCE_NAME: u32 = 7;
15-
pub const DICT_SOURCE_TYPE_NAME: u32 = 8;
16-
pub const DICT_ORIGIN_INFO: u32 = 9;
17-
18-
// Per-metric columns
19-
pub const TYPES: u32 = 10;
20-
pub const NAMES: u32 = 11;
21-
pub const TAGS: u32 = 12;
22-
pub const RESOURCES: u32 = 13;
23-
pub const INTERVALS: u32 = 14;
24-
pub const NUM_POINTS: u32 = 15;
25-
26-
// Point data
27-
pub const TIMESTAMPS: u32 = 16;
28-
pub const VALS_SINT64: u32 = 17;
29-
pub const VALS_FLOAT32: u32 = 18;
30-
pub const VALS_FLOAT64: u32 = 19;
31-
32-
// Sketch data
33-
pub const SKETCH_NUM_BINS: u32 = 20;
34-
pub const SKETCH_BIN_KEYS: u32 = 21;
35-
pub const SKETCH_BIN_CNTS: u32 = 22;
36-
37-
// Additional per-metric columns
38-
pub const SOURCE_TYPE_NAME: u32 = 23;
39-
pub const ORIGIN_INFO: u32 = 24;
40-
}
41-
423
/// V3 metric type values.
434
///
44-
/// These match the `metricType` enum in `payload_v3.proto`.
5+
/// These match the `metricType` enum in `intake_v3.proto`.
456
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
467
#[repr(u8)]
478
pub enum V3MetricType {
@@ -53,7 +14,7 @@ pub enum V3MetricType {
5314

5415
impl V3MetricType {
5516
/// Returns the numeric value for encoding in the types column.
56-
pub fn as_u64(self) -> u64 {
17+
pub const fn as_u64(self) -> u64 {
5718
self as u64
5819
}
5920
}
@@ -67,10 +28,13 @@ impl V3MetricType {
6728
pub enum V3ValueType {
6829
/// Value is zero, not stored explicitly.
6930
Zero = 0x00,
31+
7032
/// Value is stored in vals_sint64.
7133
Sint64 = 0x10,
34+
7235
/// Value is stored in vals_float32.
7336
Float32 = 0x20,
37+
7438
/// Value is stored in vals_float64.
7539
Float64 = 0x30,
7640
}

lib/saluki-components/src/encoders/datadog/metrics/v3/writer.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use protobuf::CodedOutputStream;
77
use saluki_error::GenericError;
88

9+
use super::constants::*;
910
use super::interner::Interner;
10-
use super::types::{field_numbers, value_type_for_values, V3MetricType, V3ValueType};
11+
use super::types::{value_type_for_values, V3MetricType, V3ValueType};
1112

1213
const METRIC_TYPE_DEFAULT: i32 = 0;
1314
const METRIC_TYPE_AGENT_HIDDEN: i32 = 9;
@@ -183,49 +184,49 @@ impl V3Writer {
183184

184185
// Dictionary fields (bytes - varint-length-prefixed strings concatenated)
185186
if !data.dict_name_bytes.is_empty() {
186-
os.write_bytes(field_numbers::DICT_NAME_STR, &data.dict_name_bytes)?;
187+
os.write_bytes(DICT_NAME_STR_FIELD_NUMBER, &data.dict_name_bytes)?;
187188
}
188189
if !data.dict_tags_bytes.is_empty() {
189-
os.write_bytes(field_numbers::DICT_TAGS_STR, &data.dict_tags_bytes)?;
190+
os.write_bytes(DICT_TAGS_STR_FIELD_NUMBER, &data.dict_tags_bytes)?;
190191
}
191192

192193
// Packed repeated fields for dictionaries
193-
os.write_repeated_packed_sint64(field_numbers::DICT_TAGSETS, &data.dict_tagsets)?;
194+
os.write_repeated_packed_sint64(DICT_TAGSETS_FIELD_NUMBER, &data.dict_tagsets)?;
194195

195196
if !data.dict_resource_str_bytes.is_empty() {
196-
os.write_bytes(field_numbers::DICT_RESOURCE_STR, &data.dict_resource_str_bytes)?;
197+
os.write_bytes(DICT_RESOURCE_STR_FIELD_NUMBER, &data.dict_resource_str_bytes)?;
197198
}
198199

199-
os.write_repeated_packed_int64(field_numbers::DICT_RESOURCE_LEN, &data.dict_resource_len)?;
200-
os.write_repeated_packed_sint64(field_numbers::DICT_RESOURCE_TYPE, &data.dict_resource_type)?;
201-
os.write_repeated_packed_sint64(field_numbers::DICT_RESOURCE_NAME, &data.dict_resource_name)?;
200+
os.write_repeated_packed_int64(DICT_RESOURCE_LEN_FIELD_NUMBER, &data.dict_resource_len)?;
201+
os.write_repeated_packed_sint64(DICT_RESOURCE_TYPE_FIELD_NUMBER, &data.dict_resource_type)?;
202+
os.write_repeated_packed_sint64(DICT_RESOURCE_NAME_FIELD_NUMBER, &data.dict_resource_name)?;
202203

203204
if !data.dict_source_type_bytes.is_empty() {
204-
os.write_bytes(field_numbers::DICT_SOURCE_TYPE_NAME, &data.dict_source_type_bytes)?;
205+
os.write_bytes(DICT_SOURCE_TYPE_NAME_FIELD_NUMBER, &data.dict_source_type_bytes)?;
205206
}
206207

207-
os.write_repeated_packed_int32(field_numbers::DICT_ORIGIN_INFO, &data.dict_origin_info)?;
208+
os.write_repeated_packed_int32(DICT_ORIGIN_INFO_FIELD_NUMBER, &data.dict_origin_info)?;
208209

209210
// Per-metric columns
210-
os.write_repeated_packed_uint64(field_numbers::TYPES, &data.types)?;
211-
os.write_repeated_packed_sint64(field_numbers::NAMES, &data.names)?;
212-
os.write_repeated_packed_sint64(field_numbers::TAGS, &data.tags)?;
213-
os.write_repeated_packed_sint64(field_numbers::RESOURCES, &data.resources)?;
214-
os.write_repeated_packed_uint64(field_numbers::INTERVALS, &data.intervals)?;
215-
os.write_repeated_packed_uint64(field_numbers::NUM_POINTS, &data.num_points)?;
216-
os.write_repeated_packed_sint64(field_numbers::SOURCE_TYPE_NAME, &data.source_type_names)?;
217-
os.write_repeated_packed_sint64(field_numbers::ORIGIN_INFO, &data.origin_infos)?;
211+
os.write_repeated_packed_uint64(TYPES_FIELD_NUMBER, &data.types)?;
212+
os.write_repeated_packed_sint64(NAMES_FIELD_NUMBER, &data.names)?;
213+
os.write_repeated_packed_sint64(TAGS_FIELD_NUMBER, &data.tags)?;
214+
os.write_repeated_packed_sint64(RESOURCES_FIELD_NUMBER, &data.resources)?;
215+
os.write_repeated_packed_uint64(INTERVALS_FIELD_NUMBER, &data.intervals)?;
216+
os.write_repeated_packed_uint64(NUM_POINTS_FIELD_NUMBER, &data.num_points)?;
217+
os.write_repeated_packed_sint64(SOURCE_TYPE_NAME_FIELD_NUMBER, &data.source_type_names)?;
218+
os.write_repeated_packed_sint64(ORIGIN_INFO_FIELD_NUMBER, &data.origin_infos)?;
218219

219220
// Point data
220-
os.write_repeated_packed_sint64(field_numbers::TIMESTAMPS, &data.timestamps)?;
221-
os.write_repeated_packed_sint64(field_numbers::VALS_SINT64, &data.vals_sint64)?;
222-
os.write_repeated_packed_float(field_numbers::VALS_FLOAT32, &data.vals_float32)?;
223-
os.write_repeated_packed_double(field_numbers::VALS_FLOAT64, &data.vals_float64)?;
221+
os.write_repeated_packed_sint64(TIMESTAMPS_FIELD_NUMBER, &data.timestamps)?;
222+
os.write_repeated_packed_sint64(VALS_SINT64_FIELD_NUMBER, &data.vals_sint64)?;
223+
os.write_repeated_packed_float(VALS_FLOAT32_FIELD_NUMBER, &data.vals_float32)?;
224+
os.write_repeated_packed_double(VALS_FLOAT64_FIELD_NUMBER, &data.vals_float64)?;
224225

225226
// Sketch data
226-
os.write_repeated_packed_uint64(field_numbers::SKETCH_NUM_BINS, &data.sketch_num_bins)?;
227-
os.write_repeated_packed_sint32(field_numbers::SKETCH_BIN_KEYS, &data.sketch_bin_keys)?;
228-
os.write_repeated_packed_uint32(field_numbers::SKETCH_BIN_CNTS, &data.sketch_bin_cnts)?;
227+
os.write_repeated_packed_uint64(SKETCH_NUM_BINS_FIELD_NUMBER, &data.sketch_num_bins)?;
228+
os.write_repeated_packed_sint32(SKETCH_BIN_KEYS_FIELD_NUMBER, &data.sketch_bin_keys)?;
229+
os.write_repeated_packed_uint32(SKETCH_BIN_CNTS_FIELD_NUMBER, &data.sketch_bin_cnts)?;
229230

230231
os.flush()?;
231232
Ok(())

0 commit comments

Comments
 (0)