Skip to content

Commit

Permalink
Readded time label, removed labeling TODO. Refs #2
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikbend committed Dec 27, 2023
1 parent bedbeda commit 2a70c19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
7 changes: 6 additions & 1 deletion pkg/plugin/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ func (ds *ODataSource) query(clientInstance ODataClient, query backend.DataQuery

if qm.TimeProperty != nil {
log.DefaultLogger.Debug("Time property configured", "name", qm.TimeProperty.Name)
field := data.NewField(qm.TimeProperty.Name, nil, odata.ToArray(qm.TimeProperty.Type))
labels, err := data.LabelsFromString("time=" + qm.TimeProperty.Name)
if err != nil {
response.Error = err
return response
}
field := data.NewField(qm.TimeProperty.Name, labels, odata.ToArray(qm.TimeProperty.Type))
frame.Fields = append(frame.Fields, field)
}
for _, prop := range qm.Properties {
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/datasource_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestQuery(t *testing.T) {
),
),
expected: aDataResponse(withBaseFrame("defaultTestFrame",
withTimeField("time"),
withTimeField("time", true),
withField("int32", []*int32{}),
withField("boolean", []*bool{}),
withField("string", []*string{}),
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestQuery(t *testing.T) {
withProp("time", "2022-01-02T00:00:00Z")),
),
expected: aDataResponse(withBaseFrame("defaultTestFrame",
withTimeField("time"),
withTimeField("time", false),
withField("int32", []*int32{}),
withField("boolean", []*bool{}),
withField("string", []*string{}),
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestQuery(t *testing.T) {
withProp("otherTimePropName", "2022-01-02T00:00:00Z")),
),
expected: aDataResponse(withBaseFrame("defaultTestFrame",
withTimeField("time"),
withTimeField("time", false),
withField("int32", []*int32{}),
withField("boolean", []*bool{}),
withField("string", []*string{}),
Expand Down
1 change: 0 additions & 1 deletion pkg/plugin/odata/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

// ToArray maps OData property types to Grafana Field type
func ToArray(propertyType string) interface{} {
// TODO: Add field labels here?
switch propertyType {
case EdmBoolean:
return []*bool{}
Expand Down
11 changes: 8 additions & 3 deletions pkg/plugin/testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ func withErrorResponse(err error) func(n *backend.DataResponse) {
func withDefaultTestFrame(builders ...func(*data.Frame)) func(n *backend.DataResponse) {
return func(dataResponse *backend.DataResponse) {
var frame = aDataFrame("defaultTestFrame", builders...)
timeLabel, _ := data.LabelsFromString("time=time")
frame.Fields = append(
frame.Fields,
data.NewField("time", nil, []*time.Time{}),
data.NewField("time", timeLabel, []*time.Time{}),
data.NewField("int32", nil, []*int32{}),
data.NewField("boolean", nil, []*bool{}),
data.NewField("string", nil, []*string{}),
Expand All @@ -174,9 +175,13 @@ func withBaseFrame(name string, builders ...func(*data.Frame)) func(n *backend.D
}
}

func withTimeField(name string) func(n *data.Frame) {
func withTimeField(name string, withLabels bool) func(n *data.Frame) {
return func(frame *data.Frame) {
frame.Fields = append(frame.Fields, data.NewField(name, nil, []*time.Time{}))
var labels data.Labels = nil
if withLabels {
labels, _ = data.LabelsFromString("time=" + name)
}
frame.Fields = append(frame.Fields, data.NewField(name, labels, []*time.Time{}))
}
}

Expand Down

0 comments on commit 2a70c19

Please sign in to comment.