Skip to content

Commit

Permalink
Make struct fields private
Browse files Browse the repository at this point in the history
  • Loading branch information
VianneyRuhlmann committed Aug 21, 2024
1 parent 1295857 commit c6b0466
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
40 changes: 30 additions & 10 deletions data-pipeline/src/concentrator/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const TAG_ORIGIN: &str = "_dd.origin";

/// This struct represent the key used to group spans together to compute stats.
#[derive(Debug, Hash, PartialEq, Eq, Clone, Default)]
pub struct AggregationKey {
pub resource_name: String,
pub service_name: String,
pub operation_name: String,
pub span_type: String,
pub span_kind: String,
pub http_status_code: u32,
pub is_synthetics_request: bool,
pub peer_tags: Vec<Tag>,
pub is_trace_root: bool,
pub(crate) struct AggregationKey {
resource_name: String,
service_name: String,
operation_name: String,
span_type: String,
span_kind: String,
http_status_code: u32,
is_synthetics_request: bool,
peer_tags: Vec<Tag>,
is_trace_root: bool,
}

impl AggregationKey {
Expand Down Expand Up @@ -64,6 +64,26 @@ impl AggregationKey {
}
}

impl From<pb::ClientGroupedStats> for AggregationKey {
fn from(value: pb::ClientGroupedStats) -> Self {
Self {
resource_name: value.resource,
service_name: value.service,
operation_name: value.name,
span_type: value.r#type,
span_kind: value.span_kind,
http_status_code: value.http_status_code,
is_synthetics_request: value.synthetics,
peer_tags: value
.peer_tags
.into_iter()
.flat_map(|t| ddcommon::tag::parse_tags(&t).0)
.collect(),
is_trace_root: value.is_trace_root == 1,
}
}
}

/// Return the status code of a span based on the metrics and meta tags.
fn get_status_code(span: &pb::Span) -> u32 {
if let Some(status_code) = span.metrics.get(TAG_STATUS_CODE) {
Expand Down
23 changes: 2 additions & 21 deletions data-pipeline/src/concentrator/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0
//! This module implements the Concentrator used to aggregate spans into stats
#![allow(dead_code)] // TODO: Remove once the trace exporter uses the concentrator
use std::collections::HashMap;
use std::time::{self, Duration, SystemTime};

Expand Down Expand Up @@ -221,24 +220,6 @@ mod tests {
span
}

fn aggregation_key_from_grouped_stats(value: pb::ClientGroupedStats) -> AggregationKey {
AggregationKey {
resource_name: value.resource,
service_name: value.service,
operation_name: value.name,
span_type: value.r#type,
span_kind: value.span_kind,
http_status_code: value.http_status_code,
is_synthetics_request: value.synthetics,
peer_tags: value
.peer_tags
.into_iter()
.flat_map(|t| ddcommon::tag::parse_tags(&t).0)
.collect(),
is_trace_root: value.is_trace_root == 1,
}
}

fn assert_counts_equal(
expected: Vec<pb::ClientGroupedStats>,
actual: Vec<pb::ClientGroupedStats>,
Expand All @@ -248,12 +229,12 @@ mod tests {
expected.into_iter().for_each(|mut group| {
group.ok_summary = vec![];
group.error_summary = vec![];
expected_map.insert(aggregation_key_from_grouped_stats(group.clone()), group);
expected_map.insert(AggregationKey::from(group.clone()), group);
});
actual.into_iter().for_each(|mut group| {
group.ok_summary = vec![];
group.error_summary = vec![];
actual_map.insert(aggregation_key_from_grouped_stats(group.clone()), group);
actual_map.insert(AggregationKey::from(group.clone()), group);
});
assert_eq!(expected_map, actual_map)
}
Expand Down

0 comments on commit c6b0466

Please sign in to comment.