Exclude csv_timestamp_column and csv_measurement_column from fields (#7572)
This commit is contained in:
parent
2561aac6ef
commit
092059c066
|
@ -211,8 +211,7 @@ cpu,42
|
|||
"path": tmpfile.Name(),
|
||||
},
|
||||
map[string]interface{}{
|
||||
"time_idle": 42,
|
||||
"measurement": "cpu",
|
||||
"time_idle": 42,
|
||||
},
|
||||
time.Unix(0, 0)),
|
||||
testutil.MustMetric("cpu",
|
||||
|
@ -220,8 +219,7 @@ cpu,42
|
|||
"path": tmpfile.Name(),
|
||||
},
|
||||
map[string]interface{}{
|
||||
"time_idle": 42,
|
||||
"measurement": "cpu",
|
||||
"time_idle": 42,
|
||||
},
|
||||
time.Unix(0, 0)),
|
||||
}
|
||||
|
|
|
@ -56,11 +56,13 @@ values.
|
|||
## will be added as fields.
|
||||
csv_tag_columns = []
|
||||
|
||||
## The column to extract the name of the metric from
|
||||
## The column to extract the name of the metric from. Will not be
|
||||
## included as field in metric.
|
||||
csv_measurement_column = ""
|
||||
|
||||
## The column to extract time information for the metric
|
||||
## `csv_timestamp_format` must be specified if this is used
|
||||
## `csv_timestamp_format` must be specified if this is used.
|
||||
## Will not be included as field in metric.
|
||||
csv_timestamp_column = ""
|
||||
|
||||
## The format of time data extracted from `csv_timestamp_column`
|
||||
|
|
|
@ -216,6 +216,10 @@ outer:
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Exclude `TimestampColumn` and `MeasurementColumn`
|
||||
delete(recordFields, p.TimestampColumn)
|
||||
delete(recordFields, p.MeasurementColumn)
|
||||
|
||||
m, err := metric.New(measurementName, tags, recordFields, metricTime)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -281,10 +281,10 @@ hello,80,test_name2`
|
|||
|
||||
expectedFields := map[string]interface{}{
|
||||
"line2": int64(80),
|
||||
"line3": "test_name2",
|
||||
}
|
||||
metrics, err := p.Parse([]byte(testCSV))
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "test_name2", metrics[0].Name())
|
||||
require.Equal(t, expectedFields, metrics[0].Fields())
|
||||
}
|
||||
|
||||
|
@ -364,7 +364,64 @@ func TestTimestampUnixFloatPrecision(t *testing.T) {
|
|||
map[string]string{},
|
||||
map[string]interface{}{
|
||||
"value": 42,
|
||||
"time": 1551129661.954561233,
|
||||
},
|
||||
time.Unix(1551129661, 954561233),
|
||||
),
|
||||
}
|
||||
|
||||
metrics, err := p.Parse([]byte(data))
|
||||
require.NoError(t, err)
|
||||
testutil.RequireMetricsEqual(t, expected, metrics)
|
||||
}
|
||||
|
||||
func TestSkipMeasurementColumn(t *testing.T) {
|
||||
p := Parser{
|
||||
MetricName: "csv",
|
||||
HeaderRowCount: 1,
|
||||
TimestampColumn: "timestamp",
|
||||
TimestampFormat: "unix",
|
||||
TimeFunc: DefaultTime,
|
||||
TrimSpace: true,
|
||||
}
|
||||
data := `id,value,timestamp
|
||||
1,5,1551129661.954561233`
|
||||
|
||||
expected := []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"csv",
|
||||
map[string]string{},
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"value": 5,
|
||||
},
|
||||
time.Unix(1551129661, 954561233),
|
||||
),
|
||||
}
|
||||
|
||||
metrics, err := p.Parse([]byte(data))
|
||||
require.NoError(t, err)
|
||||
testutil.RequireMetricsEqual(t, expected, metrics)
|
||||
}
|
||||
|
||||
func TestSkipTimestampColumn(t *testing.T) {
|
||||
p := Parser{
|
||||
MetricName: "csv",
|
||||
HeaderRowCount: 1,
|
||||
TimestampColumn: "timestamp",
|
||||
TimestampFormat: "unix",
|
||||
TimeFunc: DefaultTime,
|
||||
TrimSpace: true,
|
||||
}
|
||||
data := `id,value,timestamp
|
||||
1,5,1551129661.954561233`
|
||||
|
||||
expected := []telegraf.Metric{
|
||||
testutil.MustMetric(
|
||||
"csv",
|
||||
map[string]string{},
|
||||
map[string]interface{}{
|
||||
"id": 1,
|
||||
"value": 5,
|
||||
},
|
||||
time.Unix(1551129661, 954561233),
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue