Skip to content

Commit

Permalink
Merge pull request #49 from Financial-Times/fetch-services
Browse files Browse the repository at this point in the history
listing services to collect metrics on here rather than next-express
  • Loading branch information
wheresrhys committed Oct 13, 2015
2 parents 633d486 + 01ec4bb commit 51ad874
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,5 @@ Metrics.prototype.registerAggregator = function (func) {
};

module.exports = new Metrics();

module.exports.services = require('./metrics/services');
9 changes: 7 additions & 2 deletions lib/metrics/fetch.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
'use strict';
var metrics = require('metrics');
var services = require('./services')

var Fetch = function() {
this.counters = {};
};

Fetch.prototype.instrument = function(opts) {
opts = opts || {};

if (!GLOBAL.fetch) {
throw 'You need to require(\'isomorphic-fetch\'); before instrumenting it';
}
if (GLOBAL.fetch._instrumented) {
return console.warn('You can only instrument fetch once. Remember, if you\'re using next-express metrics for most fetch calls are setup automatically');
}

this.serviceMatchers = opts.serviceMatchers;
this.serviceMatchers = services;
this.onUninstrumented = opts.onUninstrumented || function() {};
this.serviceNames = Object.keys(opts.serviceMatchers);
this.serviceNames = Object.keys(services);

this.serviceNames.forEach(function(service) {
this.counters['fetch_' + service + '_requests'] = new metrics.Counter();
Expand Down Expand Up @@ -123,3 +126,5 @@ Fetch.prototype.reporter = function() {
};

module.exports = Fetch;


68 changes: 68 additions & 0 deletions lib/metrics/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
module.exports = {
'amo': /^https?:\/\/barrier-app.memb\.ft\.com\/memb\/amo\/v1\/amo-data/,
'blogs': /^https?:\/\/blogs\.ft\.com/,
'capi-v1-article': /^https?:\/\/api\.ft\.com\/content\/items\/v1\/[\w\-]+/,
'capi-v1-page': /^https?:\/\/api\.ft\.com\/site\/v1\/pages\/[\w\-]+/,
'capi-v1-pages-list': /^https?:\/\/api\.ft\.com\/site\/v1\/pages/,
'capi-v1-navigations': /^https?:\/\/api\.ft\.com\/site\/v1\/navigations/,
'sapi': /^https?:\/\/api\.ft\.com\/content\/search\/v1/,
'aws-elastic-v1-article': /^https?:\/\/[\w\-]+\.[\w\-]+\.es\.amazonaws\.com\/v1_api_v2\/item/,
'aws-elastic-v2-article': /^https?:\/\/[\w\-]+\.[\w\-]+\.es\.amazonaws\.com\/v2_api_v[12]\/item/,
'aws-elastic-v1-item-search': /^https?:\/\/[\w\-]+\.[\w\-]+\.es\.amazonaws\.com\/v1_api_v2\/item\/_search/,
'aws-elastic-v2-item-search': /^https?:\/\/[\w\-]+\.[\w\-]+\.es\.amazonaws\.com\/v2_api_v2\/item\/_search/,
'aws-elastic-v1-search': /^https?:\/\/[\w\-]+\.[\w\-]+\.es\.amazonaws\.com\/v1_api_v2\/_search/,
'aws-elastic-v2-search': /^https?:\/\/[\w\-]+\.[\w\-]+\.es\.amazonaws\.com\/v2_api_v2\/_search/,
'elastic-v1-article': /^https?:\/\/[\w\-]+\.foundcluster\.com(:\d+)?\/v1_api_v2\/item/,
'elastic-v2-article': /^https?:\/\/[\w\-]+\.foundcluster\.com(:\d+)?\/v2_api_v[12]\/item/,
'elastic-v1-item-search': /^https?:\/\/[\w\-]+\.foundcluster\.com(:\d+)?\/v1_api_v2\/item\/_search/,
'elastic-v2-item-search': /^https?:\/\/[\w\-]+\.foundcluster\.com(:\d+)?\/v2_api_v2\/item\/_search/,
'elastic-v1-search': /^https?:\/\/[\w\-]+\.foundcluster\.com(:\d+)?\/v1_api_v2\/_search/,
'elastic-v2-search': /^https?:\/\/[\w\-]+\.foundcluster\.com(:\d+)?\/v2_api_v2\/_search/,
'ft-next-api-user-prefs-v002': /^https?:\/\/ft-next-api-user-prefs-v002\.herokuapp\.com/,
'api-feature-flags': /^https?:\/\/(?:ft-next-feature-flags-prod\..*\.amazonaws\.com|next-flags\.ft\.com)/,
'capi-v2-article': /^https?:\/\/api\.ft\.com\/content\/[\w\-]+/,
'capi-v2-concordances': /^https?:\/\/api\.ft\.com\/concordances\?/,
'capi-v2-enriched-article': /^https?:\/\/api\.ft\.com\/enrichedcontent\/[\w\-]+/,
'capi-v2-lists': /^https?:\/\/api\.ft\.com\/lists\/[\w\-]+/,
'capi-v2-thing': /^https?:\/\/api\.ft\.com\/things\/[\w\-]+/,
'capi-v2-people': /^https?:\/\/api\.ft\.com\/people\/[\w\-]+/,
'capi-v2-organisation': /^https?:\/\/api\.ft\.com\/organisations\/[\w\-]+/,
'capi-v2-content-by-concept': /^https?:\/\/api\.ft\.com\/content\?isAnnotatedBy=http:\/\/api\.ft\.com\/things\/[\w\-]+/,
// fastft
'fastft': /https?:\/\/clamo\.ftdata\.co\.uk\/api/,
// ft.com (temporary for article comment hack)
'ft-com': /^https?:\/\/www\.ft\.com\/cms\/s\/[\w\-]+\.html$/,
'ft-next-beacon': /^https?:\/\/next-beacon\.ft\.com\/px\.gif/,
'ft-next-session-service': /^https?:\/\/session-next\.ft\.com/,
'ft-next-ab': /^https?:\/\/ft-next-ab\.herokuapp\.com/,
'ft-next-concepts-api': /^https?:\/\/ft-next-concepts-api\.herokuapp\.com/,
'ft-next-markets-proxy-api': /^https?:\/\/next-markets-proxy\.ft\.com/,
'barriers-api': /^https?:\/\/subscribe.ft.com\/memb\/barrier/,
'barriers-api-direct': /^https?:\/\/barrier-app\.memb\.ft\.com\/memb\/barrier/,
'brightcove': /^https?:\/\/api\.brightcove\.com\/services\/library/,
'bertha': /^https?:\/\/bertha\.ig\.ft\.com/,
'markets': /^https?:\/\/markets\.ft\.com/,
'fastly': /^https?:\/\/next\.ft\.com/,
'fastly-api': /^https?:\/\/api\.fastly\.com/,
'ft-next-harrier-eu': /^https?:\/\/ft-next-harrier-eu\.herokuapp\.com\//,
'ft-next-personalised-feed-api': /^https?:\/\/(personalised-feed\.ft\.com|ft-next-personalised-feed-api\.herokuapp\.com)\/v1\/feed/,
'portfolio': /https?\:\/\/(?:209\.234\.235\.243|portfolio\.ft\.com)/,
'graphite': /^https?:\/\/www\.hostedgraphite\.com\//,
'ft-next-sharedcount-api': /^https?:\/\/ft-next-sharedcount-api\.herokuapp\.com/,
'next-sapi-capi-slurp': /https?\:\/\/next-slurp\.ft\.com/,
'spoor-uuid-counter': /https?\:\/\/spoor-uuid-counter\.herokuapp\.com/,
'spoor-ingest': /https?:\/\/spoor-api\.ft\.com\/ingest/,
'livefyre': /https?\:\/\/ft.bootstrap.fyre.co/,
'ft-next-myft-api': /https?\:\/\/ft-next-myft-api\.herokuapp\.com/,
'myft-api': /https?:\/\/myft-api\.ft\.com/,
'ft-next-service-registry': /http\:\/\/next-registry\.ft\.com/,
'pingdom': /https\:\/\/api\.pingdom\.com/,
'popular': /https?:\/\/mostpopular\.sp\.ft-static.com/,
'popular-topics': /https?:\/\/ft-next-popular-api\.herokuapp\.com/,
'konstructor': /https?:\/\/konstructor\.ft\.com/,
'video': /https?:\/\/next-video\.ft\.com/,
's3o': /https?:\/\/s3o.ft.com/,
'graphql-api': /^https?:\/\/next-graphql-api\.ft\.com/,
//Used for next-article healthcheck
'session-user-data': /^https?:\/\/session-user-data.webservices.ft.com/
};

0 comments on commit 51ad874

Please sign in to comment.