Skip to content

Commit

Permalink
Merge pull request #17 from LearningLocker/newrelic
Browse files Browse the repository at this point in the history
Adds newrelic tracking.
  • Loading branch information
ryasmi authored Nov 2, 2017
2 parents 44a8b50 + 73c0825 commit b7befc0
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 29 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@
"dotenv": "^4.0.0",
"express": "^4.14.1",
"install": "^0.10.1",
"jscommons": "^1.0.1",
"jscommons": "^1.3.0",
"lodash": "^4.17.4",
"mongodb": "^2.2.26",
"redis": "^2.8.0",
"source-map-support": "^0.5.0",
"xapi-activities": "^1.1.3",
"xapi-agents": "^1.1.4",
"xapi-state": "^1.1.11",
"xapi-statements": "^1.0.16"
"xapi-statements": "^1.1.0"
},
"devDependencies": {
"@types/dotenv": "4.0.2",
Expand Down
11 changes: 11 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:max-file-line-count
import { config } from 'dotenv';
config();

Expand All @@ -15,6 +16,8 @@ const storageDir = `${process.cwd()}/storage`;
const expressPort = getNumberOption(process.env.EXPRESS_PORT, DEFAULT_EXPRESS_PORT);
const demoAuth = `http://localhost:${expressPort}/auth`;
const accessLogsDir = `${storageDir}/accessLogs`;
const newRelicLogsDir = `${storageDir}/newrelic-agent.log`;
const newRelicLicenseKey = getStringOption(process.env.NEW_RELIC_LICENSE_KEY, '');

export default {
defaultTimeout: getNumberOption(process.env.DEFAULT_TIMEOUT_MS, DEFAULT_TIMEOUT_MS),
Expand Down Expand Up @@ -76,6 +79,14 @@ export default {
state: getStringOption(process.env.SUB_FOLDER_STATE, '/state'),
statements: getStringOption(process.env.SUB_FOLDER_STATEMENTS, '/statements'),
},
tracker: {
newRelic: {
enabled: newRelicLicenseKey !== '',
log: getStringOption(process.env.NEW_RELIC_LOG, newRelicLogsDir),
logLevel: getStringOption(process.env.NEW_RELIC_LOG_LEVEL, 'info'),
noConfigFile: getStringOption(process.env.NEW_RELIC_NO_CONFIG_FILE, 'true'),
},
},
winston: {
cloudWatch: {
awsConfig: {
Expand Down
7 changes: 2 additions & 5 deletions src/conformanceServer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// tslint:disable:no-console
import * as sourceMapSupport from 'source-map-support';
sourceMapSupport.install();

import { MongoClient, ObjectID } from 'mongodb';
import config from './config';
import './server'; // tslint:disable-line:no-import-side-effect
import { MongoClient, ObjectID } from 'mongodb'; // tslint:disable-line:ordered-imports
import config from './config';

const testClient = {
api: {
Expand Down
2 changes: 2 additions & 0 deletions src/routers/statements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import testAuthRepo from 'xapi-statements/dist/testAuthRepo';
import enTranslator from 'xapi-statements/dist/translatorFactory/en';
import config from '../config';
import logger from '../logger';
import tracker from '../tracker';

const getEventsRepo = () => {
switch (config.repoFactory.authRepoName) {
Expand Down Expand Up @@ -132,6 +133,7 @@ const serviceFacade = service({
enableVoiding: config.statementsService.enableVoiding,
enableVoidingChecks: config.statementsService.enableVoidingChecks,
repo: repoFacade,
tracker,
});
const expressFacade = expressPresenter({
bodyParserLimit: config.express.bodyParserLimit,
Expand Down
3 changes: 2 additions & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as sourceMapSupport from 'source-map-support';
import './tracker'; // tslint:disable-line:no-import-side-effect
import * as sourceMapSupport from 'source-map-support'; // tslint:disable-line:ordered-imports
sourceMapSupport.install();

import * as express from 'express';
Expand Down
17 changes: 17 additions & 0 deletions src/tracker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import fakeTracker from 'jscommons/dist/tracker/fake';
import newRelicTracker from 'jscommons/dist/tracker/newrelic';
import Tracker from 'jscommons/dist/tracker/Tracker';
import config from './config';

/* istanbul ignore next */
const trackerFactory = async (): Promise<Tracker> => {
if (config.tracker.newRelic.enabled) {
process.env.NEW_RELIC_NO_CONFIG_FILE = config.tracker.newRelic.noConfigFile;
process.env.NEW_RELIC_LOG = config.tracker.newRelic.log;
process.env.NEW_RELIC_LOG_LEVEL = config.tracker.newRelic.logLevel;
return newRelicTracker();
}
return fakeTracker;
};

export default trackerFactory();
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ log "Installing dependencies for the ADL conformance test suite."
npm install

log "Running the ADL conformance test suite."
node bin/console_runner.js -e "http://localhost:$EXPRESS_PORT/data/xAPI" -a -u "AAA" -p "BBB"
node bin/console_runner.js -e "http://localhost:$EXPRESS_PORT/data/xAPI" -a -u "AAA" -p "BBB" -b
exitCode=$?

log "Stopping the server."
ps aux | grep [n]ode\ dist\/server | awk '{print $2}' | xargs kill
ps aux | grep [n]ode\ dist\/conformanceServer | awk '{print $2}' | xargs kill

log "Completed conformance tests."
exit $exitCode
14 changes: 7 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ atob@^2.0.3:
resolved "https://registry.yarnpkg.com/atob/-/atob-2.0.3.tgz#19c7a760473774468f20b2d2d03372ad7d4cbf5d"

aws-sdk@^2.58.0, aws-sdk@^2.74.0, aws-sdk@^2.80.0, aws-sdk@^2.97.0:
version "2.141.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.141.0.tgz#3d96a5970fd9f540ceabcc1d4baeb33b71583aa7"
version "2.142.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.142.0.tgz#efdf69d2be3132aa51d4e7abb2c28fe42771e3ec"
dependencies:
buffer "4.9.1"
crypto-browserify "1.0.9"
Expand Down Expand Up @@ -1809,7 +1809,7 @@ jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"

jscommons@^1.0.1:
jscommons@^1.0.1, jscommons@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/jscommons/-/jscommons-1.3.0.tgz#2ed1065fc7b970ecc728d0bd65ff0bfed564ce54"
dependencies:
Expand Down Expand Up @@ -3596,9 +3596,9 @@ xapi-state@^1.1.11:
uuid "^3.0.1"
xapi-validation "^2.1.0"

xapi-statements@^1.0.16:
version "1.0.16"
resolved "https://registry.yarnpkg.com/xapi-statements/-/xapi-statements-1.0.16.tgz#9363655ca0ae3c9e8e0bac06914c81df78051d8a"
xapi-statements@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/xapi-statements/-/xapi-statements-1.1.0.tgz#08aef148a73d95faa1c2067d3e90c7b7f61d7c9c"
dependencies:
accept-language-parser "^1.4.1"
atob "^2.0.3"
Expand All @@ -3613,7 +3613,7 @@ xapi-statements@^1.0.16:
file-stream-rotator "^0.2.0"
fs-extra "^4.0.2"
helmet "^3.5.0"
jscommons "^1.0.1"
jscommons "^1.3.0"
jsonwebtoken "^8.0.1"
lodash "^4.17.4"
mime-types "^2.1.17"
Expand Down

0 comments on commit b7befc0

Please sign in to comment.