-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add list time series to query editor
- Loading branch information
Showing
17 changed files
with
402 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package framer | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iotsitewise" | ||
"github.com/grafana/grafana-plugin-sdk-go/data" | ||
"github.com/grafana/iot-sitewise-datasource/pkg/framer/fields" | ||
"github.com/grafana/iot-sitewise-datasource/pkg/models" | ||
"github.com/grafana/iot-sitewise-datasource/pkg/sitewise/resource" | ||
|
||
) | ||
|
||
type TimeSeries iotsitewise.ListTimeSeriesOutput | ||
|
||
type timeSeriesSummaryFields struct { | ||
alias *data.Field | ||
assetId *data.Field | ||
dataType *data.Field | ||
dataTypeSpec *data.Field | ||
propertyId *data.Field | ||
timeSeriesArn *data.Field | ||
timeSeriesId *data.Field | ||
timeSeriesCreationDate *data.Field | ||
timeSeriesLastUpdateDate *data.Field | ||
} | ||
|
||
func (f *timeSeriesSummaryFields) fields() data.Fields { | ||
return data.Fields{ | ||
f.alias, | ||
f.assetId, | ||
f.dataType, | ||
f.dataTypeSpec, | ||
f.propertyId, | ||
f.timeSeriesArn, | ||
f.timeSeriesId, | ||
f.timeSeriesCreationDate, | ||
f.timeSeriesLastUpdateDate, | ||
} | ||
} | ||
|
||
func newTimeSeriesSummaryFields(length int) *timeSeriesSummaryFields { | ||
return &timeSeriesSummaryFields{ | ||
alias: fields.AliasField(length), | ||
assetId: fields.AssetIdField(length), | ||
dataType: fields.DataTypeField(length), | ||
dataTypeSpec: fields.DataTypeSpecField(length), | ||
propertyId: fields.PropertyIdField(length), | ||
timeSeriesArn: fields.TimeSeriesArnField(length), | ||
timeSeriesId: fields.TimeSeriesIdField(length), | ||
timeSeriesCreationDate: fields.TimeSeriesCreationDateField(length), | ||
timeSeriesLastUpdateDate: fields.TimeSeriesLastUpdateDateField(length), | ||
} | ||
} | ||
|
||
func (t TimeSeries) Frames(_ context.Context, _ resource.ResourceProvider) (data.Frames, error) { | ||
|
||
length := len(t.TimeSeriesSummaries) | ||
|
||
timeSeriesSummaryFields := newTimeSeriesSummaryFields(length) | ||
|
||
for i, timeSeries := range t.TimeSeriesSummaries { | ||
|
||
|
||
if (timeSeries.Alias != nil) { | ||
timeSeriesSummaryFields.alias.Set(i, *timeSeries.Alias) | ||
} | ||
if (timeSeries.AssetId != nil) { | ||
timeSeriesSummaryFields.assetId.Set(i, *timeSeries.AssetId) | ||
} | ||
if (timeSeries.DataType != nil) { | ||
timeSeriesSummaryFields.dataType.Set(i, *timeSeries.DataType) | ||
} | ||
if (timeSeries.DataTypeSpec != nil) { | ||
timeSeriesSummaryFields.dataTypeSpec.Set(i, *timeSeries.DataTypeSpec) | ||
} | ||
if (timeSeries.PropertyId != nil) { | ||
timeSeriesSummaryFields.propertyId.Set(i, *timeSeries.PropertyId) | ||
} | ||
if (timeSeries.TimeSeriesArn != nil) { | ||
timeSeriesSummaryFields.timeSeriesArn.Set(i, *timeSeries.TimeSeriesArn) | ||
} | ||
if (timeSeries.TimeSeriesId != nil) { | ||
timeSeriesSummaryFields.timeSeriesId.Set(i, *timeSeries.TimeSeriesId) | ||
} | ||
if (timeSeries.TimeSeriesCreationDate != nil) { | ||
timeSeriesSummaryFields.timeSeriesCreationDate.Set(i, *timeSeries.TimeSeriesCreationDate) | ||
} | ||
if (timeSeries.TimeSeriesLastUpdateDate != nil) { | ||
timeSeriesSummaryFields.timeSeriesLastUpdateDate.Set(i, *timeSeries.TimeSeriesLastUpdateDate) | ||
} | ||
} | ||
|
||
frame := data.NewFrame("", timeSeriesSummaryFields.fields()...) | ||
|
||
frame.Meta = &data.FrameMeta{ | ||
Custom: models.SitewiseCustomMeta{ | ||
NextToken: aws.StringValue(t.NextToken), | ||
}, | ||
} | ||
|
||
return data.Frames{frame}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package api | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/iotsitewise" | ||
|
||
"github.com/grafana/iot-sitewise-datasource/pkg/framer" | ||
"github.com/grafana/iot-sitewise-datasource/pkg/models" | ||
"github.com/grafana/iot-sitewise-datasource/pkg/sitewise/client" | ||
"github.com/grafana/iot-sitewise-datasource/pkg/util" | ||
|
||
) | ||
|
||
func ListTimeSeries(ctx context.Context, client client.SitewiseClient, query models.ListTimeSeriesQuery) (*framer.TimeSeries, error) { | ||
|
||
var ( | ||
timeSeriesType *string | ||
assetId *string = util.GetAssetId(query.BaseQuery) | ||
aliasPrefix *string | ||
) | ||
|
||
if query.TimeSeriesType != "" { | ||
// if user wants to see all timeseries data do not filter on type | ||
if query.TimeSeriesType == "ALL" { | ||
timeSeriesType = nil | ||
} else { | ||
timeSeriesType = aws.String(query.TimeSeriesType) | ||
} | ||
} | ||
|
||
if query.AliasPrefix != "" { | ||
aliasPrefix = aws.String(query.AliasPrefix) | ||
} | ||
|
||
if query.TimeSeriesType == "DISASSOCIATED" { | ||
// cannot filter on assetId for disassociated data | ||
assetId = nil | ||
} | ||
|
||
if query.TimeSeriesType == "ASSOCIATED" { | ||
// cannot filter by alias prefix on associated data | ||
aliasPrefix = nil | ||
} | ||
|
||
resp, err := client.ListTimeSeriesWithContext(ctx, &iotsitewise.ListTimeSeriesInput{ | ||
AssetId: assetId, | ||
TimeSeriesType: timeSeriesType, | ||
AliasPrefix: aliasPrefix, | ||
MaxResults: aws.Int64(250), | ||
NextToken: getNextToken(query.BaseQuery), | ||
}) | ||
|
||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &framer.TimeSeries{ | ||
TimeSeriesSummaries: resp.TimeSeriesSummaries, | ||
NextToken: resp.NextToken, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.