Skip to content

Commit

Permalink
fix: remove flags field
Browse files Browse the repository at this point in the history
Helps open-telemetry/opentelemetry-collector-contrib#29896

The flags field is set as an unsigned integer, which is not compatible
with InfluxDB 1.x. Luckily, the field is also not useful, as it stores
a value chosen from an enum containing no useful values.

In this change, the flags field is removed from conversion. If it needs
to be added in the future, we can expect that enough time will have
passed that retention policies will have removed the prior `flags` field.
  • Loading branch information
jacobmarble committed May 25, 2024
1 parent 3e3c07a commit cb655fb
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 103 deletions.
2 changes: 1 addition & 1 deletion docs/logs.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ timestamp | `time_unix_nano` fixed64
`otel.log.dropped_attributes_count` field uint | `dropped_attributes_count` uint32
`severity_number` tag uint | `severity_number` enum SeverityNumber | | `level` number | `PRI severity` integer | `PRI severity` integer
`severity_text` field string | `severity_text` string
`otel.log.flags` field uint | `flags` fixed32
. | `flags` fixed32
. | `attributes["fluent.tag"]` string | `tag` string
. | `Resource.attributes["net.host.name"]` string | | `host` string | `HEADER hostname` string | `HOSTNAME` string
. | `Resource.attributes["net.host.ip"]` string | | | `HEADER IP address` string | `HOSTNAME` string
Expand Down
38 changes: 4 additions & 34 deletions influx2otel/metrics_telegraf_prometheus_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ func (b *MetricsBatch) convertGaugeV1(measurement string, tags map[string]string
}
}
}
if flagsObj, ok := fields[common.AttributeFlags]; ok {
if flagsUint64, ok := flagsObj.(uint64); ok {
dataPoint.SetFlags(pmetric.DataPointFlags(flagsUint64))
}
}

if floatValue != nil {
dataPoint.SetDoubleValue(*floatValue)
Expand All @@ -114,7 +109,7 @@ func (b *MetricsBatch) convertGaugeV1(measurement string, tags map[string]string
var floatValue *float64
var intValue *int64

if k == common.AttributeStartTimeStatsd || k == common.AttributeFlags {
if k == common.AttributeStartTimeStatsd {
continue
}
switch typedValue := fieldValue.(type) {
Expand Down Expand Up @@ -145,11 +140,6 @@ func (b *MetricsBatch) convertGaugeV1(measurement string, tags map[string]string
}
}
}
if flagsObj, ok := fields[common.AttributeFlags]; ok {
if flagsUint64, ok := flagsObj.(uint64); ok {
dataPoint.SetFlags(pmetric.DataPointFlags(flagsUint64))
}
}

if floatValue != nil {
dataPoint.SetDoubleValue(*floatValue)
Expand Down Expand Up @@ -193,11 +183,6 @@ func (b *MetricsBatch) convertSumV1(measurement string, tags map[string]string,
}
}
}
if flagsObj, ok := fields[common.AttributeFlags]; ok {
if flagsUint64, ok := flagsObj.(uint64); ok {
dataPoint.SetFlags(pmetric.DataPointFlags(flagsUint64))
}
}

if floatValue != nil {
dataPoint.SetDoubleValue(*floatValue)
Expand All @@ -211,7 +196,7 @@ func (b *MetricsBatch) convertSumV1(measurement string, tags map[string]string,
}

for k, fieldValue := range fields {
if k == common.AttributeStartTimeStatsd || k == common.AttributeFlags {
if k == common.AttributeStartTimeStatsd {
continue
}

Expand Down Expand Up @@ -245,11 +230,6 @@ func (b *MetricsBatch) convertSumV1(measurement string, tags map[string]string,
}
}
}
if flagsObj, ok := fields[common.AttributeFlags]; ok {
if flagsUint64, ok := flagsObj.(uint64); ok {
dataPoint.SetFlags(pmetric.DataPointFlags(flagsUint64))
}
}

if floatValue != nil {
dataPoint.SetDoubleValue(*floatValue)
Expand Down Expand Up @@ -295,7 +275,7 @@ func (b *MetricsBatch) convertHistogramV1(measurement string, tags map[string]st
bucketCounts = append(bucketCounts, uint64(vBucketCount))
}

} else if k == common.AttributeStartTimeStatsd || k == common.AttributeFlags {
} else if k == common.AttributeStartTimeStatsd {
} else {
b.logger.Debug("skipping unrecognized histogram field", "field", k, "value", vi)
}
Expand Down Expand Up @@ -337,11 +317,6 @@ func (b *MetricsBatch) convertHistogramV1(measurement string, tags map[string]st
}
}
}
if flagsObj, ok := fields[common.AttributeFlags]; ok {
if flagsUint64, ok := flagsObj.(uint64); ok {
dataPoint.SetFlags(pmetric.DataPointFlags(flagsUint64))
}
}

