telefonicaid / iotagent-ul

IoT Agent for a UltraLight 2.0 based protocol (with HTTP, MQTT and AMQP transports)
https://fiware-iotagent-ul.rtfd.io/
GNU Affero General Public License v3.0
37 stars 55 forks source link

Static type config ignored #581

Closed c0c0n3 closed 1 year ago

c0c0n3 commented 1 year ago

Hello, I'm trying to configure UL Agent (Docker image: fiware/iotagent-ul:1.24.0) w/ static types but it looks like the agent isn't able to pick up my config. Possibly something I got wrong, not sure this is a bug actually.

I start the agent with the config below

let config = {};

config.http = {
    port: 7896
};
config.iota = {
    server: {
        port: 4041
    },
    logLevel: 'DEBUG',
    service: 'kitt4sme',
    subservice: '/',

    contextBroker: {
        host: 'orion',
        port: '1026',
        ngsiVersion: 'v2',
        fallbackTenant: 'kitt4sme',
        fallbackPath: '/'
    },
    providerUrl: 'http://ulagent:4041',

    deviceRegistry: {
        type: 'memory'
    },
    mongodb: {},
    deviceRegistrationDuration: 'P100Y',

    defaultResource: '/iot/d',
    defaultType: 'Thing',
    timestamp: true,
    explicitAttrs: false,
    autocast: true,
    types: {
        Greeting: {
            apikey: 'g',
            type: 'Greeting',
            service: 'greeting',
            subservice: '/',
            active: [
                { "object_id": "m", "name": "message", "type": "Text" }
            ]
        }
    }
};

module.exports = config;

Then I try sending some data

$ curl -v -X POST \
  'http://192.168.64.20:7896/iot/d?k=g&i=greet001' \
  -H 'Content-Type: text/plain' \
  -d 'm|howzit!'

But I get back this error message

{"name":"DEVICE_GROUP_NOT_FOUND","message":"Couldn\t find device group for fields: \"/iot/d\" and values: \"g\""}

The log file says

time=2022-11-06T11:22:30.637Z | lvl=DEBUG | corr=2a329358-7980-4248-81fc-c81bd83919e3 | trans=2a329358-7980-4248-81fc-c81bd83919e3 | op=IOTAUL.HTTP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=Parsing payload [m|howzit!] | comp=IoTAgent
time=2022-11-06T11:22:30.638Z | lvl=DEBUG | corr=2a329358-7980-4248-81fc-c81bd83919e3 | trans=2a329358-7980-4248-81fc-c81bd83919e3 | op=IOTAUL.HTTP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=Parsed data: [[{"m":"howzit!"}]] | comp=IoTAgent
time=2022-11-06T11:22:30.639Z | lvl=DEBUG | corr=2a329358-7980-4248-81fc-c81bd83919e3 | trans=2a329358-7980-4248-81fc-c81bd83919e3 | op=IOTAUL.HTTP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=Processing multiple HTTP measures for device [greet001] with apiKey ["g"] | comp=IoTAgent
time=2022-11-06T11:22:30.641Z | lvl=DEBUG | corr=2a329358-7980-4248-81fc-c81bd83919e3 | trans=2a329358-7980-4248-81fc-c81bd83919e3 | op=IOTAUL.HTTP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=Error [DEVICE_GROUP_NOT_FOUND] handing request: Couldn   find device group for fields: "/iot/d" and values: "g" | comp=IoTAgent

Any idea what's going on? Any help would be greatly appreciated!!

c0c0n3 commented 1 year ago

I came across this:

and in fact I had the exact same issue when provisioning devices through HTTP calls, but I don't think it's actually related to my issue with static types?

fgalan commented 1 year ago

The capability of specifying groups statically by configuration along with memory device registry is no longer supported. They both were used in the early days when IOTA development started, but at the present moment we don't use or support them.

Having said that, if you are still interested in it, we will be more than happy to review contributions to fix/improve this in the form of PRs. You can have a look to this testing PR if you want and continue work based on it: PR https://github.com/telefonicaid/iotagent-node-lib/pull/1299.

c0c0n3 commented 1 year ago

hi @fgalan :-)

The capability of specifying groups statically by configuration along with memory device registry is no longer supported.

Oh deary, deary :-) I worked on a couple of deployments where I was hoping to use this feature since it's documented in the manual---https://iotagent-node-lib.readthedocs.io/en/latest/api.html#type-configuration. Maybe that section should be removed from the docs?

you can have a look to this testing PR if you want and continue work based on it

Cool, thanks for this. I'll have a look. I think static type config would be really useful in GitOps scenarios where you could keep the whole config in git and have a repo monitor (e.g. Argo CD) instantiate a working system from the repo.

fgalan commented 1 year ago

Maybe that section should be removed from the docs?

Yes, we should tell in documentation that memory device registry is deprecated.

In addition, groups statically defined by configuration are also deprecated. In the case of needing them, the MongoDB collection can be statically pre-provisioned with the static configuration.

Document modification to tell about this deprecation will be done in a next PR.

c0c0n3 commented 1 year ago

@fgalan great, thanks for the heads up!

fgalan commented 1 year ago

That PR is this one: https://github.com/telefonicaid/iotagent-node-lib/pull/1318