me-box / databox

Databox container manager and dashboard server
MIT License
94 stars 25 forks source link

issue with lib-node-databox and zest on pi #320

Open tlodge opened 5 years ago

tlodge commented 5 years ago

Having an issue writing a simple app to listen on osmonitor (on raspberry pi). Relevant code as follows:

const hcatobj = JSON.parse(process.env[`DATASOURCE_${n.id}`]);
const monitorStream = databox.HypercatToSourceDataMetadata(hcatobj);
const store = databox.NewStoreClient(hcatobj.href, process.env['DATABOX_ARBITER_ENDPOINT'], true);

store.TSBlob.Observe(monitorStream.DataSourceID).then((emitter) => {

      console.log("now have emitter!");
      this.emitter = emitter;
      emitter.on('data', cb);

      emitter.on('error', (err) => {
                console.warn(err);
      });
}).catch((err) => {
  console.warn("Error", monitorStream.DataSourceID, " ", err);
});

And get the following error:

[Node ZestClient ]  { oc: 5,

code: 1,
tkl: 236,
token: 'alongtokenstring',
options:
[ { number: 11, len: 16, value: '/ts/blob/freemem' },
{ number: 3, len: 14, value: 'tlodge-monitor' },
{ number: 6, len: 0, value: '' },
{ number: 12, len: 2, value: 50 },
{ number: 14, len: 4, value: 0 } ],
payload: '' }

[Node ZestClient ]  { oc: 5,
 code: 1,
 tkl: 236,
token: 'alongtokenstring',
options:
[ { number: 11, len: 16, value: '/ts/blob/freemem' },
{ number: 3, len: 14, value: 'tlodge-monitor' },
{ number: 6, len: 0, value: '' },
{ number: 12, len: 2, value: 50 },
{ number: 14, len: 4, value: 0 } ],
payload: '' }

[Node ZestClient ]  { number: 11, len: 16, value: '/ts/blob/freemem' }
[Node ZestClient ]  { number: 3, len: 14, value: 'tlodge-monitor' }
[Node ZestClient ]  { number: 6, len: 0, value: '' }
[Node ZestClient ]  { number: 12, len: 2, value: 50 }
[Node ZestClient ]  { number: 14, len: 4, value: 0 }
(node:29) UnhandledPromiseRejectionWarning: Error: Invalid argument
|     at exports.Socket.Socket.connect (/home/databox/data/nodes/databox/node_modules/zeromq/lib/index.js:510:13)
at openRouterSocket (/home/databox/data/nodes/databox/node_modules/node-databox/lib/zest.js:18:13)
at Promise (/home/databox/data/nodes/databox/node_modules/node-databox/lib/zest.js:193:29)
at new Promise (<anonymous>)
at sendRequestAndAwaitResponse (/home/databox/data/nodes/databox/node_modules/node-databox/lib/zest.js:192:16)
at Object.Observe (/home/databox/data/nodes/databox/node_modules/node-databox/lib/zest.js:108:30)
at _observe (/home/databox/data/nodes/databox/node_modules/node-databox/main.js:368:47)
 at <anonymous>

(node:29) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)

(node:29) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Toshbrown commented 5 years ago

Do you see the same issue on x86?

tlodge commented 5 years ago

Haven't tried, as built all images for pi only through updated sdk which runs off the pi.

On Fri, Jul 5, 2019 at 10:25 AM toshbrown notifications@github.com wrote:

Do you see the same issue on x86?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/me-box/databox/issues/320?email_source=notifications&email_token=AAA63ZYUFLF3I6WJYG6ATC3P54HR5A5CNFSM4H6JMFMKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZJBFFA#issuecomment-508695188, or mute the thread https://github.com/notifications/unsubscribe-auth/AAA63Z242AIMWUD37K4JSELP54HR5ANCNFSM4H6JMFMA .

tlodge commented 5 years ago

Tried simple (updated) version of node/app driver from databox quickstart - driver works fine, but app fails with issue above on pi and nuc.

    const hcatobj = JSON.parse(process.env[`DATASOURCE_helloWorldActuator`]);
    console.log("hcatobj", JSON.stringify(hcatobj,null, 4));

    //listen in on the helloWorld Actuator, which we have asked permissions for in the manifest
    const metadata = databox.HypercatToSourceDataMetadata(hcatobj);
    console.log("metadata", JSON.stringify(metadata,null,4));

    store = databox.NewStoreClient(hcatobj.href, DATABOX_ARBITER_ENDPOINT, true);

    store.TS.Observe(metadata.DataSourceID).then((emitter) => {
        listenToActuator(emitter);
    }).catch((err) => {
        console.warn("Error Observing helloWorldActuator", err);
    });
