Skip to content

Commit

Permalink
Merge branch 'main' into dependabot-sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
idastambuk authored Sep 24, 2024
2 parents 9af016c + f446fe8 commit 4498086
Show file tree
Hide file tree
Showing 39 changed files with 2,001 additions and 139 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# Change Log

All notable changes to this project will be documented in this file.
## 1.25.0

- Fix: batch entries up to the limit specified in the API [#355](https://github.com/grafana/iot-sitewise-datasource/pull/355)

## 1.24.0

- fix: add check for nil for property value [#352](https://github.com/grafana/iot-sitewise-datasource/pull/352)
- Fix golangci-lint errors [#353](https://github.com/grafana/iot-sitewise-datasource/pull/353)
- fix: migrate asset id on the frontend in the query editor [#350](https://github.com/grafana/iot-sitewise-datasource/pull/350)
- Remove "ANY" as a query quality option [#347](https://github.com/grafana/iot-sitewise-datasource/pull/347)
- Chore: Rename datasource file [#344](https://github.com/grafana/iot-sitewise-datasource/pull/344)
- Add precommit hook [#338](https://github.com/grafana/iot-sitewise-datasource/pull/338)
- Remove unused fields from Get property value query editor [#343](https://github.com/grafana/iot-sitewise-datasource/pull/343)
- Remove ANY option for interpolated property quality [#342](https://github.com/grafana/iot-sitewise-datasource/pull/342)


## 1.23.0

Expand Down
4 changes: 3 additions & 1 deletion cspell.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"pkg/**/*_test.go",
"provisioning/**/*.yaml",
"**/testdata/*.json",
"**/testdata/*.jsonc",
"**/dashboards/*.json",
"src/static/**",
"vendor/**",
Expand Down Expand Up @@ -72,6 +73,7 @@
"ssjagad",
"jackspeak",
"nvmrc",
"gomod"
"gomod",
"golangci"
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "grafana-iot-sitewise-datasource",
"version": "1.23.0",
"version": "1.25.0",
"description": "View IoT Sitewise data in grafana",
"scripts": {
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
Expand Down
61 changes: 35 additions & 26 deletions pkg/framer/property_aggregate_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
)

type AssetPropertyAggregatesBatch struct {
Request iotsitewise.BatchGetAssetPropertyAggregatesInput
Response iotsitewise.BatchGetAssetPropertyAggregatesOutput
Requests []iotsitewise.BatchGetAssetPropertyAggregatesInput
Responses []iotsitewise.BatchGetAssetPropertyAggregatesOutput
}

// getAggregationFields enforces ordering of aggregate fields
Expand Down Expand Up @@ -86,40 +86,49 @@ func addAggregateFieldValues(idx int, fields map[string]*data.Field, aggs *iotsi
}

func (a AssetPropertyAggregatesBatch) Frames(ctx context.Context, resources resource.ResourceProvider) (data.Frames, error) {
resp := a.Response
frames := data.Frames{}
successEntriesLength := 0
for _, r := range a.Responses {
successEntriesLength += len(r.SuccessEntries)
}
frames := make(data.Frames, 0, successEntriesLength)

properties, err := resources.Properties(ctx)
if err != nil {
return nil, err
}

for i, e := range resp.SuccessEntries {
property := properties[*e.EntryId]
frame, err := a.Frame(ctx, property, e.AggregatedValues)
if err != nil {
return nil, err
}
frame.Meta = &data.FrameMeta{
Custom: models.SitewiseCustomMeta{
NextToken: aws.StringValue(resp.NextToken),
Resolution: aws.StringValue(a.Request.Entries[i].Resolution),
Aggregates: aws.StringValueSlice(a.Request.Entries[i].AggregateTypes),
},
}
frames = append(frames, frame)
}
for i, r := range a.Responses {
request := a.Requests[i]
for j, e := range r.SuccessEntries {
property := properties[*e.EntryId]
frame, err := a.Frame(ctx, property, e.AggregatedValues)
if err != nil {
return nil, err
}

for _, e := range resp.ErrorEntries {
property := properties[*e.EntryId]
frame := data.NewFrame(getFrameName(property))
if e.ErrorMessage != nil {
frame.Meta = &data.FrameMeta{
Notices: []data.Notice{{Severity: data.NoticeSeverityError, Text: *e.ErrorMessage}},
Custom: models.SitewiseCustomMeta{
NextToken: aws.StringValue(r.NextToken),
EntryId: *e.EntryId,
Resolution: aws.StringValue(request.Entries[j].Resolution),
Aggregates: aws.StringValueSlice(request.Entries[j].AggregateTypes),
},
}
frames = append(frames, frame)
}

for _, e := range r.ErrorEntries {
property := properties[*e.EntryId]
frame := data.NewFrame(getFrameName(property))
if e.ErrorMessage != nil {
frame.Meta = &data.FrameMeta{
Notices: []data.Notice{{Severity: data.NoticeSeverityError, Text: *e.ErrorMessage}},
}
}
frames = append(frames, frame)
}
frames = append(frames, frame)
}

return frames, nil
}

Expand Down Expand Up @@ -152,4 +161,4 @@ func (a AssetPropertyAggregatesBatch) Frame(ctx context.Context, property *iotsi

return frame, nil

}
}
6 changes: 3 additions & 3 deletions pkg/framer/property_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func (p AssetPropertyValue) Frames(ctx context.Context, resources resource.Resou
valueField := fields.PropertyValueField(property, length)
qualityField := fields.QualityField(length)

frame := data.NewFrame(getFrameName(property), timeField, valueField, qualityField)
frame := data.NewFrame(getFrameName(property), timeField, valueField, qualityField)

if p.PropertyValue != nil {
if p.PropertyValue != nil && getPropertyVariantValue(p.PropertyValue.Value) != nil {
timeField.Set(0, getTime(p.PropertyValue.Timestamp))
valueField.Set(0, getPropertyVariantValue(p.PropertyValue.Value))
qualityField.Set(0, *p.PropertyValue.Quality)
}

return data.Frames{frame}, nil
}
}
61 changes: 36 additions & 25 deletions pkg/framer/property_value_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,58 @@ import (
)

type AssetPropertyValueBatch struct {
*iotsitewise.BatchGetAssetPropertyValueOutput
Responses []*iotsitewise.BatchGetAssetPropertyValueOutput
AnomalyAssetIds []string
SitewiseClient client.SitewiseClient
}

func (p AssetPropertyValueBatch) Frames(ctx context.Context, resources resource.ResourceProvider) (data.Frames, error) {
frames := data.Frames{}
successEntriesLength := 0
for _, r := range p.Responses {
successEntriesLength += len(r.SuccessEntries)
}
frames := make(data.Frames, 0, successEntriesLength)

properties, err := resources.Properties(ctx)
if err != nil {
return nil, err
}

for _, e := range p.SuccessEntries {
property := properties[*e.EntryId]
if util.IsAssetProperty(property) && *property.AssetProperty.DataType == *aws.String("?") && e.AssetPropertyValue != nil {
property.AssetProperty.DataType = aws.String(getPropertyVariantValueType(e.AssetPropertyValue.Value))
}
for _, r := range p.Responses {
for _, e := range r.SuccessEntries {
property := properties[*e.EntryId]
if util.IsAssetProperty(property) && *property.AssetProperty.DataType == *aws.String("?") && e.AssetPropertyValue != nil {
property.AssetProperty.DataType = aws.String(getPropertyVariantValueType(e.AssetPropertyValue.Value))
}

var frame *data.Frame
if property.AssetId != nil && slices.Contains(p.AnomalyAssetIds, *property.AssetId) {
frame, err = p.frameL4ePropertyValue(ctx, property, e.AssetPropertyValue)
if err != nil {
return nil, err
var frame *data.Frame
if property.AssetId != nil && slices.Contains(p.AnomalyAssetIds, *property.AssetId) {
frame, err = p.frameL4ePropertyValue(ctx, property, e.AssetPropertyValue)
if err != nil {
return nil, err
}
} else {
frame = p.framePropertyValue(property, e.AssetPropertyValue)
}
frame.Meta = &data.FrameMeta{
Custom: models.SitewiseCustomMeta{
NextToken: aws.StringValue(r.NextToken),
EntryId: *e.EntryId,
},
}
} else {
frame = p.framePropertyValue(property, e.AssetPropertyValue)
frames = append(frames, frame)
}

frames = append(frames, frame)
}

for _, e := range p.ErrorEntries {
property := properties[*e.EntryId]
frame := data.NewFrame(*property.AssetName)
if e.ErrorMessage != nil {
frame.Meta = &data.FrameMeta{
Notices: []data.Notice{{Severity: data.NoticeSeverityError, Text: *e.ErrorMessage}},
for _, e := range r.ErrorEntries {
property := properties[*e.EntryId]
frame := data.NewFrame(*property.AssetName)
if e.ErrorMessage != nil {
frame.Meta = &data.FrameMeta{
Notices: []data.Notice{{Severity: data.NoticeSeverityError, Text: *e.ErrorMessage}},
}
}
frames = append(frames, frame)
}
frames = append(frames, frame)
}

return frames, nil
Expand All @@ -71,7 +82,7 @@ func (AssetPropertyValueBatch) framePropertyValue(property *iotsitewise.Describe

frame := data.NewFrame(*property.AssetName, timeField, valueField, qualityField)

if assetPropertyValue != nil {
if assetPropertyValue != nil && getPropertyVariantValue(assetPropertyValue.Value) != nil {
timeField.Append(getTime(assetPropertyValue.Timestamp))
valueField.Append(getPropertyVariantValue(assetPropertyValue.Value))
qualityField.Append(*assetPropertyValue.Quality)
Expand Down
8 changes: 5 additions & 3 deletions pkg/framer/property_value_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func (p AssetPropertyValueHistory) Frames(ctx context.Context, resources resourc
}

for i, v := range p.AssetPropertyValueHistory {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
if v.Value != nil && getPropertyVariantValue(v.Value) != nil {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
}
}

return data.Frames{frame}, nil
Expand Down
71 changes: 36 additions & 35 deletions pkg/framer/property_value_history_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,59 @@ import (
)

type AssetPropertyValueHistoryBatch struct {
*iotsitewise.BatchGetAssetPropertyValueHistoryOutput
Responses []*iotsitewise.BatchGetAssetPropertyValueHistoryOutput
Query models.AssetPropertyValueQuery
AnomalyAssetIds []string
SitewiseClient client.SitewiseClient
}

func (p AssetPropertyValueHistoryBatch) Frames(ctx context.Context, resources resource.ResourceProvider) (data.Frames, error) {
frames := make(data.Frames, 0, len(p.SuccessEntries))
successEntriesLength := 0
for _, r := range p.Responses {
successEntriesLength += len(r.SuccessEntries)
}
frames := make(data.Frames, 0, successEntriesLength)

properties, err := resources.Properties(ctx)
if err != nil {
return frames, err
}

for _, h := range p.SuccessEntries {
frame, err := p.Frame(ctx, properties[*h.EntryId], h.AssetPropertyValueHistory)
if err != nil {
return nil, err
}
if frame != nil {
frames = append(frames, frame)
for _, r := range p.Responses {
for _, s := range r.SuccessEntries {
frame, err := p.Frame(ctx, properties[*s.EntryId], s.AssetPropertyValueHistory)
frame.Meta = &data.FrameMeta{
Custom: models.SitewiseCustomMeta{
NextToken: aws.StringValue(r.NextToken),
EntryId: *s.EntryId,
Resolution: models.PropertyQueryResolutionRaw,
},
}
if err != nil {
return nil, err
}
if frame != nil {
frames = append(frames, frame)
}
}
}

for _, e := range p.ErrorEntries {
property := properties[*e.EntryId]
frame := data.NewFrame(getFrameName(property))
if e.ErrorMessage != nil {
frame.Meta = &data.FrameMeta{
Notices: []data.Notice{{Severity: data.NoticeSeverityError, Text: *e.ErrorMessage}},
for _, e := range r.ErrorEntries {
property := properties[*e.EntryId]
frame := data.NewFrame(getFrameName(property))
if e.ErrorMessage != nil {
frame.Meta = &data.FrameMeta{
Notices: []data.Notice{{Severity: data.NoticeSeverityError, Text: *e.ErrorMessage}},
}
}
frames = append(frames, frame)
}
frames = append(frames, frame)
}

return frames, nil
}

func (p AssetPropertyValueHistoryBatch) Frame(ctx context.Context, property *iotsitewise.DescribeAssetPropertyOutput, h []*iotsitewise.AssetPropertyValue) (*data.Frame, error) {
length := len(h)

// TODO: make this work with the API instead of ad-hoc dataType inference
// https://github.com/grafana/iot-sitewise-datasource/issues/98#issuecomment-892947756
if util.IsAssetProperty(property) && *property.AssetProperty.DataType == *aws.String("?") {
Expand Down Expand Up @@ -94,17 +107,12 @@ func (p AssetPropertyValueHistoryBatch) framePropertyValues(property *iotsitewis
valueField,
qualityField)

frame.Meta = &data.FrameMeta{
Custom: models.SitewiseCustomMeta{
NextToken: aws.StringValue(p.NextToken),
Resolution: models.PropertyQueryResolutionRaw,
},
}

for i, v := range h {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
if v.Value != nil && getPropertyVariantValue(v.Value) != nil {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
}
}

return frame, nil
Expand All @@ -128,13 +136,6 @@ func (p AssetPropertyValueHistoryBatch) frameL4ePropertyValues(ctx context.Conte
frameName,
dataFields...)

frame.Meta = &data.FrameMeta{
Custom: models.SitewiseCustomMeta{
NextToken: aws.StringValue(p.NextToken),
Resolution: models.PropertyQueryResolutionRaw,
},
}

return frame, nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/models/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type AWSSiteWiseDataSourceSetting struct {
}

func (s *AWSSiteWiseDataSourceSetting) Load(config backend.DataSourceInstanceSettings) error {
if config.JSONData != nil && len(config.JSONData) > 1 {
if len(config.JSONData) > 1 {
if err := json.Unmarshal(config.JSONData, s); err != nil {
return fmt.Errorf("could not unmarshal DatasourceSettings json: %w", err)
}
Expand Down
Loading

0 comments on commit 4498086

Please sign in to comment.