{"action":"created","comment":{"url":"https://api.github.com/repos/uber/ringpop-node/pulls/comments/39476438","id":39476438,"diff_hunk":"@@ -0,0 +1,135 @@\n+// Copyright (c) 2015 Uber Technologies, Inc.\n+//\n+// Permission is hereby granted, free of charge, to any person obtaining a copy\n+// of this software and associated documentation files (the \"Software\"), to deal\n+// in the Software without restriction, including without limitation the rights\n+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+// copies of the Software, and to permit persons to whom the Software is\n+// furnished to do so, subject to the following conditions:\n+//\n+// The above copyright notice and this permission notice shall be included in\n+// all copies or substantial portions of the Software.\n+//\n+// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n+// THE SOFTWARE.\n+\n+'use strict';\n+\n+var EventEmitter = require('events').EventEmitter;\n+\n+var after = require('after');\n+var async = require('async');\n+var test = require('tape');\n+\n+var core = require('../lib/trace/core');\n+var TracerStore = require('../lib/trace/store');\n+\n+test('trace adds/removes work and are idempotent', function t(assert) {\n+    assert.plan(15);\n+    var cbJoin = after(5, assert.end.bind(assert));\n+\n+    var ringpop = new rpMock();\n+    var store = new TracerStore(ringpop);\n+\n+    var config = core.resolveEventConfig(ringpop, 'membership.update');\n+    assert.ok(config, 'event resolves');\n+    assert.equal(config.sourceEmitter, ringpop.membership, 'config has right membership emitter');\n+    var opts = {expiresIn: 50, sink: {type: 'log'}};\n+\n+    // remove from nothing, then add, and again. should end with one tracer\n+    store.remove(config, opts, function onRemove(err, tracer) {\n+        assert.false(err, 'no error, idempotent remove');\n+        assert.false(tracer, 'no tracer, idempotent remove');\n+    });\n+\n+    var theTracer = store.add(config, opts, function onAdd(err, tracer) {\n+        assert.false(err, 'no error, add good');\n+        assert.true(tracer, 'tracer added');\n+    });\n+    assert.true(theTracer, 'tracer added, double checking');\n+\n+    store.add(config, opts, function onAdd(err, tracer) {\n+        assert.false(err, 'no error, idempotent add');\n+        assert.true(tracer, 'tracer already added');\n+        assert.equal(tracer, theTracer, 'tracer returned is same');\n+    });\n+\n+    // remove twice, checking both times\n+    store.remove(config, opts, function onRemove(err, tracer) {\n+        assert.false(err, 'no error, idempotent remove');\n+        assert.true(tracer, 'tracer removed');\n+        assert.equal(tracer, theTracer, 'tracer returned is same');\n+    });\n+\n+    store.remove(config, opts, function onRemove(err, tracer) {\n+        assert.false(err, 'no error, idempotent remove');\n+        assert.false(tracer, 'tracer already removed');\n+    });\n+});\n+\n+test('trace events get traced', function t(assert) {\n+    var ringpop = new rpMock();\n+    var store = new TracerStore(ringpop);\n+    var config = core.resolveEventConfig(ringpop, 'membership.update');\n+    var opts = {expiresIn: 50, sink: {type: 'log'}};\n+    var tracer = store.add(config, opts);\n+\n+    assert.plan(5);\n+    tracer.on('connectSink', function onTracer() {\n+        // now test events on this thing\n+        assert.equal(ringpop.journal.length, 0, 'journal starts empty');\n+        ringpop.membership.emit('updated', 'foo');\n+        assert.equal(ringpop.journal.length, 1, 'journal has 1 entry');\n+        assert.equal(ringpop.journal[0], 'foo', 'journal added foo');\n+\n+        ringpop.membership.emit('updated', 'bar');\n+        assert.equal(ringpop.journal.length, 2, 'journal has 2 entries');\n+        assert.equal(ringpop.journal[1], 'bar', 'journal added bar');\n+    });\n+});\n+\n+test('trace events can renew, and expire', function t(assert) {\n+    var ringpop = new rpMock();\n+    var store = new TracerStore(ringpop);\n+    var config = core.resolveEventConfig(ringpop, 'membership.update');\n+    var opts = {expiresIn: 50, sink: {type: 'log'}};\n+    var tracer = store.add(config, opts);\n+\n+    assert.plan(3);\n+\n+    // nextTick okay since log \"connects\" instantly\n+    process.nextTick(function onTracer() {\n+        // now test events on this thing\n+        ringpop.membership.emit('updated', 'foo');\n+        assert.equal(ringpop.journal.length, 1, 'journal has 1 entry');\n+\n+        // renew after 25, run @ 60, confirm event; this is racey...\n+        setTimeout(store.add.bind(store, config, opts), 25);","path":"test/trace-test.js","position":112,"original_position":112,"commit_id":"fe4a75b54f80a792f012acaf8e935eef7fa41eab","original_commit_id":"4cc5ee0edea93dcc5091329350265343701f1b3f","user":{"login":"benfleis","id":2185001,"avatar_url":"https://avatars.githubusercontent.com/u/2185001?v=3","gravatar_id":"","url":"https://api.github.com/users/benfleis","html_url":"https://github.com/benfleis","followers_url":"https://api.github.com/users/benfleis/followers","following_url":"https://api.github.com/users/benfleis/following{/other_user}","gists_url":"https://api.github.com/users/benfleis/gists{/gist_id}","starred_url":"https://api.github.com/users/benfleis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benfleis/subscriptions","organizations_url":"https://api.github.com/users/benfleis/orgs","repos_url":"https://api.github.com/users/benfleis/repos","events_url":"https://api.github.com/users/benfleis/events{/privacy}","received_events_url":"https://api.github.com/users/benfleis/received_events","type":"User","site_admin":false},"body":"Gladly. I hadn't seen time-mock (I looked briefly at stealing the time mock from sinon), and ultimately thought that these tiny timevals wouldn't be so bad, but I can easily rework to use the mock.\r\n\r\n(Just checked, they add 140ms total time to the tests as-is. I still feel like mock time is better here for reliable timing, instead of the risk of system delays screwing up tests. But just thought I'd share.)","created_at":"2015-09-15T05:48:42Z","updated_at":"2015-09-15T05:48:42Z","html_url":"https://github.com/uber/ringpop-node/pull/140#discussion_r39476438","pull_request_url":"https://api.github.com/repos/uber/ringpop-node/pulls/140","_links":{"self":{"href":"https://api.github.com/repos/uber/ringpop-node/pulls/comments/39476438"},"html":{"href":"https://github.com/uber/ringpop-node/pull/140#discussion_r39476438"},"pull_request":{"href":"https://api.github.com/repos/uber/ringpop-node/pulls/140"}}},"pull_request":{"url":"https://api.github.com/repos/uber/ringpop-node/pulls/140","id":42123026,"html_url":"https://github.com/uber/ringpop-node/pull/140","diff_url":"https://github.com/uber/ringpop-node/pull/140.diff","patch_url":"https://github.com/uber/ringpop-node/pull/140.patch","issue_url":"https://api.github.com/repos/uber/ringpop-node/issues/140","number":140,"state":"open","locked":false,"title":"add basic trace feature to ringpop; currently support traces that output","user":{"login":"benfleis","id":2185001,"avatar_url":"https://avatars.githubusercontent.com/u/2185001?v=3","gravatar_id":"","url":"https://api.github.com/users/benfleis","html_url":"https://github.com/benfleis","followers_url":"https://api.github.com/users/benfleis/followers","following_url":"https://api.github.com/users/benfleis/following{/other_user}","gists_url":"https://api.github.com/users/benfleis/gists{/gist_id}","starred_url":"https://api.github.com/users/benfleis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benfleis/subscriptions","organizations_url":"https://api.github.com/users/benfleis/orgs","repos_url":"https://api.github.com/users/benfleis/repos","events_url":"https://api.github.com/users/benfleis/events{/privacy}","received_events_url":"https://api.github.com/users/benfleis/received_events","type":"User","site_admin":false},"body":"to tchannel or the given logger object.\r\n\r\nevent tracers allow a live ringpop system to dynamically foward internal\r\nevents to arbitrary events, creating space for ephemeral live event\r\nanalysis and diagnostics in running clusters.\r\n\r\nsee https://github.com/uber/ringpop/issues/139\r\n\r\nThis diff is *incomplete* -- tests are not added yet, and there are several open XXX questions for @jwolski (or others, wink wink @raynos) to consider addressing.","created_at":"2015-08-11T12:27:58Z","updated_at":"2015-09-15T05:48:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db0b4fc410794380cf585a2ea08ffe1260923c4e","assignee":{"login":"CorgiMan","id":2640140,"avatar_url":"https://avatars.githubusercontent.com/u/2640140?v=3","gravatar_id":"","url":"https://api.github.com/users/CorgiMan","html_url":"https://github.com/CorgiMan","followers_url":"https://api.github.com/users/CorgiMan/followers","following_url":"https://api.github.com/users/CorgiMan/following{/other_user}","gists_url":"https://api.github.com/users/CorgiMan/gists{/gist_id}","starred_url":"https://api.github.com/users/CorgiMan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CorgiMan/subscriptions","organizations_url":"https://api.github.com/users/CorgiMan/orgs","repos_url":"https://api.github.com/users/CorgiMan/repos","events_url":"https://api.github.com/users/CorgiMan/events{/privacy}","received_events_url":"https://api.github.com/users/CorgiMan/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/uber/ringpop-node/pulls/140/commits","review_comments_url":"https://api.github.com/repos/uber/ringpop-node/pulls/140/comments","review_comment_url":"https://api.github.com/repos/uber/ringpop-node/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uber/ringpop-node/issues/140/comments","statuses_url":"https://api.github.com/repos/uber/ringpop-node/statuses/fe4a75b54f80a792f012acaf8e935eef7fa41eab","head":{"label":"uber:feature/trace","ref":"feature/trace","sha":"fe4a75b54f80a792f012acaf8e935eef7fa41eab","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":29378455,"name":"ringpop-node","full_name":"uber/ringpop-node","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/ringpop-node","description":"Scalable, fault-tolerant application-layer sharding","fork":false,"url":"https://api.github.com/repos/uber/ringpop-node","forks_url":"https://api.github.com/repos/uber/ringpop-node/forks","keys_url":"https://api.github.com/repos/uber/ringpop-node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/ringpop-node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/ringpop-node/teams","hooks_url":"https://api.github.com/repos/uber/ringpop-node/hooks","issue_events_url":"https://api.github.com/repos/uber/ringpop-node/issues/events{/number}","events_url":"https://api.github.com/repos/uber/ringpop-node/events","assignees_url":"https://api.github.com/repos/uber/ringpop-node/assignees{/user}","branches_url":"https://api.github.com/repos/uber/ringpop-node/branches{/branch}","tags_url":"https://api.github.com/repos/uber/ringpop-node/tags","blobs_url":"https://api.github.com/repos/uber/ringpop-node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/ringpop-node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/ringpop-node/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/ringpop-node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/ringpop-node/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/ringpop-node/languages","stargazers_url":"https://api.github.com/repos/uber/ringpop-node/stargazers","contributors_url":"https://api.github.com/repos/uber/ringpop-node/contributors","subscribers_url":"https://api.github.com/repos/uber/ringpop-node/subscribers","subscription_url":"https://api.github.com/repos/uber/ringpop-node/subscription","commits_url":"https://api.github.com/repos/uber/ringpop-node/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/ringpop-node/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/ringpop-node/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/ringpop-node/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/ringpop-node/contents/{+path}","compare_url":"https://api.github.com/repos/uber/ringpop-node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/ringpop-node/merges","archive_url":"https://api.github.com/repos/uber/ringpop-node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/ringpop-node/downloads","issues_url":"https://api.github.com/repos/uber/ringpop-node/issues{/number}","pulls_url":"https://api.github.com/repos/uber/ringpop-node/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/ringpop-node/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/ringpop-node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/ringpop-node/labels{/name}","releases_url":"https://api.github.com/repos/uber/ringpop-node/releases{/id}","created_at":"2015-01-17T03:26:35Z","updated_at":"2015-09-15T02:24:29Z","pushed_at":"2015-09-15T04:50:25Z","git_url":"git://github.com/uber/ringpop-node.git","ssh_url":"git@github.com:uber/ringpop-node.git","clone_url":"https://github.com/uber/ringpop-node.git","svn_url":"https://github.com/uber/ringpop-node","homepage":"","size":3273,"stargazers_count":229,"watchers_count":229,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":22,"forks":16,"open_issues":22,"watchers":229,"default_branch":"master"}},"base":{"label":"uber:master","ref":"master","sha":"6f616265967c678580d16d447d218199e843144c","user":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"repo":{"id":29378455,"name":"ringpop-node","full_name":"uber/ringpop-node","owner":{"login":"uber","id":538264,"avatar_url":"https://avatars.githubusercontent.com/u/538264?v=3","gravatar_id":"","url":"https://api.github.com/users/uber","html_url":"https://github.com/uber","followers_url":"https://api.github.com/users/uber/followers","following_url":"https://api.github.com/users/uber/following{/other_user}","gists_url":"https://api.github.com/users/uber/gists{/gist_id}","starred_url":"https://api.github.com/users/uber/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uber/subscriptions","organizations_url":"https://api.github.com/users/uber/orgs","repos_url":"https://api.github.com/users/uber/repos","events_url":"https://api.github.com/users/uber/events{/privacy}","received_events_url":"https://api.github.com/users/uber/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uber/ringpop-node","description":"Scalable, fault-tolerant application-layer sharding","fork":false,"url":"https://api.github.com/repos/uber/ringpop-node","forks_url":"https://api.github.com/repos/uber/ringpop-node/forks","keys_url":"https://api.github.com/repos/uber/ringpop-node/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uber/ringpop-node/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uber/ringpop-node/teams","hooks_url":"https://api.github.com/repos/uber/ringpop-node/hooks","issue_events_url":"https://api.github.com/repos/uber/ringpop-node/issues/events{/number}","events_url":"https://api.github.com/repos/uber/ringpop-node/events","assignees_url":"https://api.github.com/repos/uber/ringpop-node/assignees{/user}","branches_url":"https://api.github.com/repos/uber/ringpop-node/branches{/branch}","tags_url":"https://api.github.com/repos/uber/ringpop-node/tags","blobs_url":"https://api.github.com/repos/uber/ringpop-node/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uber/ringpop-node/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uber/ringpop-node/git/refs{/sha}","trees_url":"https://api.github.com/repos/uber/ringpop-node/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uber/ringpop-node/statuses/{sha}","languages_url":"https://api.github.com/repos/uber/ringpop-node/languages","stargazers_url":"https://api.github.com/repos/uber/ringpop-node/stargazers","contributors_url":"https://api.github.com/repos/uber/ringpop-node/contributors","subscribers_url":"https://api.github.com/repos/uber/ringpop-node/subscribers","subscription_url":"https://api.github.com/repos/uber/ringpop-node/subscription","commits_url":"https://api.github.com/repos/uber/ringpop-node/commits{/sha}","git_commits_url":"https://api.github.com/repos/uber/ringpop-node/git/commits{/sha}","comments_url":"https://api.github.com/repos/uber/ringpop-node/comments{/number}","issue_comment_url":"https://api.github.com/repos/uber/ringpop-node/issues/comments{/number}","contents_url":"https://api.github.com/repos/uber/ringpop-node/contents/{+path}","compare_url":"https://api.github.com/repos/uber/ringpop-node/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uber/ringpop-node/merges","archive_url":"https://api.github.com/repos/uber/ringpop-node/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uber/ringpop-node/downloads","issues_url":"https://api.github.com/repos/uber/ringpop-node/issues{/number}","pulls_url":"https://api.github.com/repos/uber/ringpop-node/pulls{/number}","milestones_url":"https://api.github.com/repos/uber/ringpop-node/milestones{/number}","notifications_url":"https://api.github.com/repos/uber/ringpop-node/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uber/ringpop-node/labels{/name}","releases_url":"https://api.github.com/repos/uber/ringpop-node/releases{/id}","created_at":"2015-01-17T03:26:35Z","updated_at":"2015-09-15T02:24:29Z","pushed_at":"2015-09-15T04:50:25Z","git_url":"git://github.com/uber/ringpop-node.git","ssh_url":"git@github.com:uber/ringpop-node.git","clone_url":"https://github.com/uber/ringpop-node.git","svn_url":"https://github.com/uber/ringpop-node","homepage":"","size":3273,"stargazers_count":229,"watchers_count":229,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":22,"forks":16,"open_issues":22,"watchers":229,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uber/ringpop-node/pulls/140"},"html":{"href":"https://github.com/uber/ringpop-node/pull/140"},"issue":{"href":"https://api.github.com/repos/uber/ringpop-node/issues/140"},"comments":{"href":"https://api.github.com/repos/uber/ringpop-node/issues/140/comments"},"review_comments":{"href":"https://api.github.com/repos/uber/ringpop-node/pulls/140/comments"},"review_comment":{"href":"https://api.github.com/repos/uber/ringpop-node/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uber/ringpop-node/pulls/140/commits"},"statuses":{"href":"https://api.github.com/repos/uber/ringpop-node/statuses/fe4a75b54f80a792f012acaf8e935eef7fa41eab"}}}}