cgreenhalgh commented 5 years ago

I think this may be addressed by me-box/lib-node-databox#46 and i think it may be due to using the href directly rather than stripping off the path and just using the host and port url (use utility GetStoreURLFromHypercat)

tlodge commented 5 years ago

I've updated my code to new lib-node-databox (0.10.8), and now use GetSToreURLFromHypercat to pull out store url:

const hcatobj = JSON.parse(process.env[`DATASOURCE_helloWorldActuator`]);

//listen in on the helloWorld Actuator, which we have asked permissions for in the manifest
const metadata = databox.HypercatToDataSourceMetadata(hcatobj);
const storeurl = databox.GetStoreURLFromHypercat(hcatobj);
console.log("have store url", storeurl);
store = databox.NewStoreClient(storeurl, DATABOX_ARBITER_ENDPOINT, true);

store.TS.Observe(metadata.DataSourceID).then((emitter) => {
    listenToActuator(emitter);
}).catch((err) => {
    console.warn("Error Observing helloWorldActuator", err);
});

and where I set up the server:

console.log("[Creating https server]", PORT);
const credentials = databox.GetHttpsCredentials();
server = https.createServer(credentials, app).listen(PORT);
console.log("server listening...");

When I install and try to view, I get:

Get https://app-helloworld-node:8080/ui: dial tcp 10.0.0.239:8080: i/o timeout

Logs of the app are:

app-helloworld-node.1.k6v2et8uxsjb@databox | have store url tcp://driver-helloworld-node-core-store:5555 app-helloworld-node.1.k6v2et8uxsjb@databox | [Creating https server] 8080 app-helloworld-node.1.k6v2et8uxsjb@databox | server listening... app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { oc: 5, app-helloworld-node.1.k6v2et8uxsjb@databox | code: 1, app-helloworld-node.1.k6v2et8uxsjb@databox | tkl: 252, app-helloworld-node.1.k6v2et8uxsjb@databox | token: 'MDAwZWxvY2F0aW9uIAowMDEwaWRlbnRpZmllciAKMDAyNmNpZCBwYXRoID0gL3RzL2hlbGxvV29ybGRBY3R1YXRvcgowMDE1Y2lkIG1ldGhvZCA9IEdFVAowMDMzY2lkIHRhcmdldCA9IGRyaXZlci1oZWxsb3dvcmxkLW5vZGUtY29yZS1zdG9yZQowMDJmc2lnbmF0dXJlIC4cScjFmth8KqnApDCqRJ4n5U2_G15EhP_LV3HVPLFnCg==', app-helloworld-node.1.k6v2et8uxsjb@databox | options: app-helloworld-node.1.k6v2et8uxsjb@databox | [ { number: 11, len: 22, value: '/ts/helloWorldActuator' }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 3, len: 19, value: 'app-helloworld-node' }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 6, len: 0, value: '' }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 12, len: 2, value: 50 }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 14, len: 4, value: 0 } ], app-helloworld-node.1.k6v2et8uxsjb@databox | payload: '' } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { oc: 5, app-helloworld-node.1.k6v2et8uxsjb@databox | code: 1, app-helloworld-node.1.k6v2et8uxsjb@databox | tkl: 252, app-helloworld-node.1.k6v2et8uxsjb@databox | token: 'MDAwZWxvY2F0aW9uIAowMDEwaWRlbnRpZmllciAKMDAyNmNpZCBwYXRoID0gL3RzL2hlbGxvV29ybGRBY3R1YXRvcgowMDE1Y2lkIG1ldGhvZCA9IEdFVAowMDMzY2lkIHRhcmdldCA9IGRyaXZlci1oZWxsb3dvcmxkLW5vZGUtY29yZS1zdG9yZQowMDJmc2lnbmF0dXJlIC4cScjFmth8KqnApDCqRJ4n5U2_G15EhP_LV3HVPLFnCg==', app-helloworld-node.1.k6v2et8uxsjb@databox | options: app-helloworld-node.1.k6v2et8uxsjb@databox | [ { number: 11, len: 22, value: '/ts/helloWorldActuator' }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 3, len: 19, value: 'app-helloworld-node' }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 6, len: 0, value: '' }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 12, len: 2, value: 50 }, app-helloworld-node.1.k6v2et8uxsjb@databox | { number: 14, len: 4, value: 0 } ], app-helloworld-node.1.k6v2et8uxsjb@databox | payload: '' } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { number: 11, len: 22, value: '/ts/helloWorldActuator' } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { number: 3, len: 19, value: 'app-helloworld-node' } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { number: 6, len: 0, value: '' } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { number: 12, len: 2, value: 50 } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] { number: 14, len: 4, value: 0 } app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] Sending request: app-helloworld-node.1.k6v2et8uxsjb@databox | [Node ZestClient ] app-helloworld-node.1.k6v2et8uxsjb@databox | 0000: 0105 00fc 4d44 4177 5a57 7876 5932 4630 ....MDAwZWxvY2F0 app-helloworld-node.1.k6v2et8uxsjb@databox | 0010: 6157 3975 4941 6f77 4d44 4577 6157 526c aW9uIAowMDEwaWRl app-helloworld-node.1.k6v2et8uxsjb@databox | 0020: 626e 5270 5a6d 6c6c 6369 414b 4d44 4179 bnRpZmllciAKMDAy app-helloworld-node.1.k6v2et8uxsjb@databox | 0030: 4e6d 4e70 5a43 4277 5958 526f 4944 3067 NmNpZCBwYXRoID0g app-helloworld-node.1.k6v2et8uxsjb@databox | 0040: 4c33 527a 4c32 686c 6247 7876 5632 3979 L3RzL2hlbGxvV29y app-helloworld-node.1.k6v2et8uxsjb@databox | 0050: 6247 5242 5933 5231 5958 5276 6367 6f77 bGRBY3R1YXRvcgow app-helloworld-node.1.k6v2et8uxsjb@databox | 0060: 4d44 4531 5932 6c6b 4947 316c 6447 6876 MDE1Y2lkIG1ldGhv app-helloworld-node.1.k6v2et8uxsjb@databox | 0070: 5a43 4139 4945 6446 5641 6f77 4d44 4d7a ZCA9IEdFVAowMDMz app-helloworld-node.1.k6v2et8uxsjb@databox | 0080: 5932 6c6b 4948 5268 636d 646c 6443 4139 Y2lkIHRhcmdldCA9 app-helloworld-node.1.k6v2et8uxsjb@databox | 0090: 4947 5279 6158 5a6c 6369 316f 5a57 7873 IGRyaXZlci1oZWxs app-helloworld-node.1.k6v2et8uxsjb@databox | 00a0: 6233 6476 636d 786b 4c57 3576 5a47 5574 b3dvcmxkLW5vZGUt app-helloworld-node.1.k6v2et8uxsjb@databox | 00b0: 5932 3979 5a53 317a 6447 3979 5a51 6f77 Y29yZS1zdG9yZQow app-helloworld-node.1.k6v2et8uxsjb@databox | 00c0: 4d44 4a6d 6332 6c6e 626d 4630 6458 4a6c MDJmc2lnbmF0dXJl app-helloworld-node.1.k6v2et8uxsjb@databox | 00d0: 4943 3463 5363 6a46 6d74 6838 4b71 6e41 IC4cScjFmth8KqnA app-helloworld-node.1.k6v2et8uxsjb@databox | 00e0: 7044 4371 524a 346e 3555 325f 4731 3545 pDCqRJ4n5U2_G15E app-helloworld-node.1.k6v2et8uxsjb@databox | 00f0: 6850 5f4c 5633 4856 504c 466e 4367 3d3d hP_LV3HVPLFnCg== app-helloworld-node.1.k6v2et8uxsjb@databox | 0100: 000b 0016 2f74 732f 6865 6c6c 6f57 6f72 ..../ts/helloWor app-helloworld-node.1.k6v2et8uxsjb@databox | 0110: 6c64 4163 7475 6174 6f72 0003 0013 6170 ldActuator....ap app-helloworld-node.1.k6v2et8uxsjb@databox | 0120: 702d 6865 6c6c 6f77 6f72 6c64 2d6e 6f64 p-helloworld-nod app-helloworld-node.1.k6v2et8uxsjb@databox | 0130: 6500 0600 0000 0c00 0200 3200 0e00 0400 e.........2..... app-helloworld-node.1.k6v2et8uxsjb@databox | 0140: 0000 00 ...

Can partially decode base64 as:

000elocation 0010identifier 0026cid path = /ts/helloWorldActuator 0015cid method = GET 0033cid target = driver-hell