edgexfoundry / device-sdk-go

Owner: Device WG

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Events which created by AutoEvent contains the reading didn't set on device AutoEvent

cherrycl opened this issue Β· comments

🐞 Bug Report

Affected Services [REQUIRED]

The issue is located in: device-service

Is this a regression?

Yes

Description and Minimal Reproduction [REQUIRED]

  1. Deploy EdgeX with compose file
  2. Verify the events of Random-UnsignedInteger-Device which pushing by auto event
GET  localhost:59880/api/v2/event/device/name/Random-UnsignedInteger-Device

{
    "apiVersion": "v2",
    "statusCode": 200,
    "totalCount": 28,
    "events": [
        {
            "apiVersion": "v2",
            "id": "8f8f2746-d892-408e-8eff-42546b9a10a8",
            "deviceName": "Random-UnsignedInteger-Device",
            "profileName": "Random-UnsignedInteger-Device",
            "sourceName": "Uint16",
            "origin": 1681191249346359994,
            "readings": [
                {
                    "id": "d5c3b949-8778-4436-a15b-320827a2cfc0",
                    "origin": 1681191249346359994,
                    "deviceName": "Random-UnsignedInteger-Device",
                    "resourceName": "Uint16Array",
                    "profileName": "Random-UnsignedInteger-Device",
                    "valueType": "Uint16Array",
                    "value": "[24214, 10860, 9406, 54914, 7435]"
                },
                {
                    "id": "308af7f6-0a3d-4d9e-8cff-20ce698db4b9",
                    "origin": 1681191249346359994,
                    "deviceName": "Random-UnsignedInteger-Device",
                    "resourceName": "Uint16",
                    "profileName": "Random-UnsignedInteger-Device",
                    "valueType": "Uint16",
                    "value": "39176"
                }
            ]
        },
...
}

πŸ”₯ Exception or Error

Default auto event setting didn't contain resource Uint16Array, but got the Uint16Array reading in the event

🌍 Your Environment

Deployment Environment: Ubuntu22 / x86

EdgeX Version [REQUIRED]: Main

Anything else relevant?

The reason is that SDK allows regex autoevent source name and regexp.MatchString("Uint16", "Uint16Array") returns true.

var res []models.DeviceResource
for _, dr := range drs {
match, _ := regexp.MatchString(regex, dr.Name)
if match {
res = append(res, dr)
}
}
return res, true

We can update autoevent source name to ^Uint16$ to avoid this or update SDK code to handle this situation (I haven't come up with any good idea though)

we have to update sdk code to handle this situation.
@lenny-intel @iain-anderson @jpwhitemn we enable regexp by default, but here is the side effect.
should we disable regexp by default and allow users to enable it when they need?

Even if I had enabled regexp I would not expect "UInt16" to expand to "UInt16Array"
Use CompilePOSIX and FindString and check that the string found is the entire resource name?