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: Optimize findMatchingFunction #1071

Merged
merged 2 commits into from
Apr 6, 2022

Conversation

FelixTing
Copy link
Member

@FelixTing FelixTing commented Apr 1, 2022

Sometimes the name of a newly added configurable pipeline function may start with one of the existing function names. For example, user is unaware of the existence of AddTags, implements function AddTagsFromDeviceResource and uses it in App Service configuration. In this case, sdk will resolve it as the function AddTags.

To make the result more accurate, the findMatchingFunction should try to find if there is a function with name identical to the target configuration function first. If no match, then iterate over all the functions to see if the target configuration function name starts with actual function name. If there are multiple matches then pick the one with the longest name.

Signed-off-by: Felix Ting [email protected]

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/app-functions-sdk-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?) Requires integration tests
  • 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?) no docs change

Testing Instructions

Clone app-functions-sdk and modify /internal/app/configurable.go:

  1. Add the following to the end of the built-in AddTags function
    app.lc.Info("I am AddTags")

  2. Add the following two functions

func (app *Configurable) AddTagsFromDeviceResource(parameters map[string]string) interfaces.AppFunction {
	app.lc.Info("I am AddTagsFromDeviceResource")
    return func(appCxt interfaces.AppFunctionContext, data interface{}) (bool, interface{}) { return true, data }
}
func (app *Configurable) AddTagsFromDevice(parameters map[string]string) interfaces.AppFunction {
	app.lc.Info("I am AddTagsFromDevice")
    return func(appCxt interfaces.AppFunctionContext, data interface{}) (bool, interface{}) { return true, data }
}
  1. Run core services using EdgeX Docker Compose

  2. Clone app-service-configurable
    Modify go.mod to replace the app-functions-sdk dependency with the local app-functions-sdk

  3. Run app-service-configurable with the following pipeline configuration

  [Writable.Pipeline]
  ExecutionOrder = "AddTags, AddTagsFromDevice, AddTagsFromDeviceResource2"

  [Writable.Pipeline.Functions]
    [Writable.Pipeline.Functions.AddTags]
      [Writable.Pipeline.Functions.AddTags.Parameters]
      Tags=""
    [Writable.Pipeline.Functions.AddTagsFromDevice]
      [Writable.Pipeline.Functions.AddTagsFromDevice.Parameters]
      Param=""
    [Writable.Pipeline.Functions.AddTagsFromDeviceResource2]
      [Writable.Pipeline.Functions.AddTagsFromDeviceResource2.Parameters]
      Param=""

Verify logs contain following messages

level=INFO ts=2022-03-31T15:09:49.75482Z app=app- source=main.go:38 msg="Loading Configurable Pipeline..."
level=INFO ts=2022-03-31T15:09:49.754875Z app=app- source=configurable.go:605 msg="I am AddTags"
level=INFO ts=2022-03-31T15:09:49.754892Z app=app- source=configurable.go:762 msg="I am AddTagsFromDevice"
level=INFO ts=2022-03-31T15:09:49.754912Z app=app- source=configurable.go:756 msg="I am AddTagsFromDeviceResource"

New Dependency Instructions (If applicable)

Sometimes the name of a newly added configurable pipeline function may start with one of the existing function names. For example, user is unaware of the existence of AddTags, implements function AddTagsFromDeviceResource and uses it in App Service configuration. In this case, sdk will resolve it as the function AddTags.
To make the result more accurate, the findMatchingFunction should try to find if there is a function with name identical to the target configuration function first. If no match, then iterate over all the functions to see if the target configuration function name starts with actual function name. If there are multiple matches then pick the one with the longest name.

Signed-off-by: Felix Ting <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Apr 1, 2022

Codecov Report

Merging #1071 (171602f) into main (7cb97b0) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1071      +/-   ##
==========================================
+ Coverage   68.76%   68.79%   +0.02%     
==========================================
  Files          36       36              
  Lines        2917     2919       +2     
==========================================
+ Hits         2006     2008       +2     
  Misses        798      798              
  Partials      113      113              
Impacted Files Coverage Δ
internal/app/configupdates.go 17.07% <100.00%> (+2.07%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7cb97b0...171602f. Read the comment docs.

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 lenny-goodell merged commit 5f18f9a into edgexfoundry:main Apr 6, 2022
@FelixTing FelixTing deleted the issue-1070 branch April 7, 2022 03:13
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.

Optimize findMatchingFunction to make it more accurate
3 participants