mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TestData: Support labels in CSV content name (#61337)
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
parent
4aa207ed83
commit
effe21fb65
@ -147,6 +147,16 @@ func LoadCsvContent(ioReader io.Reader, name string) (*data.Frame, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check for labels in the name
|
||||
idx := strings.Index(fieldName, "{")
|
||||
if idx >= 0 {
|
||||
labels := parseLabelsString(fieldName[idx:], fieldIndex) // _ := data.LabelsFromString(fieldName[idx:])
|
||||
if len(labels) > 0 {
|
||||
field.Labels = labels
|
||||
fieldName = fieldName[:idx]
|
||||
}
|
||||
}
|
||||
|
||||
field.Name = fieldName
|
||||
fields = append(fields, field)
|
||||
if field.Len() > longest {
|
||||
|
@ -22,7 +22,7 @@ func TestCSVFileScenario(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("loadCsvFile", func(t *testing.T) {
|
||||
files := []string{"simple", "mixed"}
|
||||
files := []string{"simple", "mixed", "labels"}
|
||||
for _, name := range files {
|
||||
t.Run("Should load CSV Text: "+name, func(t *testing.T) {
|
||||
filePath := filepath.Join("testdata", name+".csv")
|
||||
|
3
pkg/tsdb/testdatasource/testdata/labels.csv
vendored
Normal file
3
pkg/tsdb/testdatasource/testdata/labels.csv
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"a{foo=bar,x=y}",b{foo=baz},"{foo=x, no=name, idx=$seriesIndex}"
|
||||
1,2,3
|
||||
4,5,6
|
|
79
pkg/tsdb/testdatasource/testdata/labels.golden.jsonc
vendored
Normal file
79
pkg/tsdb/testdatasource/testdata/labels.golden.jsonc
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0]
|
||||
// Name: labels
|
||||
// Dimensions: 3 Fields by 2 Rows
|
||||
// +----------------------+-----------------+-------------------------------+
|
||||
// | Name: a | Name: b | Name: |
|
||||
// | Labels: foo=bar, x=y | Labels: foo=baz | Labels: foo=x, idx=2, no=name |
|
||||
// | Type: []*int64 | Type: []*int64 | Type: []*int64 |
|
||||
// +----------------------+-----------------+-------------------------------+
|
||||
// | 1 | 2 | 3 |
|
||||
// | 4 | 5 | 6 |
|
||||
// +----------------------+-----------------+-------------------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"name": "labels",
|
||||
"fields": [
|
||||
{
|
||||
"name": "a",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "int64",
|
||||
"nullable": true
|
||||
},
|
||||
"labels": {
|
||||
"foo": "bar",
|
||||
"x": "y"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "b",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "int64",
|
||||
"nullable": true
|
||||
},
|
||||
"labels": {
|
||||
"foo": "baz"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "int64",
|
||||
"nullable": true
|
||||
},
|
||||
"labels": {
|
||||
"foo": "x",
|
||||
"idx": "2",
|
||||
"no": "name"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1,
|
||||
4
|
||||
],
|
||||
[
|
||||
2,
|
||||
5
|
||||
],
|
||||
[
|
||||
3,
|
||||
6
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user