Last active
February 1, 2017 22:28
-
-
Save jdlrobson/2c3e3b48dd2de848e750cf3efcc49f00 to your computer and use it in GitHub Desktop.
Simulate events for the reading web trending service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| sudo service eventlogging-service-eventbus status | |
| sudo service eventlogging-service-eventbus start | |
| tail -f /vagrant/logs/eventbus.log | |
| npm install node-fetch | |
| node simulate.js | |
| if doesnt work verify the event was received: | |
| sudo tail -f /var/log/upstart/eventlogging-service-eventbus.log | |
| wget -O - http://0.0.0.0:6927/en.wikipedia.org/v1/feed/trending-edits | tail | |
| */ | |
| var fetch = require('node-fetch'); | |
| const EVENT = {"comment": "", "database": "wiki", "meta": {"domain": "dev.wiki.local.wmftest.net", "id": "c7abff50-ab57-11e6-b998-080027627611", "request_id": "a71fb6f7-e35e-475c-9e19-5e6416822e1f", "schema_uri": "mediawiki/revision/create/1", "topic": "mediawiki.revision-create", "uri": "http://dev.wiki.local.wmftest.net:8080/wiki/T1"}, "page_id": 4, "page_is_redirect": false, "page_namespace": 0, "rev_content_format": "wikitext", "rev_content_model": "wikitext", "rev_id": 7, "rev_minor_edit": false, "rev_parent_id": 6, "rev_sha1": "2vm4buc9z8jsju7chm460aplwg32lip"}; | |
| var titles = {}; | |
| var users = {}; | |
| var date = new Date(); | |
| var nextId = 1; | |
| function tick( mins ) { | |
| date = new Date( date.getTime() + ( mins * 60 * 1000 ) ); | |
| }; | |
| function simulate( title, editor, isAnon ) { | |
| var id = titles[title]; | |
| var userId = users[editor]; | |
| if ( !id ) { | |
| id = nextId; | |
| nextId++; | |
| } | |
| if ( userId === undefined ) { | |
| userId = nextId; | |
| nextId++; | |
| if ( isAnon ) { | |
| userId = false; | |
| } | |
| } | |
| titles[title] = id; | |
| users[editor] = userId; | |
| var event = Object.assign( {}, EVENT, { | |
| page_title: title, | |
| page_id: titles[title], | |
| // always increase rev_len to ensure bytes are being added and avoid negative score | |
| rev_len: 8 * nextId, | |
| performer: { | |
| user_groups: [], | |
| user_text: editor, | |
| user_is_bot: false | |
| } | |
| }); | |
| event.meta.dt = date.toISOString(); | |
| event.rev_timestamp = date.toISOString(); | |
| if ( userId ) { | |
| event.performer.user_id = userId; | |
| } | |
| fetch( 'http://localhost:8085/v1/events', { | |
| method: "POST", | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify( event ) | |
| } ) | |
| } | |
| const topPage = 'Trending article'; | |
| const pageTwo = 'Page with just one editor' | |
| const pageThree = 'Just anon edits' | |
| // start 2 hours ago to allow us to test period works | |
| tick( - 60 * 2 ); | |
| // simulate some activity based on a real trending event | |
| simulate( topPage, 'AB' ); | |
| simulate( topPage, 'AB' ); | |
| simulate( pageTwo, 'Someone' ); | |
| simulate( pageThree, '127.0.0.1', true ); | |
| simulate( pageThree, '127.0.0.1', true ); | |
| simulate( pageThree, '127.0.0.1', true ); | |
| simulate( topPage, 'AB' ); | |
| simulate( topPage, 'AB' ); | |
| simulate( topPage, 'AB' ); | |
| tick(1); | |
| simulate( topPage, 'AB' ); | |
| tick(1); | |
| simulate( topPage, 'AB' ); | |
| tick(5); | |
| simulate( pageThree, '127.0.0.1', true ); | |
| simulate( pageThree, '127.0.0.1', true ); | |
| simulate( pageTwo, 'Someone' ); | |
| simulate( topPage, 'D' ); | |
| tick(9); | |
| simulate( topPage, 'AB' ); | |
| tick(5); | |
| simulate( topPage, 'AB' ); | |
| tick(17); | |
| simulate( topPage, 'SerAm' ); | |
| simulate( pageThree, '127.0.0.3', true ); | |
| simulate( pageTwo, 'Someone' ); | |
| simulate( pageTwo, 'Someone' ); | |
| simulate( pageTwo, 'Someone' ); | |
| simulate( pageTwo, 'Someone' ); | |
| tick(7); | |
| simulate( topPage, '2605', true ); | |
| simulate( topPage, '2605', true ); | |
| simulate( pageThree, '127.0.0.4', true ); | |
| simulate( topPage, 'AB' ); | |
| simulate( topPage, 'AB' ); | |
| simulate( pageTwo, 'Someone' ); | |
| simulate( pageTwo, 'Someone' ); | |
| tick(1); | |
| simulate( topPage, 'AB' ); | |
| tick(16); | |
| simulate( topPage, 'Someone' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment