Skip to content

Commit

Permalink
Merge branch 'master' into removerejection
Browse files Browse the repository at this point in the history
  • Loading branch information
pallavi2209 committed Oct 24, 2016
2 parents 0ee7bc4 + eb5ae26 commit a4026ba
Show file tree
Hide file tree
Showing 13 changed files with 1,726 additions and 22 deletions.
29 changes: 10 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[![Build Status](https://travis-ci.org/salesforce/refocus.svg?branch=master)](https://travis-ci.org/salesforce/refocus) [![StackShare](http://img.shields.io/badge/tech-stack-0690fa.svg?style=flat)](http://stackshare.io/iamigo/refocus) [![Coverage Status](https://coveralls.io/repos/github/salesforce/refocus/badge.svg?branch=master)](https://coveralls.io/github/salesforce/refocus?branch=master) [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Salesforce/refocus)
[![Build Status](https://travis-ci.org/salesforce/refocus.svg?branch=master)](https://travis-ci.org/salesforce/refocus)
[![Coverage Status](https://coveralls.io/repos/github/salesforce/refocus/badge.svg?branch=master)](https://coveralls.io/github/salesforce/refocus?branch=master)
[![StackShare](http://img.shields.io/badge/tech-stack-0690fa.svg?style=flat)](http://stackshare.io/iamigo/refocus)

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/Salesforce/refocus)

# Refocus

> ## Get started now with our [QuickStart](docs/QuickStart.md) guide!
Refocus is a platform for visualizing the health and status of systems and/or services under observation. It is *not* a monitoring or alerting tool.

*TODO: We need to flesh out this description to include why you would want to use it, why you would want to integrate it with your existing monitoring tools, etc.*
Refocus is a platform for visualizing the health and status of systems and/or services under observation. Check out our [home page](https://salesforce.github.io/refocus) and our [docs](https://salesforce.github.io/refocus/docs/00-welcome).

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down Expand Up @@ -91,29 +94,17 @@ After installing the server, you can run ```redis-cli``` to issue commands to re
- Run ```git push heroku <your branch>:master``` which will push to Heroku and start up a dyno.
- Run ```heroku open``` and view the app running in Heroku
- Run ```heroku run bash``` then run ```mocha``` to execute the test suite

- If you are running the app in more than one dyno, you will need to force the client to communicate with the server only using websockets. To do so, set the config variable SOCKETIO_TRANSPORT_PROTOCOL to websocket or run ```heroku config:set SOCKETIO_TRANSPORT_PROTOCOL=websocket```
If you are running on Heroku and you want to use Google Analytics, store your tracking id in a Heroku config variable called `GOOGLE_ANALYTICS_ID`.

## Using Trace (by RisingStack) for application performance monitoring
- Here is the quick start guide by Trace to start monitoring the app. https://trace-docs.risingstack.com/docs/getting-started
- To monitor the app deployed on heroku, follow the steps here. https://devcenter.heroku.com/articles/trace

## Configuring New Relic

### Local Deployment
Add your New Relic license key to an attribute called ```newRelicKey``` in ```config.js```

### Heroku Deployment
Install the New Relic add-on--it will automatically set the license key in your heroku environment.

### Troubleshooting a Heroku deployment
- Log errors in suspected areas. Use the logging in the error handler
- For errors 'Relation __ does not exist', the db is not set up properly. Try resetting the database. Run ```heroku run bash``` to enter shell script mode, then run ```gulp resetdb```, to reset the db
- Run ```heroku restart```, to restart the app
- Run ```heroku logs --tail``` to see the heroku logs, as they update

## Setup Production Environment on Localhost
If not already setup, follow Installation instructions to setup Refocus. Execute following commands to setup production environment and corresponding config variables:
If not already setup, follow Installation instructions to setup Refocus. Execute the following commands to setup production environment and corresponding config variables:
- Run ```export NODE_ENV=production```
- Run ```export DATABASE_URL='postgres://postgres:postgres@localhost:5432/focusdb'```
- Run ```npm start``` or ```node .```
Expand Down Expand Up @@ -158,4 +149,4 @@ The API is self-documenting based on [`./api/v1/swagger.yaml`](./api/v1/swagger.
- Node.js [token-based authentication](https://scotch.io/tutorials/authenticate-a-node-js-api-with-json-web-tokens)

## Contributing
Guidelines on contributing to Refocus are available [here](docs/Contributing.md).
Guidelines on contributing to Refocus are available [here](https://salesforce.github.io/refocus/docs/95-contributing.html).
1 change: 1 addition & 0 deletions docs/docs/95-contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Use Github to submit issues and enhancement requests.
- Code coverage tooling and % TBD
- All tests pass!
- Docs!
- If you are adding images to the docs, please keep image width < 800px
- Style!
- Run `gulp lint` to make sure your contribution follows our project's style guidelines (based on (https://github.com/airbnb/javascript)).

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function start() { // eslint-disable-line max-statements

const app = express();
const httpServer = require('http').Server(app);

const io = require('socket.io')(httpServer);
const socketIOSetup = require('./realtime/setupSocketIO');
socketIOSetup.setupNamespace(io);
Expand Down
7 changes: 6 additions & 1 deletion view/loadView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const viewmap = {
'/samples/:key/edit': 'admin',
'/perspectives': 'perspective/perspective',
'/perspectives/:key': 'perspective/perspective',
'/perspectivesBeta': 'perspectiveBeta/perspective',
'/perspectivesBeta/:key': 'perspectiveBeta/perspective',
};

/**
Expand Down Expand Up @@ -119,6 +121,7 @@ module.exports = function loadView(app, passport) {
trackingId: viewConfig.trackingId,
user: req.user,
eventThrottle: viewConfig.realtimeEventThrottleMilliseconds,
transportProtocol: viewConfig.socketIOtransportProtocol,
};

const templateVars = Object.assign(
Expand All @@ -130,7 +133,9 @@ module.exports = function loadView(app, passport) {
// if url contains a query, render perspective detail page with realtime
// updates
if ((key === '/perspectives' && Object.keys(req.query).length) ||
key === '/perspectives/:key') {
key === '/perspectives/:key' ||
(key === '/perspectivesBeta' && Object.keys(req.query).length) ||
key === '/perspectivesBeta/:key') {
res.render(viewmap[key], templateVars);
} else {
res.render(viewmap[key], trackObj);
Expand Down
30 changes: 28 additions & 2 deletions view/perspective/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const ONE = 1;

const DEBUG_REALTIME = window.location.href.split(/[&\?]/)
.includes('debug=REALTIME');

const WEBSOCKET_ONLY = window.location.href.split(/[&\?]/)
.includes('protocol=websocket');
const REQ_HEADERS = {
Authorization: u.getCookie('Authorization'),
'X-Requested-With': 'XMLHttpRequest',
Expand Down Expand Up @@ -95,11 +96,36 @@ function handleEvent(eventData, eventTypeName) {
function setupSocketIOClient(persBody) {
const namespace = u.getNamespaceString(persBody);

/*
* if the transprotocol is set, initialize the socketio client with
* the transport protocol options. The transProtocol variable is set in
* perspective.pug
*/
const options = {};
const clientProtocol = transProtocol;
if (clientProtocol) {
/*
* options is used here to set the transport type. For example to only use
* websockets as the transport protocol the options object will be
* { transports: ['websocket'] }. The regex is used to trim the white spaces
* and since clientProtocol is a string of comma seperated values,
* the split function is used to split them out by comma and convert
* it to an array.
*/
options.transports = clientProtocol.replace(/\s*,\s*/g, ',').split(',');
}

/*
* Note: The "io" variable is defined by the "/socket.io.js" script included
* in perspective.pug.
*/
const socket = io(namespace);
let socket;
if (WEBSOCKET_ONLY) {
socket = io(namespace, { transports: ['websocket'] });
} else {
socket = io(namespace, options);
}

socket.on(eventsQueue.eventType.INTRNL_SUBJ_ADD, (data) => {
handleEvent(data, eventsQueue.eventType.INTRNL_SUBJ_ADD);
});
Expand Down
3 changes: 3 additions & 0 deletions view/perspective/perspective.pug
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ html(lang = 'en')
script(src='/static/socket.io.js')
script.
var realtimeEventThrottleMilliseconds = #{eventThrottle};
script.
var transProtocol = '#{transportProtocol}';

script
if queryParams
| var queryParams = !{queryParams}
Expand Down

0 comments on commit a4026ba

Please sign in to comment.