dataPoint.SetCount(count)
dataPoint.SetSum(sum)
Expand Down Expand Up @@ -382,7 +357,7 @@ func (b *MetricsBatch) convertSummaryV1(measurement string, tags map[string]stri
valueAtQuantile.SetValue(value)
}

} else if k == common.AttributeStartTimeStatsd || k == common.AttributeFlags {
} else if k == common.AttributeStartTimeStatsd {
} else {
b.logger.Debug("skipping unrecognized summary field", "field", k, "value", vi)
}
Expand All @@ -408,11 +383,6 @@ func (b *MetricsBatch) convertSummaryV1(measurement string, tags map[string]stri
}
}
}
if flagsObj, ok := fields[common.AttributeFlags]; ok {
if flagsUint64, ok := flagsObj.(uint64); ok {
dataPoint.SetFlags(pmetric.DataPointFlags(flagsUint64))
}
}

dataPoint.SetCount(count)
dataPoint.SetSum(sum)
Expand Down
22 changes: 0 additions & 22 deletions influx2otel/metrics_telegraf_prometheus_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func TestAddPoint_v1_gauge(t *testing.T) {
},
map[string]interface{}{
"gauge": float64(23.9),
"flags": uint64(1),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeGauge)
Expand Down Expand Up @@ -60,12 +59,10 @@ func TestAddPoint_v1_gauge(t *testing.T) {
dp.Attributes().PutStr("engine_id", "0")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(23.9)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
dp = m.Gauge().DataPoints().AppendEmpty()
dp.Attributes().PutStr("engine_id", "1")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(11.9)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -84,7 +81,6 @@ func TestAddPoint_v1_untypedGauge(t *testing.T) {
},
map[string]interface{}{
"gauge": float64(23.9),
"flags": uint64(1),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeUntyped)
Expand Down Expand Up @@ -117,12 +113,10 @@ func TestAddPoint_v1_untypedGauge(t *testing.T) {
dp.Attributes().PutStr("engine_id", "0")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(23.9)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
dp = m.Gauge().DataPoints().AppendEmpty()
dp.Attributes().PutStr("engine_id", "1")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(11.9)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -142,7 +136,6 @@ func TestAddPoint_v1_sum(t *testing.T) {
},
map[string]interface{}{
"counter": float64(1027),
"flags": uint64(1),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeSum)
Expand Down Expand Up @@ -179,13 +172,11 @@ func TestAddPoint_v1_sum(t *testing.T) {
dp.Attributes().PutStr("method", "post")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(1027)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
dp = m.Sum().DataPoints().AppendEmpty()
dp.Attributes().PutStr("code", "400")
dp.Attributes().PutStr("method", "post")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(3)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -205,7 +196,6 @@ func TestAddPoint_v1_untypedSum(t *testing.T) {
},
map[string]interface{}{
"counter": float64(1027),
"flags": uint64(0),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeUntyped)
Expand Down Expand Up @@ -242,13 +232,11 @@ func TestAddPoint_v1_untypedSum(t *testing.T) {
dp.Attributes().PutStr("method", "post")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(1027)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))
dp = m.Sum().DataPoints().AppendEmpty()
dp.Attributes().PutStr("code", "400")
dp.Attributes().PutStr("method", "post")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetDoubleValue(3)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -275,7 +263,6 @@ func TestAddPoint_v1_histogram(t *testing.T) {
"0.5": float64(129389),
"1": float64(133988),
"+Inf": float64(144320),
"flags": uint64(1),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeHistogram)
Expand All @@ -299,7 +286,6 @@ func TestAddPoint_v1_histogram(t *testing.T) {
dp.SetSum(53423)
dp.BucketCounts().FromRaw([]uint64{24054, 9390, 66948, 28997, 4599, 10332})
dp.ExplicitBounds().FromRaw([]float64{0.05, 0.1, 0.2, 0.5, 1})
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -325,7 +311,6 @@ func TestAddPoint_v1_histogram_missingInfinityBucket(t *testing.T) {
"0.2": float64(100392),
"0.5": float64(129389),
"1": float64(133988),
"flags": uint64(0),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeHistogram)
Expand All @@ -349,7 +334,6 @@ func TestAddPoint_v1_histogram_missingInfinityBucket(t *testing.T) {
dp.SetSum(53423)
dp.BucketCounts().FromRaw([]uint64{24054, 9390, 66948, 28997, 4599, 10332})
dp.ExplicitBounds().FromRaw([]float64{0.05, 0.1, 0.2, 0.5, 1})
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -375,7 +359,6 @@ func TestAddPoint_v1_untypedHistogram(t *testing.T) {
"0.2": float64(100392),
"0.5": float64(129389),
"1": float64(133988),
"flags": uint64(1),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeUntyped)
Expand All @@ -399,7 +382,6 @@ func TestAddPoint_v1_untypedHistogram(t *testing.T) {
dp.SetSum(53423)
dp.BucketCounts().FromRaw([]uint64{24054, 9390, 66948, 28997, 4599, 10332})
dp.ExplicitBounds().FromRaw([]float64{0.05, 0.1, 0.2, 0.5, 1})
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))

assertMetricsEqual(t, expect, b.GetMetrics())
}
Expand All @@ -425,7 +407,6 @@ func TestAddPoint_v1_summary(t *testing.T) {
"0.5": float64(4773),
"0.9": float64(9001),
"0.99": float64(76656),
"flags": uint64(1),
},
time.Unix(0, 1395066363000000123),
common.InfluxMetricValueTypeSummary)
Expand All @@ -446,7 +427,6 @@ func TestAddPoint_v1_summary(t *testing.T) {
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(0, 1395066363000000123)))
dp.SetCount(2693)
dp.SetSum(17560473)
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(true))
qv := dp.QuantileValues().AppendEmpty()
qv.SetQuantile(0.01)
qv.SetValue(3102)
Expand Down Expand Up @@ -487,7 +467,6 @@ func TestAddPoint_v1_untypedSummary(t *testing.T) {
"0.5": float64(4773),
"0.9": float64(9001),
"0.99": float64(76656),
"flags": uint64(0),
},
time.Unix(0, 1395066363000000123).UTC(),
common.InfluxMetricValueTypeUntyped)
Expand All @@ -511,7 +490,6 @@ func TestAddPoint_v1_untypedSummary(t *testing.T) {
dp.SetSum(17560473)
dp.BucketCounts().FromRaw([]uint64{3102, 170, 1501, 4228, 67655, 2693})
dp.ExplicitBounds().FromRaw([]float64{0.01, 0.05, 0.5, 0.9, 0.99})
dp.SetFlags(pmetric.DefaultDataPointFlags.WithNoRecordedValue(false))

assertMetricsEqual(t, expect, b.GetMetrics())
}
4 changes: 2 additions & 2 deletions otel2influx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ For example:
- `Metric.unit` is ignored
- `Metric` values are assigned field keys `gauge`, `counter`, `count`, `sum`, `inf`
- Metric conversion follows Prometheus conventions for compatibility
- `LogRecord.flags` is ignored
- This is an enum with no values defines yet
- `flags` fields are ignored
- These are enum with no values defines yet

## Example Line Protocol

Expand Down
1 change: 0 additions & 1 deletion otel2influx/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ func (c *OtelLogsToLineProtocol) enqueueLogRecord(ctx context.Context, resource
tags := make(map[string]string, len(c.logRecordDimensions)+2)
fields := make(map[string]interface{})

fields[common.AttributeFlags] = uint64(logRecord.Flags())
if ots := logRecord.ObservedTimestamp().AsTime(); !ots.IsZero() && !ots.Equal(time.Unix(0, 0)) {
fields[common.AttributeObservedTimeUnixNano] = ots.UnixNano()
}
Expand Down
1 change: 0 additions & 1 deletion otel2influx/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ type basicDataPoint interface {
Timestamp() pcommon.Timestamp
StartTimestamp() pcommon.Timestamp
Attributes() pcommon.Map
Flags() pmetric.DataPointFlags
}
2 changes: 0 additions & 2 deletions otel2influx/metrics_otel_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (m *metricWriterOtelV1) enqueueSum(ctx context.Context, measurementName str

for i := 0; i < pm.Sum().DataPoints().Len(); i++ {
// TODO datapoint exemplars
// TODO datapoint flags
dataPoint := pm.Sum().DataPoints().At(i)

fields := make(map[string]interface{}, 3)
Expand Down Expand Up @@ -116,7 +115,6 @@ func (m *metricWriterOtelV1) enqueueHistogram(ctx context.Context, measurementNa

for i := 0; i < pm.Histogram().DataPoints().Len(); i++ {
// TODO datapoint exemplars
// TODO datapoint flags
dataPoint := pm.Histogram().DataPoints().At(i)

bucketCounts, explicitBounds := dataPoint.BucketCounts(), dataPoint.ExplicitBounds()
Expand Down
1 change: 0 additions & 1 deletion otel2influx/metrics_telegraf_prometheus_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (c *metricWriterTelegrafPrometheusV1) initMetricTagsAndTimestamp(dataPoint
if dataPoint.StartTimestamp() != 0 {
fields[common.AttributeStartTimeUnixNano] = int64(dataPoint.StartTimestamp())
}
fields[common.AttributeFlags] = uint64(dataPoint.Flags())

tags = maps.Clone(tags)
dataPoint.Attributes().Range(func(k string, v pcommon.Value) bool {
Expand Down
Loading

0 comments on commit cb655fb

Please sign in to comment.