Skip to content

Commit 00db1f8

Browse files
committed
remove OTEL dependency to keep system minimal
1 parent ba40beb commit 00db1f8

7 files changed

Lines changed: 33 additions & 738 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

open-tsdb/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ thiserror.workspace = true
1818
uuid.workspace = true
1919

2020
blake3 = "1.8.2"
21-
opentelemetry-proto = "0.30"
2221
promql-parser = "0.6"
2322
roaring = "0.7"
2423
tsz = "0.1"

open-tsdb/src/delta.rs

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ use std::collections::HashMap;
22
use std::sync::atomic::{AtomicU32, Ordering};
33

44
use dashmap::DashMap;
5-
use opentelemetry_proto::tonic::metrics::v1::{Metric, MetricsData};
65

76
use 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(

open-tsdb/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod head;
44
mod index;
55
mod minitsdb;
66
mod model;
7-
mod otel;
87
mod promql;
98
mod serde;
109
mod storage;

open-tsdb/src/minitsdb.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ use std::sync::{Arc, atomic::AtomicU32};
2323

2424
use dashmap::DashMap;
2525
use opendata_common::{Storage, StorageRead};
26-
use opentelemetry_proto::tonic::metrics::v1::MetricsData;
2726
use tokio::sync::{Mutex, RwLock};
2827

2928
use crate::delta::{TsdbDelta, TsdbDeltaBuilder};
29+
use crate::head::TsdbHead;
30+
use crate::model::{SampleWithAttributes, SeriesFingerprint, SeriesId, TimeBucket};
3031
use crate::storage::OpenTsdbStorageReadExt;
3132
use crate::util::Result;
32-
use crate::{
33-
head::TsdbHead,
34-
model::{SeriesFingerprint, SeriesId, TimeBucket},
35-
};
3633

3734
pub(crate) struct MiniState {
3835
head: TsdbHead,
@@ -104,13 +101,16 @@ impl MiniTsdb {
104101
})
105102
}
106103

107-
/// Ingest an OLTP payload (this is the main entry point for ingestion)
108-
pub(crate) async fn ingest(&self, data: MetricsData) -> Result<()> {
109-
let delta =
110-
TsdbDeltaBuilder::new(self.bucket.clone(), &self.series_dict, &self.next_series_id)
111-
.ingest_metrics_data(data)?
112-
.build();
104+
/// Ingest samples with attributes (this is the main entry point for ingestion)
105+
pub(crate) async fn ingest(&self, samples: Vec<SampleWithAttributes>) -> Result<()> {
106+
let mut builder =
107+
TsdbDeltaBuilder::new(self.bucket.clone(), &self.series_dict, &self.next_series_id);
113108

109+
for sample in samples {
110+
builder.ingest(sample);
111+
}
112+
113+
let delta = builder.build();
114114
self.ingest_delta(&delta).await
115115
}
116116

open-tsdb/src/model.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ pub(crate) struct Sample {
8484
pub(crate) value: f64,
8585
}
8686

87+
/// A sample with all its attributes, including the metric name
88+
#[derive(Clone, Debug)]
89+
pub(crate) struct SampleWithAttributes {
90+
pub(crate) attributes: Vec<Attribute>,
91+
pub(crate) metric_unit: Option<String>,
92+
pub(crate) metric_type: MetricType,
93+
pub(crate) sample: Sample,
94+
}
95+
8796
/// Convert TimeBucketSize to hours
8897
pub fn time_bucket_size_hours(size: BucketSize) -> u32 {
8998
if size == 0 || size > 15 {

0 commit comments

Comments
 (0)