Azure / azure-iot-sdk-node

A Node.js SDK for connecting devices to Microsoft Azure IoT services
https://docs.microsoft.com/en-us/azure/iot-hub/
Other
262 stars 227 forks source link

Spelling bug in azure-iothub package related to updating Module Twins using iot device configurations #675

Closed DoychinDoychev closed 4 years ago

DoychinDoychev commented 4 years ago

Context

Description of the issue:

There is a spelling mistake in configuration.d.ts file, line 77

export interface ConfigurationContent {
    /**
     * The configuration for all the modules.
     */
--->L:77    modulesContent?: {
        [key: string]: Object;
    };

should read

moduleContent - there is no 's' at the end of the word module

Code sample exhibiting the issue:

this.config.content.modulesContent -> generates bad request this.config.content.moduleContent -> works like a charm notice the missing 's'

Console log of the issue:

Add configuration failed: BadRequest

DoychinDoychev commented 4 years ago

P.S. I need to be shipping a product next week and this is a key blocker :)

anthonyvercolano commented 4 years ago

Sorry for the delay on this. I however need to take a much closer look at this. The pre-release version of this feature did have the property named 'moduleContent', and quite frankly considering that the other property is name 'deviceContent', well.... HOWEVER there is quite a bit of code that says 'modulesContent' including other SDKs that have this as the property name.

I have to try some things before I move forward with this. I have a PR ready to go with the change but I need to do more checking.

anthonyvercolano commented 4 years ago

@DoychinDoychev I've tested the sample edge_deployment_sample.js in the services/samples directory.

It uses the modulesContent property name and runs without failure.

In the preview for this feature the property HAD been named moduleContent. However when it went GA the name was changed to modulesContent.

Right now the only thing I can think of is that somehow the environment that is experiencing a failure has old SDK packages in it. The main reason I suspect that it that by working when you change to the old property name, this would indicate that you are invoking the preview release of the API.

If you can demonstrate this problem repeatedly you might try (assuming a Mac)

export DEBUG="azure*"

You should see a bunch of debug logs when you then invoke your application.

At the point where you invoke addConfiguration you should see a log statement that begins:

  azure-iot-http-base.RestApiClient sending PUT call to /configurations/fake-deployment?api-version=2019-03-30 +0ms
  azure-iot-http-base.RestApiClient with body {"id":"fake-deployment","content":{"modulesContent":{"$edgeAgent":{"properties.desired":{"schemaVersion":"1.0","runtime":{"type":"docker","settings":{"minDockerVersion":"v1.25","loggingOptions":""}},"systemModules":{"edgeAgent":{"type":"docker","settings":{"image":"microsoft/azureiotedge-agent:1.0-preview","createOptions":"{}"}},"edgeHub":{"type"

What is very important is the api-version on the first line. Let us know.

DoychinDoychev commented 4 years ago

Hi @anthonyvercolano and thank you for responding so quickly.

To give you as much information as possible and to illustrate what i did and what i found i've mocked a quick git project that you can find here

https://github.com/DoychinDoychev/azure-iothub-bug

I've outlined what i did, the version of the sdk, screenshots and logs.

I hope this helps and let me know if i can assist in any other way :)

... I just noticed that your module deployment looks different than mine

{"id":"fake-deployment","content":{"modulesContent":{"$edgeAgent":{"properties.desired":{"schemaVersion":"1.0",

I think the data structure you are using is different from what i'm using. You seem to be specifying the target module id as part of the configuration not as part of your target condition.

Thanks

anthonyvercolano commented 4 years ago

Property "moduleContent" has been added.

This has been released to npm.

az-iot-builder-01 commented 4 years ago

@DoychinDoychev, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey