tessel / t1-runtime

[UNMAINTAINED] Tessel 1 JavaScript runtime.
Other
117 stars 33 forks source link

Splunk's SDK failing when accessing custom functions #572

Open glennblock opened 10 years ago

glennblock commented 10 years ago

I am trying to use Splunk's SDK from my Tessel. Running the following code fails:

var splunkjs = require('splunk-sdk');

setImmediate(function start() {
    var service = new splunkjs.Service({
        username: "admin", 
        password: "changeme", 
        host:"192.168.20.106", 
        port:"8089"}
    );

    service.login(function(err, success) {
        if (err) {
            throw err;
        }

        console.log("Login was successful: " + success);
        service.jobs().fetch(function(err, jobs) {
            var jobList = jobs.list();
            for(var i = 0; i < jobList.length; i++) {
                console.log("Job " + i + ": " + jobList[i].sid);
            }
        });
    });
});

With the following error:

Glenns-MacBook-Pro:splunk-client glennblock$ tessel run test.js
TESSEL! Connected to TM-00-04-f0009a30-00574342-347845c2.
INFO Bundling directory /Users/glennblock/src/tessel/splunk-client
INFO Deploying bundle (15.36 MB)...
INFO Running script...
/app/node_modules/splunk-sdk/lib/service.js:37: attempt to call method 'extend' (a nil value)

The extend method mentioned is defined here.

It is required by the Splunk Service here

Any help / pointers would be appreciated.

tcr commented 10 years ago

Thanks for filing this @glennblock. The root cause is that arguments.callee isn't implemented in Colony yet. I've opened up #573 to track this.

If you want a short-term fix, change the line https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/jquery.class.js#L15 to:

    root.Class.extend = function self (prop) {

And https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/jquery.class.js#L62 to:

      Class.extend = self;

Your test seemed to work after that change.

glennblock commented 10 years ago

Thanks @tcr! I have a talk coming up in Europe, and I was planning to show our SDK running on Tessel as part of it. I'll see if I get anything else after fixing this.

tcr commented 10 years ago

No problem. Keep us updated, and we can make sure #573 lands in a firmware release before your talk.

glennblock commented 10 years ago

@tcr will do, thanks! I appreciate the quick response. Also let me send a shout out to Pub Nub folks as I just happened to be in SF and walked by their Tessel hack night. I left and just had to get one!

tcr commented 10 years ago

That's awesome to hear! The Pub Nub team is almost more excited about Tessel than we are. It's been super fun working with them, and clearly it's paying off.

glennblock commented 10 years ago

@tcr that solved that problem! Got a new one :-)

Glenns-MacBook-Pro:splunk-client glennblock$ tessel run test.js
TESSEL! Connected to TM-00-04-f0009a30-00574342-347845c2.
INFO Bundling directory /Users/glennblock/src/tessel/splunk-client
INFO Deploying bundle (15.36 MB)...
INFO Running script...
loaded
/app/node_modules/splunk-sdk/lib/utils.js:133: attempt to index local 'original' (a nil value)

Also defined in utils.js: https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/utils.js#L133

glennblock commented 10 years ago

This is the same code (though I added the "loaded" console.log). This is just the next error.

rwaldron commented 10 years ago

@glennblock what is the target platform for that code? Was it always for Tessel?

glennblock commented 10 years ago

@rwaldron do you mean our SDK? The SDK itself is not built for Tessel, I am testing it out to see if it can work. The code using it is very simple / which is in this issue.

glennblock commented 10 years ago

The SDK is supported on Windows, Mac and Linux. We test on Ubuntu and I think CentOs.

rwaldron commented 10 years ago

Then I can assume you mean node? I'm asking because I don't understand why there are definitions for things like indexOf(and others)

glennblock commented 10 years ago

Yes this is node

On Tuesday, October 14, 2014, Rick Waldron notifications@github.com wrote:

Then I can assume you mean node? I'm asking because I don't understand why there are definitions for things like indexOf(and others)

— Reply to this email directly or view it on GitHub https://github.com/tessel/runtime/issues/572#issuecomment-59143449.

glennblock commented 10 years ago

It also supports browser usage as well.

glennblock commented 10 years ago

I forgot to mention that.

rwaldron commented 10 years ago

Does that include IE8? Are you using browserify?

glennblock commented 10 years ago

I believe we do use Browserify. Not sure on IE8 but can check.

On Tuesday, October 14, 2014, Rick Waldron notifications@github.com wrote:

Does that include IE8? Are you using browserify?

— Reply to this email directly or view it on GitHub https://github.com/tessel/runtime/issues/572#issuecomment-59145088.

rwaldron commented 10 years ago

Is there a reduced test case for the match bug? I was going to file this as a new issue for you, but I can't imagine what would cause this beyond something like:

function startsWith(original, prefix) {
  var matches = original.match("^" + prefix);
  return matches && matches.length > 0 && matches[0] === prefix;
}
startsWith(null, "foo");
startsWith(undefined, "foo");

But that's not a tessel/runtime issue.

tcr commented 10 years ago

I believe this issue is caused by a dropping HTTP connection not having the right fields populated. So a node-compatibility issue. I can reproduce it intermittently, but it takes a bit—I'll update here soon.

rwaldron commented 10 years ago

Sure, but it has nothing to do with string.match(...)

tcr commented 10 years ago

Yep. Also, it appears to be a bug in the Splunk SDK's error handling. In splunk/lib/platform/node/node_http.js we find:

 req.on("abort", function() {
                var res = { headers: {}, statusCode: "abort" };
                var data = "{}";
                var complete_response = that._buildResponse("abort", res, data);
                ...

Which brings us to (splunk/lib/http.js](https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/http.js#L238):

 _buildResponse: function(error, response, data) {
            var complete_response, json = {};

            var contentType = null;
            if (response && response.headers) {
                contentType = utils.trim(response.headers["content-type"] || response.headers["Content-Type"]);
            }
            ...  

So if the internet connection drops, and the request library issues an "abort" error, it will create an empty headers object but expect it to have a "content-type" field. So that's always going to throw an error rather than be handled gracefully.

@glennblock, I'll dig into what error conditions trigger the "abort" event in request, but this issue is a bug in the SDK itself (preventing you from gracefully handling the error and re-establishing the connection.)

glennblock commented 10 years ago

Ok, I will look into this. Weird it only showed up when I used it on Tessel.

On Wednesday, October 15, 2014, Tim Cameron Ryan notifications@github.com wrote:

Yep. Also, it appears to be a bug in the Splunk SDK's error handling. In splunk/lib/platform/node/node_http.js https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/platform/node/node_http.js#L59 we find:

req.on("abort", function() { var res = { headers: {}, statusCode: "abort" }; var data = "{}"; var complete_response = that._buildResponse("abort", res, data); ...

Which brings us to (splunk/lib/http.js]( https://github.com/splunk/splunk-sdk-javascript/blob/master/lib/http.js#L238 ):

_buildResponse: function(error, response, data) { var complete_response, json = {};

        var contentType = null;
        if (response && response.headers) {
            contentType = utils.trim(response.headers["content-type"] || response.headers["Content-Type"]);
        }
        ...

So if the internet connection drops, and the request library issues an "abort" error, it will create an empty headers object but expect it to have a "content-type" field. So that's always going to throw an error rather than be handled gracefully.

@glennblock https://github.com/glennblock, I'll dig into what error conditions trigger the "abort" event in request, but this issue is a bug in the SDK itself (preventing you from gracefully handling the error and re-establishing the connection.)

— Reply to this email directly or view it on GitHub https://github.com/tessel/runtime/issues/572#issuecomment-59311828.

glennblock commented 10 years ago

@tcr can you file a bug with our SDK?

glennblock commented 10 years ago

Hi folks

I wasn't able to get the Splunk SDK working on the device in time for my talk. Instead I demoed piping accelerometer data from the Tessel into Splunk and then visualizing within. The talk is here: http://vimeo.com/111111119 with the Tessel part in the last 10 mins.