@@ -2,13 +2,14 @@ use std::collections::HashMap;
22use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
33
44use dashmap:: DashMap ;
5- use opentelemetry_proto:: tonic:: metrics:: v1:: { Metric , MetricsData } ;
65
76use crate :: {
87 index:: { ForwardIndex , InvertedIndex } ,
9- model:: { Attribute , MetricType , Sample , SeriesFingerprint , SeriesId , SeriesSpec , TimeBucket } ,
10- otel:: { OtelUtil , collect_resource_attributes, collect_scope_attributes} ,
11- util:: { Fingerprint , Result , normalize_str} ,
8+ model:: {
9+ Attribute , MetricType , Sample , SampleWithAttributes , SeriesFingerprint , SeriesId ,
10+ SeriesSpec , TimeBucket ,
11+ } ,
12+ util:: Fingerprint ,
1213} ;
1314
1415/// The delta chunk is the current in-memory segment of OpenTSDB representing
@@ -40,44 +41,14 @@ impl<'a> TsdbDeltaBuilder<'a> {
4041 }
4142 }
4243
43- /// Ingest a full MetricsData payload, processing all resource_metrics, scope_metrics, and metrics.
44- /// Resource and scope attributes are merged into each sample's attributes.
45- pub ( crate ) fn ingest_metrics_data ( mut self , data : MetricsData ) -> Result < Self > {
46- for resource_metrics in data. resource_metrics {
47- let resource_attrs = collect_resource_attributes ( resource_metrics. resource . as_ref ( ) ) ;
48-
49- for scope_metrics in resource_metrics. scope_metrics {
50- let scope_attrs = collect_scope_attributes ( scope_metrics. scope . as_ref ( ) ) ;
51-
52- for metric in scope_metrics. metrics {
53- self . ingest_metric_internal ( & metric, & resource_attrs, & scope_attrs) ?;
54- }
55- }
56- }
57- Ok ( self )
58- }
59-
60- /// Internal method to ingest a single metric with pre-collected resource and scope attributes
61- fn ingest_metric_internal (
62- & mut self ,
63- metric : & Metric ,
64- resource_attrs : & [ Attribute ] ,
65- scope_attrs : & [ Attribute ] ,
66- ) -> Result < ( ) > {
67- let metric_unit = normalize_str ( & metric. unit ) ;
68- let metric_type = MetricType :: try_from ( metric) ?;
69- let samples_with_attrs = OtelUtil :: samples ( metric, resource_attrs, scope_attrs) ;
70-
71- for sample_with_attrs in samples_with_attrs {
72- self . ingest_sample (
73- sample_with_attrs. attributes ,
74- metric_unit. clone ( ) ,
75- metric_type,
76- sample_with_attrs. sample ,
77- ) ;
78- }
79-
80- Ok ( ( ) )
44+ /// Ingest a sample with its attributes
45+ pub ( crate ) fn ingest ( & mut self , sample_with_attrs : SampleWithAttributes ) {
46+ self . ingest_sample (
47+ sample_with_attrs. attributes ,
48+ sample_with_attrs. metric_unit ,
49+ sample_with_attrs. metric_type ,
50+ sample_with_attrs. sample ,
51+ ) ;
8152 }
8253
8354 fn ingest_sample (
0 commit comments