From 83a6c8b8908f76d618fc60795234bbb34ceaccf1 Mon Sep 17 00:00:00 2001 From: ssjagad <145582655+ssjagad@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:43:53 -0700 Subject: [PATCH] fix: add check for nil for property value (#352) --- pkg/framer/property_value.go | 6 +++--- pkg/framer/property_value_batch.go | 2 +- pkg/framer/property_value_history.go | 8 +++++--- pkg/framer/property_value_history_batch.go | 9 +++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/framer/property_value.go b/pkg/framer/property_value.go index ef0ea173..ae438d3b 100644 --- a/pkg/framer/property_value.go +++ b/pkg/framer/property_value.go @@ -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 -} \ No newline at end of file +} diff --git a/pkg/framer/property_value_batch.go b/pkg/framer/property_value_batch.go index 0f2408e2..7f0d12ad 100644 --- a/pkg/framer/property_value_batch.go +++ b/pkg/framer/property_value_batch.go @@ -71,7 +71,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) diff --git a/pkg/framer/property_value_history.go b/pkg/framer/property_value_history.go index 114d87f8..78c5c934 100644 --- a/pkg/framer/property_value_history.go +++ b/pkg/framer/property_value_history.go @@ -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 diff --git a/pkg/framer/property_value_history_batch.go b/pkg/framer/property_value_history_batch.go index 083d39a6..465209ac 100644 --- a/pkg/framer/property_value_history_batch.go +++ b/pkg/framer/property_value_history_batch.go @@ -56,7 +56,6 @@ func (p AssetPropertyValueHistoryBatch) Frames(ctx context.Context, resources re 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("?") { @@ -102,9 +101,11 @@ func (p AssetPropertyValueHistoryBatch) framePropertyValues(property *iotsitewis } 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