Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metadata): implement Unit of Measure (UoM) ADR #4119

Merged
merged 2 commits into from
Aug 12, 2022
Merged

feat(metadata): implement Unit of Measure (UoM) ADR #4119

merged 2 commits into from
Aug 12, 2022

Conversation

chr1shung
Copy link

@chr1shung chr1shung commented Aug 8, 2022

Signed-off-by: Chris Hung chris@iotechsys.com

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?)
    feat: document core metadata units of measure capability edgex-docs#834

Testing Instructions

  1. Run metadata from this branch with WRITABLE_UOM_VALIDATION: "true"
  2. add/update device porfile and compare the result with res/uom.toml

Also,
I updated the sample uom TOML in ADR from

[Uom]
    Source="reference to source for all UoM if not specified below"
    [Uom.temperature]
    Source="www.weather.com"
    Values="C,F,K"
    [Uom.weights]
    Source="www.usa.gov/federal-agencies/weights-and-measures-division"
    Values="lbs,ounces,kilos,grams"

to

[Uom]
Source="reference to source for all UoM if not specified below"
  [Uom.Units]
    [Uom.Units.temperature]
    Source="www.weather.com"
    Values=["C","F","K"]
    [Uom.Units.weights]
    Source="www.usa.gov/federal-agencies/weights-and-measures-division"
    Values=["lbs","ounces","kilos","grams"]

so that it can be correctly unmarshaled

New Dependency Instructions (If applicable)

@cloudxxx8
Copy link
Member

@hahattan we merged a PR which should resolved the snap test issue. please rebase it.

Comment on lines 62 to 61
if container.ConfigurationFrom(dic.Get).Writable.UoM.Validation {
uom := container.UnitsOfMeasureFrom(dic.Get)
for _, dr := range d.DeviceResources {
if ok := uom.Validate(dr.Properties.Units); !ok {
return errors.NewCommonEdgeX(errors.KindServerError, fmt.Sprintf("DeviceResource %s units %s is invalid", dr.Name, dr.Properties.Units), nil)
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create helper function to reduce duplicated code

internal/core/metadata/uom/bootstrap.go Show resolved Hide resolved
snap/snapcraft.yaml Show resolved Hide resolved
Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hahattan , please complete PR check list with link to PR for the Doc updates for this new capability. THX!

internal/core/metadata/application/deviceprofile.go Outdated Show resolved Hide resolved
internal/core/metadata/uom/bootstrap.go Outdated Show resolved Hide resolved
internal/core/metadata/uom/uom.go Show resolved Hide resolved
snap/snapcraft.yaml Show resolved Hide resolved
Signed-off-by: Chris Hung <chris@iotechsys.com>
lenny-goodell
lenny-goodell previously approved these changes Aug 11, 2022
Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lenny-goodell
Copy link
Member

@hahattan , FYI I have escalated the snap testing failure to @farshidtz

@chr1shung
Copy link
Author

document PR updated: edgexfoundry/edgex-docs#834

cloudxxx8
cloudxxx8 previously approved these changes Aug 12, 2022
Copy link
Member

@cloudxxx8 cloudxxx8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

"core-metadata")
install -DT "./cmd/core-metadata/res/configuration.toml" "$SNAPCRAFT_PART_INSTALL/config/core-metadata/res/configuration.toml"
install -DT "./cmd/core-metadata/res/uom.toml" "$SNAPCRAFT_PART_INSTALL/config/core-metadata/res/uom.toml"
;;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good as it copies also uom.toml to the snap package (readonly, SNAP env var). But we also need to add code to copy it over to the snap's writable area (SNAP_DATA env var) on install time. The given path UOM_UOMFILE: $SNAP_DATA/config/core-metadata/res/uom.toml expects it to be under the writable area.

Currently only configuration.toml files get copied:

destDir := hooks.SnapDataConf + "/"
srcDir := hooks.SnapConf + "/"
// handle exceptions (i.e. config in non-std dirs)
if v == "security-bootstrap-redis" {
destDir = destDir + "security-bootstrapper/res-bootstrap-redis"
srcDir = srcDir + "security-bootstrapper/res-bootstrap-redis"
} else if v == "app-service-configurable" {
destDir = destDir + v + "/res/rules-engine"
srcDir = srcDir + "/res/rules-engine"
} else {
destDir = destDir + v + "/res"
srcDir = srcDir + v + "/res"
}
if err = os.MkdirAll(destDir, 0755); err != nil {
return err
}
srcPath := srcDir + "/configuration.toml"
destPath := destDir + "/configuration.toml"
err = hooks.CopyFile(srcPath, destPath)
if err != nil {
return err
}

This is really an unnecessary complication in how the snap is packaged. Maybe we should refactor and simply copy the whole res directory.

For now, a quick fix would be to update the referenced code to copy uom.toml from SNAP to SNAP_DATA for core-metadata. I'll work on it and commit to the same PR (since the permission has been granted by the author during PR submission.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I was wondering why I couldn't push. I was testing locally so it took some time.

You force-pushed so it isn't clear what exactly you changed. But the install.go part looks good.

Signed-off-by: Chris Hung <chris@iotechsys.com>
@chr1shung chr1shung dismissed stale reviews from cloudxxx8 and lenny-goodell via 3aaec56 August 12, 2022 09:32
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@cloudxxx8 cloudxxx8 merged commit 03487ec into edgexfoundry:main Aug 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants