fix: normalize otlp string keys (#2168)

This commit is contained in:
Ning Sun
2023-08-14 17:39:54 +08:00
committed by GitHub
parent b353bd20db
commit f3157df190
2 changed files with 11 additions and 8 deletions

View File

@@ -108,7 +108,7 @@ fn write_attribute(lines: &mut LinesWriter, attr: &KeyValue) -> Result<()> {
if let Some(val) = attr.value.as_ref().and_then(|v| v.value.as_ref()) {
match val {
any_value::Value::StringValue(s) => lines
.write_tag(&attr.key, s)
.write_tag(&normalize_otlp_name(&attr.key), s)
.context(error::OtlpMetricsWriteSnafu)?,
any_value::Value::IntValue(v) => lines

View File

@@ -79,12 +79,12 @@ mod test {
assert_eq!(
recordbatches.pretty_print().unwrap(),
"\
+------------+-------+------------+---------------------+----------------+
| resource | scope | host | greptime_timestamp | greptime_value |
+------------+-------+------------+---------------------+----------------+
| greptimedb | otel | testserver | 1970-01-01T00:00:00 | 105.0 |
| greptimedb | otel | testsevrer | 1970-01-01T00:00:00 | 100.0 |
+------------+-------+------------+---------------------+----------------+",
+------------+-------+--------------------+------------+---------------------+----------------+
| resource | scope | telemetry_sdk_name | host | greptime_timestamp | greptime_value |
+------------+-------+--------------------+------------+---------------------+----------------+
| greptimedb | otel | java | testserver | 1970-01-01T00:00:00 | 105.0 |
| greptimedb | otel | java | testsevrer | 1970-01-01T00:00:00 | 100.0 |
+------------+-------+--------------------+------------+---------------------+----------------+",
);
}
@@ -115,7 +115,10 @@ mod test {
data: Some(metric::Data::Gauge(gauge)),
}],
scope: Some(InstrumentationScope {
attributes: vec![keyvalue("scope", "otel")],
attributes: vec![
keyvalue("scope", "otel"),
keyvalue("telemetry.sdk.name", "java"),
],
..Default::default()
}),
..Default::default()