Comparing version 2.0.0 to 2.1.0
@@ -5,2 +5,12 @@ # Changelog | ||
## [2.1.0](https://github.com/nodeshift/opossum/compare/v2.0.0...v2.1.0) (2019-06-12) | ||
### Features | ||
* add function to get metrics for all circuits ([#328](https://github.com/nodeshift/opossum/issues/328)) ([ff29f2e](https://github.com/nodeshift/opossum/commit/ff29f2e)) | ||
* Add original function parameters to the failure and timeout events ([#326](https://github.com/nodeshift/opossum/issues/326)) ([f8918c4](https://github.com/nodeshift/opossum/commit/f8918c4)), closes [#324](https://github.com/nodeshift/opossum/issues/324) | ||
## [2.0.0](https://github.com/nodeshift/opossum/compare/v1.11.1...v2.0.0) (2019-06-05) | ||
@@ -18,4 +28,7 @@ | ||
### Breaking Changes | ||
* `health-check-failed` and `semaphore-locked` events have been changed to `healthCheckFailed` and `semaphoreLocked` respectively | ||
### [1.11.1](https://github.com/nodeshift/opossum/compare/v1.11.0...v1.11.1) (2019-05-22) | ||
@@ -22,0 +35,0 @@ |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.circuitBreaker=t():e.circuitBreaker=t()}(global,function(){return function(e){var t={};function s(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,r){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(r,i,function(t){return e[t]}.bind(null,i));return r},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=13)}([function(e,t,s){"use strict";const r=s(3),{globalRegistry:i}=s(1),n="gauge",{isDate:o,setValue:a,getPropertiesFromObj:c,getLabels:l,hashObject:u,isObject:h,printDeprecationObjectConstructor:p,removeLabels:m}=s(2),{validateMetricName:f,validateLabel:d,validateLabelName:g}=s(4);function _(e){return()=>{const t=Date.now()/1e3;void 0===e?this.set(t):this.set(e,t)}}function b(e){return()=>{const t=process.hrtime();return s=>{const r=process.hrtime(t);this.set(Object.assign({},e,s),r[0]+r[1]/1e9)}}}function y(e){return(t,s)=>{const r=x(e,t);this.set(r.labels,this._getValue(r.labels)-(r.value||1),s)}}function v(e){return(t,s)=>{const r=x(e,t);this.set(r.labels,this._getValue(r.labels)+(r.value||1),s)}}function w(e){return(t,s)=>{if("number"!=typeof t)throw new TypeError(`Value is not a valid number: ${r.format(t)}`);if(s&&!o(s)&&!Number.isFinite(s))throw new TypeError(`Timestamp is not a valid date or number: ${r.format(s)}`);e=e||{},d(this.labelNames,e),this.hashMap=a(this.hashMap,t,e,s)}}function x(e,t){return h(e)?{labels:e,value:t}:{value:e,labels:{}}}e.exports=class{constructor(e,t,s){let r;if(h(e)?(r=Object.assign({labelNames:[]},e)).registers||(r.registers=[i]):(p(),r={name:e,help:t,labelNames:s,registers:[i]}),!r.help)throw new Error("Missing mandatory help parameter");if(!r.name)throw new Error("Missing mandatory name parameter");if(!f(r.name))throw new Error("Invalid metric name");if(!g(r.labelNames))throw new Error("Invalid label name");this.name=r.name,this.labelNames=r.labelNames||[],this.reset(),this.help=r.help,this.aggregator=r.aggregator||"sum",r.registers.forEach(e=>e.registerMetric(this))}set(e,t,s){return h(e)?w.call(this,e)(t,s):w.call(this,null)(e,t)}reset(){return function(){this.hashMap={},0===this.labelNames.length&&(this.hashMap=a({},0,{}))}.call(this)}inc(e,t,s){v.call(this,e)(t,s)}dec(e,t,s){y.call(this,e)(t,s)}setToCurrentTime(e){return _.call(this,e)()}startTimer(e){return b.call(this,e)()}get(){return{help:this.help,name:this.name,type:n,values:c(this.hashMap),aggregator:this.aggregator}}_getValue(e){const t=u(e||{});return this.hashMap[t]?this.hashMap[t].value:0}labels(){const e=l(this.labelNames,arguments);return{inc:v.call(this,e),dec:y.call(this,e),set:w.call(this,e),setToCurrentTime:_.call(this,e),startTimer:b.call(this,e)}}remove(){const e=l(this.labelNames,arguments);m.call(this,this.hashMap,e)}}},function(e,t,s){"use strict";const{getValueAsString:r}=s(2);function i(e){return e.replace(/\n/g,"\\n").replace(/\\(?!n)/g,"\\\\")}const n={timestamps:!0};class o{constructor(){this._metrics={},this._defaultLabels={}}getMetricsAsArray(){return Object.keys(this._metrics).map(this.getSingleMetric,this)}getMetricAsPrometheusString(e,t){const s=Object.assign({},n,t),o=e.get(),a=i(o.name),c=`# HELP ${a} ${i(o.help)}`,l=`# TYPE ${a} ${o.type}`,u=Object.keys(this._defaultLabels);let h="";for(const e of o.values||[]){e.labels=e.labels||{};for(const t of u)e.labels[t]=e.labels[t]||this._defaultLabels[t];let t="";for(const s of Object.keys(e.labels))t+=`${s}="${p=e.labels[s],"string"!=typeof p?p:i(p).replace(/"/g,'\\"')}",`;let n=e.metricName||o.name;t&&(n+=`{${t.substring(0,t.length-1)}}`);let a=`${n} ${r(e.value)}`;s.timestamps&&e.timestamp&&(a+=` ${e.timestamp}`),h+=`${a.trim()}\n`}var p;return`${c}\n${l}\n${h}`.trim()}metrics(e){let t="";for(const s of this.getMetricsAsArray())t+=`${this.getMetricAsPrometheusString(s,e)}\n\n`;return t.substring(0,t.length-1)}registerMetric(e){if(this._metrics[e.name]&&this._metrics[e.name]!==e)throw new Error(`A metric with the name ${e.name} has already been registered.`);this._metrics[e.name]=e}clear(){this._metrics={},this._defaultLabels={}}getMetricsAsJSON(){const e=[],t=Object.keys(this._defaultLabels);for(const s of this.getMetricsAsArray()){const r=s.get();if(r.values)for(const e of r.values)for(const s of t)e.labels[s]=e.labels[s]||this._defaultLabels[s];e.push(r)}return e}removeSingleMetric(e){delete this._metrics[e]}getSingleMetricAsString(e){return this.getMetricAsPrometheusString(this._metrics[e])}getSingleMetric(e){return this._metrics[e]}setDefaultLabels(e){this._defaultLabels=e}resetMetrics(){for(const e in this._metrics)this._metrics[e].reset()}get contentType(){return"text/plain; version=0.0.4; charset=utf-8"}static merge(e){const t=new o;return e.reduce((e,t)=>e.concat(t.getMetricsAsArray()),[]).forEach(t.registerMetric,t),t}}e.exports=o,e.exports.globalRegistry=new o},function(e,t,s){"use strict";const r={};function i(e){let t=Object.keys(e);if(0===t.length)return"";t.length>1&&(t=t.sort());let s="",r=0;const i=t.length;for(;r<i-1;r++)s+=`${t[r]}:${e[t[r]]},`;return s+=`${t[r]}:${e[t[r]]}`}function n(e){return e instanceof Date&&!isNaN(e.valueOf())}function o(e){r[e]||(r[e]=!0,process.emitWarning?process.emitWarning(e,"DeprecationWarning"):console.warn(new Error(e)))}t.isDate=n,t.getPropertiesFromObj=function(e){return Object.keys(e).map(t=>e[t])},t.getValueAsString=function(e){return Number.isNaN(e)?"Nan":Number.isFinite(e)?`${e}`:e<0?"-Inf":"+Inf"},t.removeLabels=function(e,t){delete e[i(t)]},t.setValue=function(e,t,s,r){return e[i(s)]={value:"number"==typeof t?t:0,labels:s||{},timestamp:n(r)?r.valueOf():Number.isFinite(r)?r:void 0},e},t.getLabels=function(e,t){if(e.length!==t.length)throw new Error("Invalid number of arguments");const s=Array.prototype.slice.call(t);return e.reduce((e,t,r)=>(e[t]=s[r],e),{})},t.hashObject=i,t.isObject=function(e){return e===Object(e)},t.printDeprecationObjectConstructor=(()=>{o("prom-client - Passing a non-object to metrics constructor is deprecated")}),t.printDeprecationCollectDefaultMetricsNumber=(e=>{o(`prom-client - A number to defaultMetrics is deprecated, please use \`collectDefaultMetrics({ timeout: ${e} })\`.`)});t.Grouper=class extends Map{add(e,t){this.has(e)?this.get(e).push(t):this.set(e,[t])}}},function(e,t){e.exports=require("util")},function(e,t,s){"use strict";const r=s(3),i=/^[a-zA-Z_:][a-zA-Z0-9_:]*$/,n=/^[a-zA-Z_][a-zA-Z0-9_]*$/;t.validateMetricName=function(e){return i.test(e)},t.validateLabelName=function(e){let t=!0;return(e||[]).forEach(e=>{n.test(e)||(t=!1)}),t},t.validateLabel=function(e,t){Object.keys(t).forEach(t=>{if(-1===e.indexOf(t))throw new Error(`Added label "${t}" is not included in initial labelset: ${r.inspect(e)}`)})}},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("events")},function(e,t,s){"use strict";const{Transform:r,Readable:i}=s(16),n=s(17),o=new r({objectMode:!0,transform:(e,t,s)=>s(null,`data: ${JSON.stringify(n(e))}\n\n`)});o.resume();class a{constructor(e){this._readableStream=new i({objectMode:!0,read(){}}),e.status.on("snapshot",function(t){this._readableStream.push(Object.assign({},{name:e.name,closed:e.closed,group:e.group,options:e.options},t))}.bind(this)),this._readableStream.resume(),this._readableStream.pipe(o)}getHystrixStream(){return o}shutdown(){this._readableStream.unpipe(o)}}a.stream=o,e.exports=a},function(e,t,s){"use strict";const r=s(3),{globalRegistry:i}=s(1),n="counter",{isDate:o,getPropertiesFromObj:a,hashObject:c,isObject:l,printDeprecationObjectConstructor:u,getLabels:h,removeLabels:p}=s(2),{validateLabel:m,validateMetricName:f,validateLabelName:d}=s(4);const g=function(){this.hashMap={},0===this.labelNames.length&&(this.hashMap=b({},0))},_=function(e,t){return(s,i)=>{if(s&&!Number.isFinite(s))throw new TypeError(`Value is not a valid number: ${r.format(s)}`);if(i&&!o(i)&&!Number.isFinite(i))throw new TypeError(`Timestamp is not a valid date or number: ${r.format(i)}`);if(s<0)throw new Error("It is not possible to decrease a counter");e=e||{},m(this.labelNames,e);const n=null==s?1:s;this.hashMap=b(this.hashMap,n,i,e,t)}};function b(e,t,s,r,i){return i=i||"",s=o(s)?s.valueOf():Number.isFinite(s)?s:void 0,e[i]?(e[i].value+=t,e[i].timestamp=s):e[i]={value:t,labels:r||{},timestamp:s},e}e.exports=class{constructor(e,t,s){let r;if(l(e)?(r=Object.assign({labelNames:[]},e)).registers||(r.registers=[i]):(u(),r={name:e,help:t,labelNames:s,registers:[i]}),!r.help)throw new Error("Missing mandatory help parameter");if(!r.name)throw new Error("Missing mandatory name parameter");if(!f(r.name))throw new Error("Invalid metric name");if(!d(r.labelNames))throw new Error("Invalid label name");this.name=r.name,this.labelNames=r.labelNames||[],this.reset(),this.help=r.help,this.aggregator=r.aggregator||"sum",r.registers.forEach(e=>e.registerMetric(this))}inc(e,t,s){if(!l(e))return _.call(this,null)(e,t);const r=c(e);return _.call(this,e,r)(t,s)}reset(){return g.call(this)}get(){return{help:this.help,name:this.name,type:n,values:a(this.hashMap),aggregator:this.aggregator}}labels(){const e=h(this.labelNames,arguments)||{},t=c(e);return m(this.labelNames,e),{inc:_.call(this,e,t)}}remove(){const e=h(this.labelNames,arguments)||{};return p.call(this,this.hashMap,e)}}},function(e,t){function s(){}function r(e){this._tree=e,this._ancestors=[],this._cursor=null}s.prototype.clear=function(){this._root=null,this.size=0},s.prototype.find=function(e){for(var t=this._root;null!==t;){var s=this._comparator(e,t.data);if(0===s)return t.data;t=t.get_child(s>0)}return null},s.prototype.findIter=function(e){for(var t=this._root,s=this.iterator();null!==t;){var r=this._comparator(e,t.data);if(0===r)return s._cursor=t,s;s._ancestors.push(t),t=t.get_child(r>0)}return null},s.prototype.lowerBound=function(e){for(var t=this._root,s=this.iterator(),r=this._comparator;null!==t;){var i=r(e,t.data);if(0===i)return s._cursor=t,s;s._ancestors.push(t),t=t.get_child(i>0)}for(var n=s._ancestors.length-1;n>=0;--n)if(r(e,(t=s._ancestors[n]).data)<0)return s._cursor=t,s._ancestors.length=n,s;return s._ancestors.length=0,s},s.prototype.upperBound=function(e){for(var t=this.lowerBound(e),s=this._comparator;null!==t.data()&&0===s(t.data(),e);)t.next();return t},s.prototype.min=function(){var e=this._root;if(null===e)return null;for(;null!==e.left;)e=e.left;return e.data},s.prototype.max=function(){var e=this._root;if(null===e)return null;for(;null!==e.right;)e=e.right;return e.data},s.prototype.iterator=function(){return new r(this)},s.prototype.each=function(e){for(var t,s=this.iterator();null!==(t=s.next());)e(t)},s.prototype.reach=function(e){for(var t,s=this.iterator();null!==(t=s.prev());)e(t)},r.prototype.data=function(){return null!==this._cursor?this._cursor.data:null},r.prototype.next=function(){if(null===this._cursor){var e=this._tree._root;null!==e&&this._minNode(e)}else{var t;if(null===this._cursor.right)do{if(t=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.right===t);else this._ancestors.push(this._cursor),this._minNode(this._cursor.right)}return null!==this._cursor?this._cursor.data:null},r.prototype.prev=function(){if(null===this._cursor){var e=this._tree._root;null!==e&&this._maxNode(e)}else{var t;if(null===this._cursor.left)do{if(t=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.left===t);else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left)}return null!==this._cursor?this._cursor.data:null},r.prototype._minNode=function(e){for(;null!==e.left;)this._ancestors.push(e),e=e.left;this._cursor=e},r.prototype._maxNode=function(e){for(;null!==e.right;)this._ancestors.push(e),e=e.right;this._cursor=e},e.exports=s},function(e,t,s){"use strict";t.linearBuckets=((e,t,s)=>{if(s<1)throw new Error("Linear buckets needs a positive count");const r=new Array(s);for(let i=0;i<s;i++)r[i]=e,e+=t;return r}),t.exponentialBuckets=((e,t,s)=>{if(e<=0)throw new Error("Exponential buckets needs a positive start");if(s<1)throw new Error("Exponential buckets needs a positive count");if(t<=1)throw new Error("Exponential buckets needs a factor greater than 1");const r=new Array(s);for(let i=0;i<s;i++)r[i]=e,e*=t;return r})},function(e,t,s){"use strict";e.exports=function(){let e;try{e=process.memoryUsage()}catch(e){}return e}},function(e,t,s){"use strict";const{Grouper:r,hashObject:i}=s(2);function n(e){return t=>{if(0===t.length)return;const s={help:t[0].help,name:t[0].name,type:t[0].type,values:[],aggregator:t[0].aggregator},n=new r;return t.forEach(e=>{e.values.forEach(e=>{const t=i(e.labels);n.add(`${e.metricName}_${t}`,e)})}),n.forEach(t=>{if(0===t.length)return;const r={value:e(t),labels:t[0].labels};t[0].metricName&&(r.metricName=t[0].metricName),s.values.push(r)}),s}}t.AggregatorFactory=n,t.aggregators={sum:n(e=>e.reduce((e,t)=>e+t.value,0)),first:n(e=>e[0].value),omit:()=>{},average:n(e=>e.reduce((e,t)=>e+t.value,0)/e.length),min:n(e=>e.reduce((e,t)=>Math.min(e,t.value),1/0)),max:n(e=>e.reduce((e,t)=>Math.max(e,t.value),-1/0))}},function(e,t,s){"use strict";const r=s(14),i={timeout:1e4,errorThresholdPercentage:50,resetTimeout:3e4};function n(e,t){return new r(e,Object.assign({},i,t))}n.promisify=s(49);let o=!1;Object.defineProperty(n,"stats",{get:e=>(o||(o=!0,console.warn("WARNING: Hystrics stats are deprecated\n See: https://github.com/Netflix/Hystrix#dashboard")),s(7).stream)}),e.exports=n,e.exports.default=n},function(e,t,s){"use strict";const r=s(6),i=s(15),n=s(7),o=s(18);let a;process.env.WEB||(a=s(19));const c=Symbol("state"),l=Symbol("open"),u=Symbol("closed"),h=Symbol("half-open"),p=Symbol("pending-close"),m=Symbol("shutdown"),f=Symbol("fallback"),d=Symbol("status"),g=Symbol("name"),_=Symbol("group"),b=Symbol("hystrix-stats"),y=Symbol("prometheus-metrics"),v=new WeakMap,w=Symbol("Enabled"),x=Symbol("warming-up"),N=Symbol("volume-threshold"),E="options.maxFailures is deprecated. Please use options.errorThresholdPercentage";let M=!1;class j extends r{constructor(e,t){if(super(),this.options=t,this.options.rollingCountTimeout=t.rollingCountTimeout||1e4,this.options.rollingCountBuckets=t.rollingCountBuckets||10,this.options.rollingPercentilesEnabled=!1!==t.rollingPercentilesEnabled,this.options.capacity=Number.isInteger(t.capacity)?t.capacity:Number.MAX_SAFE_INTEGER,this.options.errorFilter=t.errorFilter||(e=>!1),this.semaphore=new o(this.options.capacity),this[N]=Number.isInteger(t.volumeThreshold)?t.volumeThreshold:0,this[x]=!0===t.allowWarmUp,this[d]=new i(this.options),this[c]=u,this[f]=null,this[p]=!1,this[g]=t.name||e.name||O(),this[_]=t.group||this[g],this[w]=!1!==t.enabled,this[x]){const e=setTimeout(e=>this[x]=!1,this.options.rollingCountTimeout);"function"==typeof e.unref&&e.unref()}this.action="function"!=typeof e?t=>Promise.resolve(e):e,t.maxFailures&&console.error(E);const s=e=>(t,s)=>this[d].increment(e,s);var r;this.on("success",s("successes")),this.on("failure",s("failures")),this.on("fallback",s("fallbacks")),this.on("timeout",s("timeouts")),this.on("fire",s("fires")),this.on("reject",s("rejects")),this.on("cacheHit",s("cacheHits")),this.on("cacheMiss",s("cacheMisses")),this.on("open",e=>this[d].open()),this.on("close",e=>this[d].close()),this.on("semaphoreLocked",s("semaphoreRejections")),this.on("open",(r=this,e=>{const t=setTimeout(()=>{r[c]=h,r[p]=!0,r.emit("halfOpen",r.options.resetTimeout)},r.options.resetTimeout);"function"==typeof t.unref&&t.unref()})),this.on("success",e=>this.close()),this.options.cache&&v.set(this,void 0),this[b]=new n(this),a&&t.usePrometheus&&(this[y]=new a(this))}close(){this[p]=!1,this[c]!==u&&(this[c]=u,this.emit("close"))}open(){this[p]=!1,this[c]!==l&&(this[c]=l,this.emit("open"))}shutdown(){this.disable(),this.removeAllListeners(),this.status.shutdown(),this.hystrixStats.shutdown(),this.metrics&&this.metrics.clear(),this[c]=m}get isShutdown(){return this[c]===m}get name(){return this[g]}get group(){return this[_]}get pendingClose(){return this[p]}get closed(){return this[c]===u}get opened(){return this[c]===l}get halfOpen(){return this[c]===h}get status(){return this[d]}get stats(){return this[d].stats}get hystrixStats(){return M||(M=!0,console.warn("WARNING: Hystrics stats are deprecated\n See: https://github.com/Netflix/Hystrix#dashboard")),this[b]}get metrics(){return this[y]}get enabled(){return this[w]}get warmUp(){return this[x]}get volumeThreshold(){return this[N]}fallback(e){let t=e;return e instanceof j&&(t=function(){return e.fire.apply(e,arguments)}),this[f]=t,this}fire(){if(this.isShutdown){const e=new Error("The circuit has been shutdown.");return e.code="ESHUTDOWN",Promise.reject(e)}const e=Array.prototype.slice.call(arguments);if(this.emit("fire",e),void 0!==v.get(this))return this.emit("cacheHit"),v.get(this);if(this.options.cache&&this.emit("cacheMiss"),!this[w]){const t=this.action.apply(this.action,e);return"function"==typeof t.then?t:Promise.resolve(t)}if(!this.closed&&!this.pendingClose){const t=new Error("Breaker is open");return t.code="EOPENBREAKER",this.emit("reject",t),k(this,t,e)||Promise.reject(t)}let t;this[p]=!1;let s=!1;return new Promise((r,i)=>{const n=Date.now();if(this.semaphore.test()){this.options.timeout&&(t=setTimeout(()=>{s=!0;const o=new Error(`Timed out after ${this.options.timeout}ms`);o.code="ETIMEDOUT";const a=Date.now()-n;this.semaphore.release(),this.emit("timeout",o,a),r(T(o,this,t,e,a,r,i))},this.options.timeout));try{const o=this.action.apply(this.action,e),a="function"==typeof o.then?o:Promise.resolve(o);a.then(e=>{s||(clearTimeout(t),this.emit("success",e,Date.now()-n),this.semaphore.release(),r(e),this.options.cache&&v.set(this,a))}).catch(o=>{if(!s){this.semaphore.release();const s=Date.now()-n;T(o,this,t,e,s,r,i)}})}catch(s){this.semaphore.release();const o=Date.now()-n;T(s,this,t,e,o,r,i)}}else{const s=Date.now()-n,o=new Error("Semaphore locked");o.code="ESEMLOCKED",this.emit("semaphoreLocked",o,s),T(o,this,t,e,s,r,i)}})}clearCache(){v.set(this,void 0)}healthCheck(e,t){if(t=t||5e3,"function"!=typeof e)throw new TypeError("Health check function must be a function");if(isNaN(t))throw new TypeError("Health check interval must be a number");const s=t=>{e.apply(this).catch(e=>{this.emit("healthCheckFailed",e),this.open()})},r=setInterval(s,t);"function"==typeof r.unref&&r.unref(),s()}enable(){this[w]=!0}disable(){this[w]=!1}}function T(e,t,s,r,i,n,o){clearTimeout(s),function(e,t,s,r){if(e.options.errorFilter(t))return;if(e.emit("failure",t,r),e.warmUp)return;const i=e.stats;if(i.fires<e.volumeThreshold&&!e.halfOpen)return;(i.failures/i.fires*100>e.options.errorThresholdPercentage||i.failures>=e.options.maxFailures||e.halfOpen)&&e.open()}(t,e,0,i);const a=k(t,e,r);a?n(a):o(e)}function k(e,t,s){if(e[f]){const r=e[f].apply(e[f],[...s,t]);return e.emit("fallback",r,t),r instanceof Promise?r:Promise.resolve(r)}}const O=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});e.exports=j},function(e,t,s){"use strict";const r=Symbol("window"),i=Symbol("buckets"),n=Symbol("timeout"),o=Symbol("percentiles"),a=s(6).EventEmitter;const c=e=>t=>{e.pop(),e.unshift(l())},l=e=>({failures:0,fallbacks:0,successes:0,rejects:0,fires:0,timeouts:0,cacheHits:0,cacheMisses:0,semaphoreRejections:0,percentiles:{},latencyTimes:[]});e.exports=class extends a{constructor(e){super(),this[i]=e.rollingCountBuckets,this[n]=e.rollingCountTimeout,this[r]=new Array(this[i]),this[o]=[0,.25,.5,.75,.9,.95,.99,.995,1],this.rollingPercentilesEnabled=e.rollingPercentilesEnabled;for(let e=0;e<this[i];e++)this[r][e]=l();const t=Math.floor(this[n]/this[i]);let s=setInterval(c(this[r]),t);"function"==typeof s.unref&&s.unref(),"function"==typeof(s=setInterval(e=>this.emit("snapshot",this.stats),t)).unref&&s.unref()}get stats(){const e=this[r].reduce((e,t)=>t?(Object.keys(e).forEach(s=>{"latencyTimes"!==s&&"percentiles"!==s&&(e[s]+=t[s]||0)}),this.rollingPercentilesEnabled&&e.latencyTimes.push.apply(e.latencyTimes,t.latencyTimes||[]),e):e,l());return this.rollingPercentilesEnabled?(e.latencyTimes.sort((e,t)=>e-t),e.latencyTimes.length?e.latencyMean=e.latencyTimes.reduce((e,t)=>e+t,0)/e.latencyTimes.length:e.latencyMean=0,this[o].forEach(t=>{e.percentiles[t]=function(e,t){if(0===e)return t[0]||0;const s=Math.ceil(e*t.length);return t[s-1]||0}(t,e.latencyTimes)})):(e.latencyMean=-1,this[o].forEach(t=>{e.percentiles[t]=-1})),e}get window(){return this[r].slice()}increment(e,t){this[r][0][e]++,"successes"!==e&&"failures"!==e&&"timeouts"!==e||this[r][0].latencyTimes.push(t||0)}open(){this[r][0].isCircuitBreakerOpen=!0}close(){this[r][0].isCircuitBreakerOpen=!1}shutdown(){this.removeAllListeners()}}},function(e,t){e.exports=require("stream")},function(e,t,s){"use strict";function r(e){return{0:e.percentiles[0],25:e.percentiles[.25],50:e.percentiles[.5],75:e.percentiles[.75],90:e.percentiles[.9],95:e.percentiles[.95],99:e.percentiles[.99],99.5:e.percentiles[.995],100:e.percentiles[1]}}e.exports=function(e){return{type:"HystrixCommand",name:e.name,group:e.group,currentTime:Date.now(),isCircuitBreakerOpen:!e.closed,errorPercentage:0===e.fires?0:e.failures/e.fires*100,errorCount:e.failures,requestCount:e.fires,rollingCountBadRequests:e.failures,rollingCountCollapsedRequests:0,rollingCountEmit:e.fires,rollingCountExceptionsThrown:0,rollingCountFailure:e.failures,rollingCountFallbackEmit:e.fallbacks,rollingCountFallbackFailure:0,rollingCountFallbackMissing:0,rollingCountFallbackRejection:0,rollingCountFallbackSuccess:0,rollingCountResponsesFromCache:e.cacheHits,rollingCountSemaphoreRejected:e.semaphoreRejections,rollingCountShortCircuited:e.rejects,rollingCountSuccess:e.successes,rollingCountThreadPoolRejected:0,rollingCountTimeout:e.timeouts,currentConcurrentExecutionCount:0,rollingMaxConcurrentExecutionCount:0,latencyExecute_mean:e.latencyMean||0,latencyExecute:r(e),latencyTotal_mean:e.latencyMean,latencyTotal:r(e),propertyValue_circuitBreakerRequestVolumeThreshold:5,propertyValue_circuitBreakerSleepWindowInMilliseconds:e.options.resetTimeout,propertyValue_circuitBreakerErrorThresholdPercentage:e.options.errorThresholdPercentage,propertyValue_circuitBreakerForceOpen:!1,propertyValue_circuitBreakerForceClosed:!1,propertyValue_circuitBreakerEnabled:!0,propertyValue_executionIsolationStrategy:"THREAD",propertyValue_executionIsolationThreadTimeoutInMilliseconds:300,propertyValue_executionTimeoutInMilliseconds:e.options.timeout,propertyValue_executionIsolationThreadInterruptOnTimeout:!0,propertyValue_executionIsolationThreadPoolKeyOverride:null,propertyValue_executionIsolationSemaphoreMaxConcurrentRequests:e.options.capacity,propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests:e.options.capacity,propertyValue_metricsRollingStatisticalWindowInMilliseconds:1e4,propertyValue_requestCacheEnabled:e.options.cache||!1,propertyValue_requestLogEnabled:!0,reportingHosts:1}}},function(e,t,s){"use strict";e.exports=function(e){const t=[];let s=e,r={take:i,release:n,test:function(){return!(s<1)&&i()&&!0}};return Object.defineProperty(r,"count",{get:e=>s,enumerable:!0}),r;function i(e){return s>0?(--s,Promise.resolve(n)):new Promise((r,i)=>{t.push(e=>{--s,r(n)}),e&&setTimeout(s=>{t.shift();const r=new Error(`Timed out after ${e}ms`);r.code="ETIMEDOUT",i(r)},e)})}function n(){s++,t.length>0&&t.shift()()}}},function(e,t,s){"use strict";const r=s(20);e.exports=class{constructor(e){this.circuit=e,this._client=r,this.counters=[];const t=`circuit_${this.circuit.name.replace(/[ |-]/g,"_")}_`;this.interval=this._client.collectDefaultMetrics({prefix:t,timeout:5e3});for(let s of this.circuit.eventNames()){const r=new this._client.Counter({name:`${t}${s}`,help:`A count of the ${e.name} circuit's ${s} event`});this.circuit.on(s,e=>{r.inc()}),this.counters.push(r)}}clear(){clearInterval(this.interval),this._client.register.clear()}get metrics(){return this._client.register.metrics()}get client(){return this._client}}},function(e,t,s){"use strict";t.register=s(1).globalRegistry,t.Registry=s(1),t.contentType=s(1).globalRegistry.contentType,t.Counter=s(8),t.Gauge=s(0),t.Histogram=s(21),t.Summary=s(22),t.Pushgateway=s(28),t.linearBuckets=s(10).linearBuckets,t.exponentialBuckets=s(10).exponentialBuckets,t.collectDefaultMetrics=s(32),t.aggregators=s(12).aggregators,t.AggregatorRegistry=s(47)},function(e,t,s){"use strict";const r=s(3),i=s(1).globalRegistry,n="histogram",{getPropertiesFromObj:o,getLabels:a,hashObject:c,isObject:l,printDeprecationObjectConstructor:u,removeLabels:h}=s(2),{validateMetricName:p,validateLabel:m,validateLabelName:f}=s(4);function d(e){return()=>{const t=process.hrtime();return s=>{const r=process.hrtime(t);this.observe(Object.assign({},e,s),r[0]+r[1]/1e9)}}}function g(e,t){return e-t}function _(e,t,s){return{labels:e,value:t,metricName:s}}function b(e){return t=>{const s=function(e,t){if(!l(e))return{value:e,labels:{}};return{labels:e,value:t}}(e,t);if(m(this.labelNames,s.labels),!Number.isFinite(s.value))throw new TypeError(`Value is not a valid number: ${r.format(s.value)}`);const i=c(s.labels);let n=this.hashMap[i];n||(n=y(s.labels,Object.assign({},this.bucketValues)));const o=function(e,t){for(let s=0;s<e.length;s++){const r=e[s];if(t<=r)return r}return-1}(this.upperBounds,s.value);n.sum+=s.value,n.count+=1,n.bucketValues.hasOwnProperty(o)&&(n.bucketValues[o]+=1),this.hashMap[i]=n}}function y(e,t){return{labels:e,bucketValues:t,sum:0,count:0}}e.exports=class{constructor(e,t,s,r){let n;if(l(e))(n=Object.assign({buckets:[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],labelNames:[]},e)).registers||(n.registers=[i]);else{let a,c=[];Array.isArray(s)?(a=r||{},c=s):a=s||{},u(),n={name:e,labelNames:c,help:t,buckets:(o=a.buckets,[].concat(o||[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10]).sort(g)),registers:[i]}}var o;!function(e,t,s){if(!t)throw new Error("Missing mandatory help parameter");if(!e)throw new Error("Missing mandatory name parameter");if(!p(e))throw new Error("Invalid metric name");if(!f(s))throw new Error("Invalid label name");s.forEach(e=>{if("le"===e)throw new Error("le is a reserved label keyword")})}(n.name,n.help,n.labelNames),this.name=n.name,this.help=n.help,this.aggregator=n.aggregator||"sum",this.upperBounds=n.buckets,this.bucketValues=this.upperBounds.reduce((e,t)=>(e[t]=0,e),{}),Object.freeze(this.bucketValues),Object.freeze(this.upperBounds),this.sum=0,this.count=0,this.hashMap={},this.labelNames=n.labelNames||[],0===this.labelNames.length&&(this.hashMap={[c({})]:y({},Object.assign({},this.bucketValues))}),n.registers.forEach(e=>e.registerMetric(this))}observe(e,t){b.call(this,0===e?0:e||{})(t)}get(){const e=o(this.hashMap).map((t=this,e=>{const s=[],r=Object.keys(e.labels);let i=0;for(const n of t.upperBounds){i+=e.bucketValues[n];const o={le:n};for(const t of r)o[t]=e.labels[t];s.push(_(o,i,`${t.name}_bucket`))}return{buckets:s,data:e}})).reduce(function(e){return(t,s)=>{t.push(...s.buckets);const r={le:"+Inf"};for(const e of Object.keys(s.data.labels))r[e]=s.data.labels[e];return t.push(_(r,s.data.count,`${e.name}_bucket`),_(s.data.labels,s.data.sum,`${e.name}_sum`),_(s.data.labels,s.data.count,`${e.name}_count`)),t}}(this),[]);var t;return{name:this.name,help:this.help,type:n,values:e,aggregator:this.aggregator}}reset(){this.sum=0,this.count=0,this.hashMap={}}startTimer(e){return d.call(this,e)()}labels(){const e=a(this.labelNames,arguments);return{observe:b.call(this,e),startTimer:d.call(this,e)}}remove(){const e=a(this.labelNames,arguments);h.call(this,this.hashMap,e)}}},function(e,t,s){"use strict";const r=s(3),{globalRegistry:i}=s(1),n="summary",{getPropertiesFromObj:o,getLabels:a,hashObject:c,isObject:l,printDeprecationObjectConstructor:u,removeLabels:h}=s(2),{validateLabel:p,validateMetricName:m,validateLabelName:f}=s(4),d=s(23);function g(e){return()=>{const t=process.hrtime();return s=>{const r=process.hrtime(t);this.observe(Object.assign({},e,s),r[0]+r[1]/1e9)}}}function _(e,t){return e-t}function b(e){return t=>{const s=function(e,t){if(void 0===t)return{value:e,labels:{}};return{labels:e,value:t}}(e,t);if(p(this.labelNames,this.labels),!Number.isFinite(s.value))throw new TypeError(`Value is not a valid number: ${r.format(s.value)}`);const i=c(s.labels);let n=this.hashMap[i];n||(n={labels:s.labels,td:new d(this.maxAgeSeconds,this.ageBuckets),count:0,sum:0}),n.td.push(s.value),n.count++,n.sum+=s.value,this.hashMap[i]=n}}e.exports=class{constructor(e,t,s,r){let n;if(l(e))(n=Object.assign({percentiles:[.01,.05,.5,.9,.95,.99,.999],labelNames:[]},e)).registers||(n.registers=[i]);else{let a,c=[];Array.isArray(s)?(a=r||{},c=s):a=s||{},u(),n={name:e,help:t,labelNames:c,percentiles:(o=a.percentiles,[].concat(o||[.01,.05,.5,.9,.95,.99,.999]).sort(_)),registers:[i],maxAgeSeconds:a.maxAgeSeconds,ageBuckets:a.ageBuckets}}var o;!function(e,t,s){if(!t)throw new Error("Missing mandatory help parameter");if(!e)throw new Error("Missing mandatory name parameter");if(!m(e))throw new Error("Invalid metric name");if(!f(s))throw new Error("Invalid label name");s.forEach(e=>{if("quantile"===e)throw new Error("quantile is a reserved label keyword")})}(n.name,n.help,n.labelNames),this.maxAgeSeconds=n.maxAgeSeconds,this.ageBuckets=n.ageBuckets,this.name=n.name,this.help=n.help,this.aggregator=n.aggregator||"sum",this.percentiles=n.percentiles,this.hashMap={},this.labelNames=n.labelNames||[],0===this.labelNames.length&&(this.hashMap={[c({})]:{labels:{},td:new d(this.maxAgeSeconds,this.ageBuckets),count:0,sum:0}}),n.registers.forEach(e=>e.registerMetric(this))}observe(e,t){b.call(this,0===e?0:e||{})(t)}get(){const e=o(this.hashMap),t=[];return e.forEach(e=>{(function(e,t){return e.td.compress(),t.map(t=>{const s=e.td.percentile(t);return{labels:Object.assign({quantile:t},e.labels),value:s||0}})})(e,this.percentiles).forEach(e=>{t.push(e)}),t.push(function(e,t){return{metricName:`${t.name}_sum`,labels:e.labels,value:e.sum}}(e,this)),t.push(function(e,t){return{metricName:`${t.name}_count`,labels:e.labels,value:e.count}}(e,this))}),{name:this.name,help:this.help,type:n,values:t,aggregator:this.aggregator}}reset(){o(this.hashMap).forEach(e=>{e.td.reset(),e.count=0,e.sum=0})}startTimer(e){return g.call(this,e)()}labels(){const e=a(this.labelNames,arguments);return{observe:b.call(this,e),startTimer:g.call(this,e)}}remove(){const e=a(this.labelNames,arguments);h.call(this,this.hashMap,e)}}},function(e,t,s){"use strict";const{TDigest:r}=s(24);function i(){let e=Date.now()-this.lastRotateTimestampMillis;for(;e>this.durationBetweenRotatesMillis&&this.shouldRotate;)this.ringBuffer[this.currentBuffer]=new r,++this.currentBuffer>=this.ringBuffer.length&&(this.currentBuffer=0),e-=this.durationBetweenRotatesMillis,this.lastRotateTimestampMillis+=this.durationBetweenRotatesMillis;return this.ringBuffer[this.currentBuffer]}e.exports=class{constructor(e,t){this.maxAgeSeconds=e||0,this.ageBuckets=t||0,this.shouldRotate=e&&t,this.ringBuffer=Array(t).fill(new r),this.currentBuffer=0,this.lastRotateTimestampMillis=Date.now(),this.durationBetweenRotatesMillis=1e3*e/t||1/0}percentile(e){return i.call(this).percentile(e)}push(e){i.call(this),this.ringBuffer.forEach(t=>{t.push(e)})}reset(){this.ringBuffer.forEach(e=>{e.reset()})}compress(){this.ringBuffer.forEach(e=>{e.compress()})}}},function(e,t,s){var r=s(25).RBTree;function i(e,t,s){this.discrete=!1===e,this.delta=e||.01,this.K=void 0===t?25:t,this.CX=void 0===s?1.1:s,this.centroids=new r(n),this.nreset=0,this.reset()}function n(e,t){return e.mean>t.mean?1:e.mean<t.mean?-1:0}function o(e,t){return e.mean_cumn-t.mean_cumn}function a(e){this.config=e||{},this.mode=this.config.mode||"auto",i.call(this,"cont"===this.mode&&e.delta),this.digest_ratio=this.config.ratio||.9,this.digest_thresh=this.config.thresh||1e3,this.n_unique=0}i.prototype.reset=function(){this.centroids.clear(),this.n=0,this.nreset+=1,this.last_cumulate=0},i.prototype.size=function(){return this.centroids.size},i.prototype.toArray=function(e){var t=[];return e?(this._cumulate(!0),this.centroids.each(function(e){t.push(e)})):this.centroids.each(function(e){t.push({mean:e.mean,n:e.n})}),t},i.prototype.summary=function(){return[(this.discrete?"exact ":"approximating ")+this.n+" samples using "+this.size()+" centroids","min = "+this.percentile(0),"Q1 = "+this.percentile(.25),"Q2 = "+this.percentile(.5),"Q3 = "+this.percentile(.75),"max = "+this.percentile(1)].join("\n")},i.prototype.push=function(e,t){t=t||1,e=Array.isArray(e)?e:[e];for(var s=0;s<e.length;s++)this._digest(e[s],t)},i.prototype.push_centroid=function(e){e=Array.isArray(e)?e:[e];for(var t=0;t<e.length;t++)this._digest(e[t].mean,e[t].n)},i.prototype._cumulate=function(e){if(!(this.n===this.last_cumulate||!e&&this.CX&&this.CX>this.n/this.last_cumulate)){var t=0;this.centroids.each(function(e){e.mean_cumn=t+e.n/2,t=e.cumn=t+e.n}),this.n=this.last_cumulate=t}},i.prototype.find_nearest=function(e){if(0===this.size())return null;var t=this.centroids.lowerBound({mean:e}),s=null===t.data()?t.prev():t.data();if(s.mean===e||this.discrete)return s;var r=t.prev();return r&&Math.abs(r.mean-e)<Math.abs(s.mean-e)?r:s},i.prototype._new_centroid=function(e,t,s){var r={mean:e,n:t,cumn:s};return this.centroids.insert(r),this.n+=t,r},i.prototype._addweight=function(e,t,s){t!==e.mean&&(e.mean+=s*(t-e.mean)/(e.n+s)),e.cumn+=s,e.mean_cumn+=s/2,e.n+=s,this.n+=s},i.prototype._digest=function(e,t){var s=this.centroids.min(),r=this.centroids.max(),i=this.find_nearest(e);if(i&&i.mean===e)this._addweight(i,e,t);else if(i===s)this._new_centroid(e,t,0);else if(i===r)this._new_centroid(e,t,this.n);else if(this.discrete)this._new_centroid(e,t,i.cumn);else{var n=i.mean_cumn/this.n;Math.floor(4*this.n*this.delta*n*(1-n))-i.n>=t?this._addweight(i,e,t):this._new_centroid(e,t,i.cumn)}this._cumulate(!1),!this.discrete&&this.K&&this.size()>this.K/this.delta&&this.compress()},i.prototype.bound_mean=function(e){var t=this.centroids.upperBound({mean:e}),s=t.prev();return[s,s.mean===e?s:t.next()]},i.prototype.p_rank=function(e){var t=(Array.isArray(e)?e:[e]).map(this._p_rank,this);return Array.isArray(e)?t:t[0]},i.prototype._p_rank=function(e){if(0!==this.size()){if(e<this.centroids.min().mean)return 0;if(e>this.centroids.max().mean)return 1;this._cumulate(!0);var t=this.bound_mean(e),s=t[0],r=t[1];if(this.discrete)return s.cumn/this.n;var i=s.mean_cumn;return s!==r&&(i+=(e-s.mean)*(r.mean_cumn-s.mean_cumn)/(r.mean-s.mean)),i/this.n}},i.prototype.bound_mean_cumn=function(e){this.centroids._comparator=o;var t=this.centroids.upperBound({mean_cumn:e});this.centroids._comparator=n;var s=t.prev();return[s,s&&s.mean_cumn===e?s:t.next()]},i.prototype.percentile=function(e){var t=(Array.isArray(e)?e:[e]).map(this._percentile,this);return Array.isArray(e)?t:t[0]},i.prototype._percentile=function(e){if(0!==this.size()){this._cumulate(!0);this.centroids.min(),this.centroids.max();var t=this.n*e,s=this.bound_mean_cumn(t),r=s[0],i=s[1];return i===r||null===r||null===i?(r||i).mean:this.discrete?t<=r.cumn?r.mean:i.mean:r.mean+(t-r.mean_cumn)*(i.mean-r.mean)/(i.mean_cumn-r.mean_cumn)}},i.prototype.compress=function(){if(!this.compressing){var e,t,s=this.toArray();for(this.reset(),this.compressing=!0;s.length>0;)this.push_centroid((e=s,t=void 0,t=Math.floor(Math.random()*e.length),e.splice(t,1)[0]));this._cumulate(!0),this.compressing=!1}},a.prototype=Object.create(i.prototype),a.prototype.constructor=a,a.prototype.push=function(e){i.prototype.push.call(this,e),this.check_continuous()},a.prototype._new_centroid=function(e,t,s){this.n_unique+=1,i.prototype._new_centroid.call(this,e,t,s)},a.prototype._addweight=function(e,t,s){1===e.n&&(this.n_unique-=1),i.prototype._addweight.call(this,e,t,s)},a.prototype.check_continuous=function(){return!("auto"!==this.mode||this.size()<this.digest_thresh)&&(this.n_unique/this.size()>this.digest_ratio&&(this.mode="cont",this.discrete=!1,this.delta=this.config.delta||.01,this.compress(),!0))},e.exports={TDigest:i,Digest:a}},function(e,t,s){e.exports={RBTree:s(26),BinTree:s(27)}},function(e,t,s){var r=s(9);function i(e){this.data=e,this.left=null,this.right=null,this.red=!0}function n(e){this._root=null,this._comparator=e,this.size=0}function o(e){return null!==e&&e.red}function a(e,t){var s=e.get_child(!t);return e.set_child(!t,s.get_child(t)),s.set_child(t,e),e.red=!0,s.red=!1,s}function c(e,t){return e.set_child(!t,a(e.get_child(!t),!t)),a(e,t)}i.prototype.get_child=function(e){return e?this.right:this.left},i.prototype.set_child=function(e,t){e?this.right=t:this.left=t},n.prototype=new r,n.prototype.insert=function(e){var t=!1;if(null===this._root)this._root=new i(e),t=!0,this.size++;else{var s=new i(void 0),r=0,n=0,l=null,u=s,h=null,p=this._root;for(u.right=this._root;;){if(null===p?(p=new i(e),h.set_child(r,p),t=!0,this.size++):o(p.left)&&o(p.right)&&(p.red=!0,p.left.red=!1,p.right.red=!1),o(p)&&o(h)){var m=u.right===l;p===h.get_child(n)?u.set_child(m,a(l,!n)):u.set_child(m,c(l,!n))}var f=this._comparator(p.data,e);if(0===f)break;n=r,r=f<0,null!==l&&(u=l),l=h,h=p,p=p.get_child(r)}this._root=s.right}return this._root.red=!1,t},n.prototype.remove=function(e){if(null===this._root)return!1;var t=new i(void 0),s=t;s.right=this._root;for(var r=null,n=null,l=null,u=1;null!==s.get_child(u);){var h=u;n=r,r=s,s=s.get_child(u);var p=this._comparator(e,s.data);if(u=p>0,0===p&&(l=s),!o(s)&&!o(s.get_child(u)))if(o(s.get_child(!u))){var m=a(s,u);r.set_child(h,m),r=m}else if(!o(s.get_child(!u))){var f=r.get_child(!h);if(null!==f)if(o(f.get_child(!h))||o(f.get_child(h))){var d=n.right===r;o(f.get_child(h))?n.set_child(d,c(r,h)):o(f.get_child(!h))&&n.set_child(d,a(r,h));var g=n.get_child(d);g.red=!0,s.red=!0,g.left.red=!1,g.right.red=!1}else r.red=!1,f.red=!0,s.red=!0}}return null!==l&&(l.data=s.data,r.set_child(r.right===s,s.get_child(null===s.left)),this.size--),this._root=t.right,null!==this._root&&(this._root.red=!1),null!==l},e.exports=n},function(e,t,s){var r=s(9);function i(e){this.data=e,this.left=null,this.right=null}function n(e){this._root=null,this._comparator=e,this.size=0}i.prototype.get_child=function(e){return e?this.right:this.left},i.prototype.set_child=function(e,t){e?this.right=t:this.left=t},n.prototype=new r,n.prototype.insert=function(e){if(null===this._root)return this._root=new i(e),this.size++,!0;for(var t=0,s=null,r=this._root;;){if(null===r)return r=new i(e),s.set_child(t,r),ret=!0,this.size++,!0;if(0===this._comparator(r.data,e))return!1;t=this._comparator(r.data,e)<0,s=r,r=r.get_child(t)}},n.prototype.remove=function(e){if(null===this._root)return!1;var t=new i(void 0),s=t;s.right=this._root;for(var r=null,n=null,o=1;null!==s.get_child(o);){r=s,s=s.get_child(o);var a=this._comparator(e,s.data);o=a>0,0===a&&(n=s)}return null!==n&&(n.data=s.data,r.set_child(r.right===s,s.get_child(null===s.left)),this._root=t.right,this.size--,!0)},e.exports=n},function(e,t,s){"use strict";const r=s(29),i=s(30),n=s(31),{globalRegistry:o}=s(1);function a(e,t,s,o){const a=r.parse(this.gatewayUrl),c=`${a.pathname&&"/"!==a.pathname?a.pathname:""}/metrics/job/${encodeURIComponent(t)}${function(e){if(!e)return"";return Object.keys(e).map(t=>`/${encodeURIComponent(t)}/${encodeURIComponent(e[t])}`).join("")}(s)}`,l=r.resolve(this.gatewayUrl,c),u=r.parse(l),h=-1!==u.href.search(/^https/)?n:i;const p=Object.assign(u,this.requestOptions,{method:e}),m=h.request(p,e=>{let t="";e.setEncoding("utf8"),e.on("data",e=>{t+=e}),e.on("end",()=>{o(null,e,t)})});m.on("error",e=>{o(e)}),"DELETE"!==e&&m.write(this.registry.metrics({timestamps:!1})),m.end()}e.exports=class{constructor(e,t,s){s||(s=o),this.registry=s,this.gatewayUrl=e,this.requestOptions=Object.assign({},t)}pushAdd(e,t){if(!e||!e.jobName)throw new Error("Missing jobName parameter");a.call(this,"POST",e.jobName,e.groupings,t)}push(e,t){if(!e||!e.jobName)throw new Error("Missing jobName parameter");a.call(this,"PUT",e.jobName,e.groupings,t)}delete(e,t){if(!e||!e.jobName)throw new Error("Missing jobName parameter");a.call(this,"DELETE",e.jobName,e.groupings,t)}}},function(e,t){e.exports=require("url")},function(e,t){e.exports=require("http")},function(e,t){e.exports=require("https")},function(e,t,s){"use strict";const r=s(33),i=s(34),n=s(35),o=s(37),a=s(39),c=s(40),l=s(41),u=s(42),h=s(43),p=s(44),m=s(46),{globalRegistry:f}=s(1),{printDeprecationCollectDefaultMetricsNumber:d}=s(2),g={processCpuTotal:r,processStartTime:i,osMemoryHeap:n,processOpenFileDescriptors:o,processMaxFileDescriptors:a,eventLoopLag:c,processHandles:l,processRequests:u,heapSizeAndUsed:h,heapSpacesSizeAndUsed:p,version:m},_=Object.keys(g);let b=null,y=!0;e.exports=function(e){let t=e;"number"==typeof e&&(d(e),t={timeout:e}),t=Object.assign({timeout:1e4},t),null!==b&&clearInterval(b);const s=_.map(s=>{const r=g[s];return y||r.metricNames.map(f.removeSingleMetric,f),r(t.register,e)});function r(){s.forEach(e=>e.call())}return r(),b=setInterval(r,t.timeout).unref(),y=!1,b},e.exports.metricsList=_},function(e,t,s){"use strict";const r=s(8);e.exports=((e,t={})=>{if("function"!=typeof process.cpuUsage)return()=>{};const s=e?[e]:void 0,i=t.prefix?t.prefix:"",n=new r({name:i+"process_cpu_user_seconds_total",help:"Total user CPU time spent in seconds.",registers:s}),o=new r({name:i+"process_cpu_system_seconds_total",help:"Total system CPU time spent in seconds.",registers:s}),a=new r({name:i+"process_cpu_seconds_total",help:"Total user and system CPU time spent in seconds.",registers:s});let c=process.cpuUsage();return()=>{const e=process.cpuUsage(),t=Date.now(),s=e.user-c.user,r=e.system-c.system;c=e,n.inc(s/1e6,t),o.inc(r/1e6,t),a.inc((s+r)/1e6,t)}}),e.exports.metricNames=["process_cpu_user_seconds_total","process_cpu_system_seconds_total","process_cpu_seconds_total"]},function(e,t,s){"use strict";const r=s(0),i=Math.round(Date.now()/1e3-process.uptime());e.exports=((e,t={})=>{const s=t.prefix?t.prefix:"",n=new r({name:s+"process_start_time_seconds",help:"Start time of the process since unix epoch in seconds.",registers:e?[e]:void 0,aggregator:"omit"});let o=!1;return()=>{o||(n.set(i),o=!0)}}),e.exports.metricNames=["process_start_time_seconds"]},function(e,t,s){"use strict";const r=s(0),i=s(36),n=s(11),o="process_resident_memory_bytes";e.exports=((e,t)=>"linux"===process.platform?i(e,t):function(e,t={}){const s=t.prefix?t.prefix:"",i=new r({name:s+o,help:"Resident memory size in bytes.",registers:e?[e]:void 0});return()=>{const e=n();e&&i.set(e.rss,Date.now())}}(e,t)),e.exports.metricNames="linux"===process.platform?i.metricNames:[o]},function(e,t,s){"use strict";const r=s(0),i=s(5),n=["VmSize","VmRSS","VmData"];e.exports=((e,t={})=>{const s=e?[e]:void 0,o=t.prefix?t.prefix:"",a=new r({name:o+"process_resident_memory_bytes",help:"Resident memory size in bytes.",registers:s}),c=new r({name:o+"process_virtual_memory_bytes",help:"Virtual memory size in bytes.",registers:s}),l=new r({name:o+"process_heap_bytes",help:"Process heap size in bytes.",registers:s});return()=>{i.readFile("/proc/self/status","utf8",(e,t)=>{if(e)return;const s=Date.now(),r=function(e){const t={};return e.split("\n").filter(e=>n.some(t=>0===e.indexOf(t))).forEach(e=>{const s=e.split(":");let r=s[1].trim();r=r.substr(0,r.length-3),r=1024*Number(r),t[s[0]]=r}),t}(t);a.set(r.VmRSS,s),c.set(r.VmSize,s),l.set(r.VmData,s)})}}),e.exports.metricNames=["process_resident_memory_bytes","process_virtual_memory_bytes","process_heap_bytes"]},function(e,t,s){"use strict";const r=s(0),i=s(5),n=s(38);e.exports=((e,t={})=>{if("linux"!==n.platform)return()=>{};const s=t.prefix?t.prefix:"",o=new r({name:s+"process_open_fds",help:"Number of open file descriptors.",registers:e?[e]:void 0});return()=>{i.readdir("/proc/self/fd",(e,t)=>{e||o.set(t.length-1,Date.now())})}}),e.exports.metricNames=["process_open_fds"]},function(e,t){e.exports=require("process")},function(e,t,s){"use strict";const r=s(0),i=s(5);e.exports=((e,t={})=>{let s=!1;if("linux"!==process.platform)return()=>{};const n=t.prefix?t.prefix:"",o=new r({name:n+"process_max_fds",help:"Maximum number of open file descriptors.",registers:e?[e]:void 0});return()=>{s||i.readFile("/proc/sys/fs/file-max","utf8",(e,t)=>{e||(s=!0,o.set(Number(t)))})}}),e.exports.metricNames=["process_max_fds"]},function(e,t,s){"use strict";const r=s(0);function i(e,t){const s=process.hrtime(e),r=(1e9*s[0]+s[1])/1e9;t.set(r,Date.now())}e.exports=((e,t={})=>{const s=t.prefix?t.prefix:"",n=new r({name:s+"nodejs_eventloop_lag_seconds",help:"Lag of event loop in seconds.",registers:e?[e]:void 0,aggregator:"average"});return()=>{const e=process.hrtime();setImmediate(i,e,n)}}),e.exports.metricNames=["nodejs_eventloop_lag_seconds"]},function(e,t,s){"use strict";const r=s(0);e.exports=((e,t={})=>{if("function"!=typeof process._getActiveHandles)return()=>{};const s=t.prefix?t.prefix:"",i=new r({name:s+"nodejs_active_handles_total",help:"Number of active handles.",registers:e?[e]:void 0});return()=>{i.set(process._getActiveHandles().length,Date.now())}}),e.exports.metricNames=["nodejs_active_handles_total"]},function(e,t,s){"use strict";const r=s(0);e.exports=((e,t={})=>{if("function"!=typeof process._getActiveRequests)return()=>{};const s=t.prefix?t.prefix:"",i=new r({name:s+"nodejs_active_requests_total",help:"Number of active requests.",registers:e?[e]:void 0});return()=>{i.set(process._getActiveRequests().length,Date.now())}}),e.exports.metricNames=["nodejs_active_requests_total"]},function(e,t,s){"use strict";const r=s(0),i=s(11);e.exports=((e,t={})=>{if("function"!=typeof process.memoryUsage)return()=>{};const s=e?[e]:void 0,n=t.prefix?t.prefix:"",o=new r({name:n+"nodejs_heap_size_total_bytes",help:"Process heap size from node.js in bytes.",registers:s}),a=new r({name:n+"nodejs_heap_size_used_bytes",help:"Process heap size used from node.js in bytes.",registers:s});let c;const l=i();return l&&l.external&&(c=new r({name:n+"nodejs_external_memory_bytes",help:"Nodejs external memory size in bytes.",registers:s})),()=>{const e=i();if(e){const t=Date.now();o.set(e.heapTotal,t),a.set(e.heapUsed,t),e.external&&c&&c.set(e.external,t)}return{total:o,used:a,external:c}}}),e.exports.metricNames=["nodejs_heap_size_total_bytes","nodejs_heap_size_used_bytes","nodejs_external_memory_bytes"]},function(e,t,s){"use strict";const r=s(0);let i;try{i=s(45)}catch(e){}const n=["total","used","available"],o={};n.forEach(e=>{o[e]=`nodejs_heap_space_size_${e}_bytes`}),e.exports=((e,t={})=>{if(void 0===i||"function"!=typeof i.getHeapSpaceStatistics)return()=>{};const s=e?[e]:void 0,a=t.prefix?t.prefix:"",c={};return n.forEach(e=>{c[e]=new r({name:a+o[e],help:`Process heap space size ${e} from node.js in bytes.`,labelNames:["space"],registers:s})}),()=>{const e={total:{},used:{},available:{}},t=Date.now();return i.getHeapSpaceStatistics().forEach(s=>{const r=s.space_name.substr(0,s.space_name.indexOf("_space"));e.total[r]=s.space_size,e.used[r]=s.space_used_size,e.available[r]=s.space_available_size,c.total.set({space:r},s.space_size,t),c.used.set({space:r},s.space_used_size,t),c.available.set({space:r},s.space_available_size,t)}),e}}),e.exports.metricNames=n.map(e=>o[e])},function(e,t){e.exports=require("v8")},function(e,t,s){"use strict";const r=s(0),i=process.version,n=i.slice(1).split(".").map(Number);e.exports=((e,t={})=>{const s=t.prefix?t.prefix:"",o=new r({name:s+"nodejs_version_info",help:"Node.js version info.",labelNames:["version","major","minor","patch"],registers:e?[e]:void 0,aggregator:"first"});let a=!1;return()=>{a||(o.labels(i,n[0],n[1],n[2]).set(1),a=!0)}}),e.exports.metricNames=["nodejs_version_info"]},function(e,t,s){"use strict";const r=s(48),i=s(1),{Grouper:n}=s(2),{aggregators:o}=s(12),a="prom-client:getMetricsReq",c="prom-client:getMetricsRes";let l=[i.globalRegistry],u=0,h=!1;const p=new Map;class m extends i{constructor(){super(),function(){if(h)return;h=!0,r.isMaster&&r.on("message",(e,t)=>{if(t.type===c){const e=p.get(t.requestId);if(t.metrics.forEach(t=>e.responses.push(t)),e.pending--,0===e.pending){if(p.delete(t.requestId),clearTimeout(e.errorTimeout),e.failed)return;const s=m.aggregate(e.responses),r=s.metrics();e.done(null,r)}}})}()}clusterMetrics(e){const t=u++;return new Promise((s,i)=>{function n(t,r){"function"==typeof e?e(t,r):t?i(t):s(r)}const o={responses:[],pending:0,done:n,errorTimeout:setTimeout(()=>{o.failed=!0;const e=new Error("Operation timed out.");o.done(e)},5e3),failed:!1};p.set(t,o);const c={type:a,requestId:t};for(const e in r.workers)r.workers[e].isConnected()&&(r.workers[e].send(c),o.pending++);0===o.pending&&(clearTimeout(o.errorTimeout),process.nextTick(()=>n(null,"")))})}static aggregate(e){const t=new i,s=new n;return e.forEach(e=>{e.forEach(e=>{s.add(e.name,e)})}),s.forEach(e=>{const s=e[0].aggregator,r=o[s];if("function"!=typeof r)throw new Error(`'${s}' is not a defined aggregator.`);const i=r(e);if(i){const e=Object.assign({get:()=>i},i);t.registerMetric(e)}}),t}static setRegistries(e){Array.isArray(e)||(e=[e]),e.forEach(e=>{if(!(e instanceof i))throw new TypeError(`Expected Registry, got ${typeof e}`)}),l=e}}r.isWorker&&process.on("message",e=>{e.type===a&&process.send({type:c,requestId:e.requestId,metrics:l.map(e=>e.getMetricsAsJSON())})}),e.exports=m},function(e,t){e.exports=require("cluster")},function(e,t,s){"use strict";e.exports=function(e){return function(){return new Promise((t,s)=>{const r=Array.prototype.slice.call(arguments);r.push((e,r)=>{e&&s(e),t(r)}),e.apply(e,r)})}}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.circuitBreaker=t():e.circuitBreaker=t()}(global,function(){return function(e){var t={};function s(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,s),i.l=!0,i.exports}return s.m=e,s.c=t,s.d=function(e,t,r){s.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},s.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.t=function(e,t){if(1&t&&(e=s(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)s.d(r,i,function(t){return e[t]}.bind(null,i));return r},s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,"a",t),t},s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s.p="",s(s.s=13)}([function(e,t,s){"use strict";const r=s(3),{globalRegistry:i}=s(1),n="gauge",{isDate:o,setValue:a,getPropertiesFromObj:c,getLabels:l,hashObject:u,isObject:h,printDeprecationObjectConstructor:p,removeLabels:m}=s(2),{validateMetricName:f,validateLabel:d,validateLabelName:g}=s(4);function _(e){return()=>{const t=Date.now()/1e3;void 0===e?this.set(t):this.set(e,t)}}function b(e){return()=>{const t=process.hrtime();return s=>{const r=process.hrtime(t);this.set(Object.assign({},e,s),r[0]+r[1]/1e9)}}}function y(e){return(t,s)=>{const r=x(e,t);this.set(r.labels,this._getValue(r.labels)-(r.value||1),s)}}function v(e){return(t,s)=>{const r=x(e,t);this.set(r.labels,this._getValue(r.labels)+(r.value||1),s)}}function w(e){return(t,s)=>{if("number"!=typeof t)throw new TypeError(`Value is not a valid number: ${r.format(t)}`);if(s&&!o(s)&&!Number.isFinite(s))throw new TypeError(`Timestamp is not a valid date or number: ${r.format(s)}`);e=e||{},d(this.labelNames,e),this.hashMap=a(this.hashMap,t,e,s)}}function x(e,t){return h(e)?{labels:e,value:t}:{value:e,labels:{}}}e.exports=class{constructor(e,t,s){let r;if(h(e)?(r=Object.assign({labelNames:[]},e)).registers||(r.registers=[i]):(p(),r={name:e,help:t,labelNames:s,registers:[i]}),!r.help)throw new Error("Missing mandatory help parameter");if(!r.name)throw new Error("Missing mandatory name parameter");if(!f(r.name))throw new Error("Invalid metric name");if(!g(r.labelNames))throw new Error("Invalid label name");this.name=r.name,this.labelNames=r.labelNames||[],this.reset(),this.help=r.help,this.aggregator=r.aggregator||"sum",r.registers.forEach(e=>e.registerMetric(this))}set(e,t,s){return h(e)?w.call(this,e)(t,s):w.call(this,null)(e,t)}reset(){return function(){this.hashMap={},0===this.labelNames.length&&(this.hashMap=a({},0,{}))}.call(this)}inc(e,t,s){v.call(this,e)(t,s)}dec(e,t,s){y.call(this,e)(t,s)}setToCurrentTime(e){return _.call(this,e)()}startTimer(e){return b.call(this,e)()}get(){return{help:this.help,name:this.name,type:n,values:c(this.hashMap),aggregator:this.aggregator}}_getValue(e){const t=u(e||{});return this.hashMap[t]?this.hashMap[t].value:0}labels(){const e=l(this.labelNames,arguments);return{inc:v.call(this,e),dec:y.call(this,e),set:w.call(this,e),setToCurrentTime:_.call(this,e),startTimer:b.call(this,e)}}remove(){const e=l(this.labelNames,arguments);m.call(this,this.hashMap,e)}}},function(e,t,s){"use strict";const{getValueAsString:r}=s(2);function i(e){return e.replace(/\n/g,"\\n").replace(/\\(?!n)/g,"\\\\")}const n={timestamps:!0};class o{constructor(){this._metrics={},this._defaultLabels={}}getMetricsAsArray(){return Object.keys(this._metrics).map(this.getSingleMetric,this)}getMetricAsPrometheusString(e,t){const s=Object.assign({},n,t),o=e.get(),a=i(o.name),c=`# HELP ${a} ${i(o.help)}`,l=`# TYPE ${a} ${o.type}`,u=Object.keys(this._defaultLabels);let h="";for(const e of o.values||[]){e.labels=e.labels||{};for(const t of u)e.labels[t]=e.labels[t]||this._defaultLabels[t];let t="";for(const s of Object.keys(e.labels))t+=`${s}="${p=e.labels[s],"string"!=typeof p?p:i(p).replace(/"/g,'\\"')}",`;let n=e.metricName||o.name;t&&(n+=`{${t.substring(0,t.length-1)}}`);let a=`${n} ${r(e.value)}`;s.timestamps&&e.timestamp&&(a+=` ${e.timestamp}`),h+=`${a.trim()}\n`}var p;return`${c}\n${l}\n${h}`.trim()}metrics(e){let t="";for(const s of this.getMetricsAsArray())t+=`${this.getMetricAsPrometheusString(s,e)}\n\n`;return t.substring(0,t.length-1)}registerMetric(e){if(this._metrics[e.name]&&this._metrics[e.name]!==e)throw new Error(`A metric with the name ${e.name} has already been registered.`);this._metrics[e.name]=e}clear(){this._metrics={},this._defaultLabels={}}getMetricsAsJSON(){const e=[],t=Object.keys(this._defaultLabels);for(const s of this.getMetricsAsArray()){const r=s.get();if(r.values)for(const e of r.values)for(const s of t)e.labels[s]=e.labels[s]||this._defaultLabels[s];e.push(r)}return e}removeSingleMetric(e){delete this._metrics[e]}getSingleMetricAsString(e){return this.getMetricAsPrometheusString(this._metrics[e])}getSingleMetric(e){return this._metrics[e]}setDefaultLabels(e){this._defaultLabels=e}resetMetrics(){for(const e in this._metrics)this._metrics[e].reset()}get contentType(){return"text/plain; version=0.0.4; charset=utf-8"}static merge(e){const t=new o;return e.reduce((e,t)=>e.concat(t.getMetricsAsArray()),[]).forEach(t.registerMetric,t),t}}e.exports=o,e.exports.globalRegistry=new o},function(e,t,s){"use strict";const r={};function i(e){let t=Object.keys(e);if(0===t.length)return"";t.length>1&&(t=t.sort());let s="",r=0;const i=t.length;for(;r<i-1;r++)s+=`${t[r]}:${e[t[r]]},`;return s+=`${t[r]}:${e[t[r]]}`}function n(e){return e instanceof Date&&!isNaN(e.valueOf())}function o(e){r[e]||(r[e]=!0,process.emitWarning?process.emitWarning(e,"DeprecationWarning"):console.warn(new Error(e)))}t.isDate=n,t.getPropertiesFromObj=function(e){return Object.keys(e).map(t=>e[t])},t.getValueAsString=function(e){return Number.isNaN(e)?"Nan":Number.isFinite(e)?`${e}`:e<0?"-Inf":"+Inf"},t.removeLabels=function(e,t){delete e[i(t)]},t.setValue=function(e,t,s,r){return e[i(s)]={value:"number"==typeof t?t:0,labels:s||{},timestamp:n(r)?r.valueOf():Number.isFinite(r)?r:void 0},e},t.getLabels=function(e,t){if(e.length!==t.length)throw new Error("Invalid number of arguments");const s=Array.prototype.slice.call(t);return e.reduce((e,t,r)=>(e[t]=s[r],e),{})},t.hashObject=i,t.isObject=function(e){return e===Object(e)},t.printDeprecationObjectConstructor=()=>{o("prom-client - Passing a non-object to metrics constructor is deprecated")},t.printDeprecationCollectDefaultMetricsNumber=e=>{o(`prom-client - A number to defaultMetrics is deprecated, please use \`collectDefaultMetrics({ timeout: ${e} })\`.`)};t.Grouper=class extends Map{add(e,t){this.has(e)?this.get(e).push(t):this.set(e,[t])}}},function(e,t){e.exports=require("util")},function(e,t,s){"use strict";const r=s(3),i=/^[a-zA-Z_:][a-zA-Z0-9_:]*$/,n=/^[a-zA-Z_][a-zA-Z0-9_]*$/;t.validateMetricName=function(e){return i.test(e)},t.validateLabelName=function(e){let t=!0;return(e||[]).forEach(e=>{n.test(e)||(t=!1)}),t},t.validateLabel=function(e,t){Object.keys(t).forEach(t=>{if(-1===e.indexOf(t))throw new Error(`Added label "${t}" is not included in initial labelset: ${r.inspect(e)}`)})}},function(e,t){e.exports=require("fs")},function(e,t){e.exports=require("events")},function(e,t,s){"use strict";const{Transform:r,Readable:i}=s(16),n=s(17),o=new r({objectMode:!0,transform:(e,t,s)=>s(null,`data: ${JSON.stringify(n(e))}\n\n`)});o.resume();class a{constructor(e){this._readableStream=new i({objectMode:!0,read(){}}),e.status.on("snapshot",function(t){this._readableStream.push(Object.assign({},{name:e.name,closed:e.closed,group:e.group,options:e.options},t))}.bind(this)),this._readableStream.resume(),this._readableStream.pipe(o)}getHystrixStream(){return o}shutdown(){this._readableStream.unpipe(o)}}a.stream=o,e.exports=a},function(e,t,s){"use strict";const r=s(3),{globalRegistry:i}=s(1),n="counter",{isDate:o,getPropertiesFromObj:a,hashObject:c,isObject:l,printDeprecationObjectConstructor:u,getLabels:h,removeLabels:p}=s(2),{validateLabel:m,validateMetricName:f,validateLabelName:d}=s(4);const g=function(){this.hashMap={},0===this.labelNames.length&&(this.hashMap=b({},0))},_=function(e,t){return(s,i)=>{if(s&&!Number.isFinite(s))throw new TypeError(`Value is not a valid number: ${r.format(s)}`);if(i&&!o(i)&&!Number.isFinite(i))throw new TypeError(`Timestamp is not a valid date or number: ${r.format(i)}`);if(s<0)throw new Error("It is not possible to decrease a counter");e=e||{},m(this.labelNames,e);const n=null==s?1:s;this.hashMap=b(this.hashMap,n,i,e,t)}};function b(e,t,s,r,i){return i=i||"",s=o(s)?s.valueOf():Number.isFinite(s)?s:void 0,e[i]?(e[i].value+=t,e[i].timestamp=s):e[i]={value:t,labels:r||{},timestamp:s},e}e.exports=class{constructor(e,t,s){let r;if(l(e)?(r=Object.assign({labelNames:[]},e)).registers||(r.registers=[i]):(u(),r={name:e,help:t,labelNames:s,registers:[i]}),!r.help)throw new Error("Missing mandatory help parameter");if(!r.name)throw new Error("Missing mandatory name parameter");if(!f(r.name))throw new Error("Invalid metric name");if(!d(r.labelNames))throw new Error("Invalid label name");this.name=r.name,this.labelNames=r.labelNames||[],this.reset(),this.help=r.help,this.aggregator=r.aggregator||"sum",r.registers.forEach(e=>e.registerMetric(this))}inc(e,t,s){if(!l(e))return _.call(this,null)(e,t);const r=c(e);return _.call(this,e,r)(t,s)}reset(){return g.call(this)}get(){return{help:this.help,name:this.name,type:n,values:a(this.hashMap),aggregator:this.aggregator}}labels(){const e=h(this.labelNames,arguments)||{},t=c(e);return m(this.labelNames,e),{inc:_.call(this,e,t)}}remove(){const e=h(this.labelNames,arguments)||{};return p.call(this,this.hashMap,e)}}},function(e,t){function s(){}function r(e){this._tree=e,this._ancestors=[],this._cursor=null}s.prototype.clear=function(){this._root=null,this.size=0},s.prototype.find=function(e){for(var t=this._root;null!==t;){var s=this._comparator(e,t.data);if(0===s)return t.data;t=t.get_child(s>0)}return null},s.prototype.findIter=function(e){for(var t=this._root,s=this.iterator();null!==t;){var r=this._comparator(e,t.data);if(0===r)return s._cursor=t,s;s._ancestors.push(t),t=t.get_child(r>0)}return null},s.prototype.lowerBound=function(e){for(var t=this._root,s=this.iterator(),r=this._comparator;null!==t;){var i=r(e,t.data);if(0===i)return s._cursor=t,s;s._ancestors.push(t),t=t.get_child(i>0)}for(var n=s._ancestors.length-1;n>=0;--n)if(r(e,(t=s._ancestors[n]).data)<0)return s._cursor=t,s._ancestors.length=n,s;return s._ancestors.length=0,s},s.prototype.upperBound=function(e){for(var t=this.lowerBound(e),s=this._comparator;null!==t.data()&&0===s(t.data(),e);)t.next();return t},s.prototype.min=function(){var e=this._root;if(null===e)return null;for(;null!==e.left;)e=e.left;return e.data},s.prototype.max=function(){var e=this._root;if(null===e)return null;for(;null!==e.right;)e=e.right;return e.data},s.prototype.iterator=function(){return new r(this)},s.prototype.each=function(e){for(var t,s=this.iterator();null!==(t=s.next());)e(t)},s.prototype.reach=function(e){for(var t,s=this.iterator();null!==(t=s.prev());)e(t)},r.prototype.data=function(){return null!==this._cursor?this._cursor.data:null},r.prototype.next=function(){if(null===this._cursor){var e=this._tree._root;null!==e&&this._minNode(e)}else{var t;if(null===this._cursor.right)do{if(t=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.right===t);else this._ancestors.push(this._cursor),this._minNode(this._cursor.right)}return null!==this._cursor?this._cursor.data:null},r.prototype.prev=function(){if(null===this._cursor){var e=this._tree._root;null!==e&&this._maxNode(e)}else{var t;if(null===this._cursor.left)do{if(t=this._cursor,!this._ancestors.length){this._cursor=null;break}this._cursor=this._ancestors.pop()}while(this._cursor.left===t);else this._ancestors.push(this._cursor),this._maxNode(this._cursor.left)}return null!==this._cursor?this._cursor.data:null},r.prototype._minNode=function(e){for(;null!==e.left;)this._ancestors.push(e),e=e.left;this._cursor=e},r.prototype._maxNode=function(e){for(;null!==e.right;)this._ancestors.push(e),e=e.right;this._cursor=e},e.exports=s},function(e,t,s){"use strict";t.linearBuckets=(e,t,s)=>{if(s<1)throw new Error("Linear buckets needs a positive count");const r=new Array(s);for(let i=0;i<s;i++)r[i]=e,e+=t;return r},t.exponentialBuckets=(e,t,s)=>{if(e<=0)throw new Error("Exponential buckets needs a positive start");if(s<1)throw new Error("Exponential buckets needs a positive count");if(t<=1)throw new Error("Exponential buckets needs a factor greater than 1");const r=new Array(s);for(let i=0;i<s;i++)r[i]=e,e*=t;return r}},function(e,t,s){"use strict";e.exports=function(){let e;try{e=process.memoryUsage()}catch(e){}return e}},function(e,t,s){"use strict";const{Grouper:r,hashObject:i}=s(2);function n(e){return t=>{if(0===t.length)return;const s={help:t[0].help,name:t[0].name,type:t[0].type,values:[],aggregator:t[0].aggregator},n=new r;return t.forEach(e=>{e.values.forEach(e=>{const t=i(e.labels);n.add(`${e.metricName}_${t}`,e)})}),n.forEach(t=>{if(0===t.length)return;const r={value:e(t),labels:t[0].labels};t[0].metricName&&(r.metricName=t[0].metricName),s.values.push(r)}),s}}t.AggregatorFactory=n,t.aggregators={sum:n(e=>e.reduce((e,t)=>e+t.value,0)),first:n(e=>e[0].value),omit:()=>{},average:n(e=>e.reduce((e,t)=>e+t.value,0)/e.length),min:n(e=>e.reduce((e,t)=>Math.min(e,t.value),1/0)),max:n(e=>e.reduce((e,t)=>Math.max(e,t.value),-1/0))}},function(e,t,s){"use strict";const r=s(14),i=[],n={timeout:1e4,errorThresholdPercentage:50,resetTimeout:3e4};function o(e,t){const s=new r(e,Object.assign({},n,t));return i.push(s),s}o.promisify=s(49),o.metrics=function(){const e=i[i.length-1];if(e&&e.metrics)return e.metrics.metrics};let a=!1;Object.defineProperty(o,"stats",{get:e=>(a||(a=!0,console.warn("WARNING: Hystrics stats are deprecated\n See: https://github.com/Netflix/Hystrix#dashboard")),s(7).stream)}),e.exports=o,e.exports.default=o},function(e,t,s){"use strict";const r=s(6),i=s(15),n=s(7),o=s(18);let a;process.env.WEB||(a=s(19));const c=Symbol("state"),l=Symbol("open"),u=Symbol("closed"),h=Symbol("half-open"),p=Symbol("pending-close"),m=Symbol("shutdown"),f=Symbol("fallback"),d=Symbol("status"),g=Symbol("name"),_=Symbol("group"),b=Symbol("hystrix-stats"),y=Symbol("prometheus-metrics"),v=new WeakMap,w=Symbol("Enabled"),x=Symbol("warming-up"),N=Symbol("volume-threshold"),E="options.maxFailures is deprecated. Please use options.errorThresholdPercentage";let M=!1;class j extends r{constructor(e,t){if(super(),this.options=t,this.options.rollingCountTimeout=t.rollingCountTimeout||1e4,this.options.rollingCountBuckets=t.rollingCountBuckets||10,this.options.rollingPercentilesEnabled=!1!==t.rollingPercentilesEnabled,this.options.capacity=Number.isInteger(t.capacity)?t.capacity:Number.MAX_SAFE_INTEGER,this.options.errorFilter=t.errorFilter||(e=>!1),this.semaphore=new o(this.options.capacity),this[N]=Number.isInteger(t.volumeThreshold)?t.volumeThreshold:0,this[x]=!0===t.allowWarmUp,this[d]=new i(this.options),this[c]=u,this[f]=null,this[p]=!1,this[g]=t.name||e.name||O(),this[_]=t.group||this[g],this[w]=!1!==t.enabled,this[x]){const e=setTimeout(e=>this[x]=!1,this.options.rollingCountTimeout);"function"==typeof e.unref&&e.unref()}this.action="function"!=typeof e?t=>Promise.resolve(e):e,t.maxFailures&&console.error(E);const s=e=>(t,s)=>this[d].increment(e,s);var r;this.on("success",s("successes")),this.on("failure",s("failures")),this.on("fallback",s("fallbacks")),this.on("timeout",s("timeouts")),this.on("fire",s("fires")),this.on("reject",s("rejects")),this.on("cacheHit",s("cacheHits")),this.on("cacheMiss",s("cacheMisses")),this.on("open",e=>this[d].open()),this.on("close",e=>this[d].close()),this.on("semaphoreLocked",s("semaphoreRejections")),this.on("open",(r=this,e=>{const t=setTimeout(()=>{r[c]=h,r[p]=!0,r.emit("halfOpen",r.options.resetTimeout)},r.options.resetTimeout);"function"==typeof t.unref&&t.unref()})),this.on("success",e=>this.close()),this.options.cache&&v.set(this,void 0),this[b]=new n(this),a&&t.usePrometheus&&(this[y]=new a(this))}close(){this[p]=!1,this[c]!==u&&(this[c]=u,this.emit("close"))}open(){this[p]=!1,this[c]!==l&&(this[c]=l,this.emit("open"))}shutdown(){this.disable(),this.removeAllListeners(),this.status.shutdown(),this.hystrixStats.shutdown(),this.metrics&&this.metrics.clear(),this[c]=m}get isShutdown(){return this[c]===m}get name(){return this[g]}get group(){return this[_]}get pendingClose(){return this[p]}get closed(){return this[c]===u}get opened(){return this[c]===l}get halfOpen(){return this[c]===h}get status(){return this[d]}get stats(){return this[d].stats}get hystrixStats(){return M||(M=!0,console.warn("WARNING: Hystrics stats are deprecated\n See: https://github.com/Netflix/Hystrix#dashboard")),this[b]}get metrics(){return this[y]}get enabled(){return this[w]}get warmUp(){return this[x]}get volumeThreshold(){return this[N]}fallback(e){let t=e;return e instanceof j&&(t=function(){return e.fire.apply(e,arguments)}),this[f]=t,this}fire(){if(this.isShutdown){const e=new Error("The circuit has been shutdown.");return e.code="ESHUTDOWN",Promise.reject(e)}const e=Array.prototype.slice.call(arguments);if(this.emit("fire",e),void 0!==v.get(this))return this.emit("cacheHit"),v.get(this);if(this.options.cache&&this.emit("cacheMiss"),!this[w]){const t=this.action.apply(this.action,e);return"function"==typeof t.then?t:Promise.resolve(t)}if(!this.closed&&!this.pendingClose){const t=new Error("Breaker is open");return t.code="EOPENBREAKER",this.emit("reject",t),k(this,t,e)||Promise.reject(t)}let t;this[p]=!1;let s=!1;return new Promise((r,i)=>{const n=Date.now();if(this.semaphore.test()){this.options.timeout&&(t=setTimeout(()=>{s=!0;const o=new Error(`Timed out after ${this.options.timeout}ms`);o.code="ETIMEDOUT";const a=Date.now()-n;this.semaphore.release(),this.emit("timeout",o,a,e),r(T(o,this,t,e,a,r,i))},this.options.timeout));try{const o=this.action.apply(this.action,e),a="function"==typeof o.then?o:Promise.resolve(o);a.then(e=>{s||(clearTimeout(t),this.emit("success",e,Date.now()-n),this.semaphore.release(),r(e),this.options.cache&&v.set(this,a))}).catch(o=>{if(!s){this.semaphore.release();const s=Date.now()-n;T(o,this,t,e,s,r,i)}})}catch(s){this.semaphore.release();const o=Date.now()-n;T(s,this,t,e,o,r,i)}}else{const s=Date.now()-n,o=new Error("Semaphore locked");o.code="ESEMLOCKED",this.emit("semaphoreLocked",o,s),T(o,this,t,e,s,r,i)}})}clearCache(){v.set(this,void 0)}healthCheck(e,t){if(t=t||5e3,"function"!=typeof e)throw new TypeError("Health check function must be a function");if(isNaN(t))throw new TypeError("Health check interval must be a number");const s=t=>{e.apply(this).catch(e=>{this.emit("healthCheckFailed",e),this.open()})},r=setInterval(s,t);"function"==typeof r.unref&&r.unref(),s()}enable(){this[w]=!0}disable(){this[w]=!1}}function T(e,t,s,r,i,n,o){clearTimeout(s),function(e,t,s,r){if(e.options.errorFilter(t))return;if(e.emit("failure",t,r,s),e.warmUp)return;const i=e.stats;if(i.fires<e.volumeThreshold&&!e.halfOpen)return;(i.failures/i.fires*100>e.options.errorThresholdPercentage||i.failures>=e.options.maxFailures||e.halfOpen)&&e.open()}(t,e,r,i);const a=k(t,e,r);a?n(a):o(e)}function k(e,t,s){if(e[f]){const r=e[f].apply(e[f],[...s,t]);return e.emit("fallback",r,t),r instanceof Promise?r:Promise.resolve(r)}}const O=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});e.exports=j},function(e,t,s){"use strict";const r=Symbol("window"),i=Symbol("buckets"),n=Symbol("timeout"),o=Symbol("percentiles"),a=s(6).EventEmitter;const c=e=>t=>{e.pop(),e.unshift(l())},l=e=>({failures:0,fallbacks:0,successes:0,rejects:0,fires:0,timeouts:0,cacheHits:0,cacheMisses:0,semaphoreRejections:0,percentiles:{},latencyTimes:[]});e.exports=class extends a{constructor(e){super(),this[i]=e.rollingCountBuckets,this[n]=e.rollingCountTimeout,this[r]=new Array(this[i]),this[o]=[0,.25,.5,.75,.9,.95,.99,.995,1],this.rollingPercentilesEnabled=e.rollingPercentilesEnabled;for(let e=0;e<this[i];e++)this[r][e]=l();const t=Math.floor(this[n]/this[i]);let s=setInterval(c(this[r]),t);"function"==typeof s.unref&&s.unref(),"function"==typeof(s=setInterval(e=>this.emit("snapshot",this.stats),t)).unref&&s.unref()}get stats(){const e=this[r].reduce((e,t)=>t?(Object.keys(e).forEach(s=>{"latencyTimes"!==s&&"percentiles"!==s&&(e[s]+=t[s]||0)}),this.rollingPercentilesEnabled&&e.latencyTimes.push.apply(e.latencyTimes,t.latencyTimes||[]),e):e,l());return this.rollingPercentilesEnabled?(e.latencyTimes.sort((e,t)=>e-t),e.latencyTimes.length?e.latencyMean=e.latencyTimes.reduce((e,t)=>e+t,0)/e.latencyTimes.length:e.latencyMean=0,this[o].forEach(t=>{e.percentiles[t]=function(e,t){if(0===e)return t[0]||0;const s=Math.ceil(e*t.length);return t[s-1]||0}(t,e.latencyTimes)})):(e.latencyMean=-1,this[o].forEach(t=>{e.percentiles[t]=-1})),e}get window(){return this[r].slice()}increment(e,t){this[r][0][e]++,"successes"!==e&&"failures"!==e&&"timeouts"!==e||this[r][0].latencyTimes.push(t||0)}open(){this[r][0].isCircuitBreakerOpen=!0}close(){this[r][0].isCircuitBreakerOpen=!1}shutdown(){this.removeAllListeners()}}},function(e,t){e.exports=require("stream")},function(e,t,s){"use strict";function r(e){return{0:e.percentiles[0],25:e.percentiles[.25],50:e.percentiles[.5],75:e.percentiles[.75],90:e.percentiles[.9],95:e.percentiles[.95],99:e.percentiles[.99],99.5:e.percentiles[.995],100:e.percentiles[1]}}e.exports=function(e){return{type:"HystrixCommand",name:e.name,group:e.group,currentTime:Date.now(),isCircuitBreakerOpen:!e.closed,errorPercentage:0===e.fires?0:e.failures/e.fires*100,errorCount:e.failures,requestCount:e.fires,rollingCountBadRequests:e.failures,rollingCountCollapsedRequests:0,rollingCountEmit:e.fires,rollingCountExceptionsThrown:0,rollingCountFailure:e.failures,rollingCountFallbackEmit:e.fallbacks,rollingCountFallbackFailure:0,rollingCountFallbackMissing:0,rollingCountFallbackRejection:0,rollingCountFallbackSuccess:0,rollingCountResponsesFromCache:e.cacheHits,rollingCountSemaphoreRejected:e.semaphoreRejections,rollingCountShortCircuited:e.rejects,rollingCountSuccess:e.successes,rollingCountThreadPoolRejected:0,rollingCountTimeout:e.timeouts,currentConcurrentExecutionCount:0,rollingMaxConcurrentExecutionCount:0,latencyExecute_mean:e.latencyMean||0,latencyExecute:r(e),latencyTotal_mean:e.latencyMean,latencyTotal:r(e),propertyValue_circuitBreakerRequestVolumeThreshold:5,propertyValue_circuitBreakerSleepWindowInMilliseconds:e.options.resetTimeout,propertyValue_circuitBreakerErrorThresholdPercentage:e.options.errorThresholdPercentage,propertyValue_circuitBreakerForceOpen:!1,propertyValue_circuitBreakerForceClosed:!1,propertyValue_circuitBreakerEnabled:!0,propertyValue_executionIsolationStrategy:"THREAD",propertyValue_executionIsolationThreadTimeoutInMilliseconds:300,propertyValue_executionTimeoutInMilliseconds:e.options.timeout,propertyValue_executionIsolationThreadInterruptOnTimeout:!0,propertyValue_executionIsolationThreadPoolKeyOverride:null,propertyValue_executionIsolationSemaphoreMaxConcurrentRequests:e.options.capacity,propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests:e.options.capacity,propertyValue_metricsRollingStatisticalWindowInMilliseconds:1e4,propertyValue_requestCacheEnabled:e.options.cache||!1,propertyValue_requestLogEnabled:!0,reportingHosts:1}}},function(e,t,s){"use strict";e.exports=function(e){const t=[];let s=e,r={take:i,release:n,test:function(){return!(s<1)&&i()&&!0}};return Object.defineProperty(r,"count",{get:e=>s,enumerable:!0}),r;function i(e){return s>0?(--s,Promise.resolve(n)):new Promise((r,i)=>{t.push(e=>{--s,r(n)}),e&&setTimeout(s=>{t.shift();const r=new Error(`Timed out after ${e}ms`);r.code="ETIMEDOUT",i(r)},e)})}function n(){s++,t.length>0&&t.shift()()}}},function(e,t,s){"use strict";const r=s(20);e.exports=class{constructor(e){this.circuit=e,this._client=r,this.counters=[];const t=`circuit_${this.circuit.name.replace(/[ |-]/g,"_")}_`;this.interval=this._client.collectDefaultMetrics({prefix:t,timeout:5e3});for(let s of this.circuit.eventNames()){const r=new this._client.Counter({name:`${t}${s}`,help:`A count of the ${e.name} circuit's ${s} event`});this.circuit.on(s,e=>{r.inc()}),this.counters.push(r)}}clear(){clearInterval(this.interval),this._client.register.clear()}get metrics(){return this._client.register.metrics()}get client(){return this._client}}},function(e,t,s){"use strict";t.register=s(1).globalRegistry,t.Registry=s(1),t.contentType=s(1).globalRegistry.contentType,t.Counter=s(8),t.Gauge=s(0),t.Histogram=s(21),t.Summary=s(22),t.Pushgateway=s(28),t.linearBuckets=s(10).linearBuckets,t.exponentialBuckets=s(10).exponentialBuckets,t.collectDefaultMetrics=s(32),t.aggregators=s(12).aggregators,t.AggregatorRegistry=s(47)},function(e,t,s){"use strict";const r=s(3),i=s(1).globalRegistry,n="histogram",{getPropertiesFromObj:o,getLabels:a,hashObject:c,isObject:l,printDeprecationObjectConstructor:u,removeLabels:h}=s(2),{validateMetricName:p,validateLabel:m,validateLabelName:f}=s(4);function d(e){return()=>{const t=process.hrtime();return s=>{const r=process.hrtime(t);this.observe(Object.assign({},e,s),r[0]+r[1]/1e9)}}}function g(e,t){return e-t}function _(e,t,s){return{labels:e,value:t,metricName:s}}function b(e){return t=>{const s=function(e,t){if(!l(e))return{value:e,labels:{}};return{labels:e,value:t}}(e,t);if(m(this.labelNames,s.labels),!Number.isFinite(s.value))throw new TypeError(`Value is not a valid number: ${r.format(s.value)}`);const i=c(s.labels);let n=this.hashMap[i];n||(n=y(s.labels,Object.assign({},this.bucketValues)));const o=function(e,t){for(let s=0;s<e.length;s++){const r=e[s];if(t<=r)return r}return-1}(this.upperBounds,s.value);n.sum+=s.value,n.count+=1,n.bucketValues.hasOwnProperty(o)&&(n.bucketValues[o]+=1),this.hashMap[i]=n}}function y(e,t){return{labels:e,bucketValues:t,sum:0,count:0}}e.exports=class{constructor(e,t,s,r){let n;if(l(e))(n=Object.assign({buckets:[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10],labelNames:[]},e)).registers||(n.registers=[i]);else{let a,c=[];Array.isArray(s)?(a=r||{},c=s):a=s||{},u(),n={name:e,labelNames:c,help:t,buckets:(o=a.buckets,[].concat(o||[.005,.01,.025,.05,.1,.25,.5,1,2.5,5,10]).sort(g)),registers:[i]}}var o;!function(e,t,s){if(!t)throw new Error("Missing mandatory help parameter");if(!e)throw new Error("Missing mandatory name parameter");if(!p(e))throw new Error("Invalid metric name");if(!f(s))throw new Error("Invalid label name");s.forEach(e=>{if("le"===e)throw new Error("le is a reserved label keyword")})}(n.name,n.help,n.labelNames),this.name=n.name,this.help=n.help,this.aggregator=n.aggregator||"sum",this.upperBounds=n.buckets,this.bucketValues=this.upperBounds.reduce((e,t)=>(e[t]=0,e),{}),Object.freeze(this.bucketValues),Object.freeze(this.upperBounds),this.sum=0,this.count=0,this.hashMap={},this.labelNames=n.labelNames||[],0===this.labelNames.length&&(this.hashMap={[c({})]:y({},Object.assign({},this.bucketValues))}),n.registers.forEach(e=>e.registerMetric(this))}observe(e,t){b.call(this,0===e?0:e||{})(t)}get(){const e=o(this.hashMap).map((t=this,e=>{const s=[],r=Object.keys(e.labels);let i=0;for(const n of t.upperBounds){i+=e.bucketValues[n];const o={le:n};for(const t of r)o[t]=e.labels[t];s.push(_(o,i,`${t.name}_bucket`))}return{buckets:s,data:e}})).reduce(function(e){return(t,s)=>{t.push(...s.buckets);const r={le:"+Inf"};for(const e of Object.keys(s.data.labels))r[e]=s.data.labels[e];return t.push(_(r,s.data.count,`${e.name}_bucket`),_(s.data.labels,s.data.sum,`${e.name}_sum`),_(s.data.labels,s.data.count,`${e.name}_count`)),t}}(this),[]);var t;return{name:this.name,help:this.help,type:n,values:e,aggregator:this.aggregator}}reset(){this.sum=0,this.count=0,this.hashMap={}}startTimer(e){return d.call(this,e)()}labels(){const e=a(this.labelNames,arguments);return{observe:b.call(this,e),startTimer:d.call(this,e)}}remove(){const e=a(this.labelNames,arguments);h.call(this,this.hashMap,e)}}},function(e,t,s){"use strict";const r=s(3),{globalRegistry:i}=s(1),n="summary",{getPropertiesFromObj:o,getLabels:a,hashObject:c,isObject:l,printDeprecationObjectConstructor:u,removeLabels:h}=s(2),{validateLabel:p,validateMetricName:m,validateLabelName:f}=s(4),d=s(23);function g(e){return()=>{const t=process.hrtime();return s=>{const r=process.hrtime(t);this.observe(Object.assign({},e,s),r[0]+r[1]/1e9)}}}function _(e,t){return e-t}function b(e){return t=>{const s=function(e,t){if(void 0===t)return{value:e,labels:{}};return{labels:e,value:t}}(e,t);if(p(this.labelNames,this.labels),!Number.isFinite(s.value))throw new TypeError(`Value is not a valid number: ${r.format(s.value)}`);const i=c(s.labels);let n=this.hashMap[i];n||(n={labels:s.labels,td:new d(this.maxAgeSeconds,this.ageBuckets),count:0,sum:0}),n.td.push(s.value),n.count++,n.sum+=s.value,this.hashMap[i]=n}}e.exports=class{constructor(e,t,s,r){let n;if(l(e))(n=Object.assign({percentiles:[.01,.05,.5,.9,.95,.99,.999],labelNames:[]},e)).registers||(n.registers=[i]);else{let a,c=[];Array.isArray(s)?(a=r||{},c=s):a=s||{},u(),n={name:e,help:t,labelNames:c,percentiles:(o=a.percentiles,[].concat(o||[.01,.05,.5,.9,.95,.99,.999]).sort(_)),registers:[i],maxAgeSeconds:a.maxAgeSeconds,ageBuckets:a.ageBuckets}}var o;!function(e,t,s){if(!t)throw new Error("Missing mandatory help parameter");if(!e)throw new Error("Missing mandatory name parameter");if(!m(e))throw new Error("Invalid metric name");if(!f(s))throw new Error("Invalid label name");s.forEach(e=>{if("quantile"===e)throw new Error("quantile is a reserved label keyword")})}(n.name,n.help,n.labelNames),this.maxAgeSeconds=n.maxAgeSeconds,this.ageBuckets=n.ageBuckets,this.name=n.name,this.help=n.help,this.aggregator=n.aggregator||"sum",this.percentiles=n.percentiles,this.hashMap={},this.labelNames=n.labelNames||[],0===this.labelNames.length&&(this.hashMap={[c({})]:{labels:{},td:new d(this.maxAgeSeconds,this.ageBuckets),count:0,sum:0}}),n.registers.forEach(e=>e.registerMetric(this))}observe(e,t){b.call(this,0===e?0:e||{})(t)}get(){const e=o(this.hashMap),t=[];return e.forEach(e=>{(function(e,t){return e.td.compress(),t.map(t=>{const s=e.td.percentile(t);return{labels:Object.assign({quantile:t},e.labels),value:s||0}})})(e,this.percentiles).forEach(e=>{t.push(e)}),t.push(function(e,t){return{metricName:`${t.name}_sum`,labels:e.labels,value:e.sum}}(e,this)),t.push(function(e,t){return{metricName:`${t.name}_count`,labels:e.labels,value:e.count}}(e,this))}),{name:this.name,help:this.help,type:n,values:t,aggregator:this.aggregator}}reset(){o(this.hashMap).forEach(e=>{e.td.reset(),e.count=0,e.sum=0})}startTimer(e){return g.call(this,e)()}labels(){const e=a(this.labelNames,arguments);return{observe:b.call(this,e),startTimer:g.call(this,e)}}remove(){const e=a(this.labelNames,arguments);h.call(this,this.hashMap,e)}}},function(e,t,s){"use strict";const{TDigest:r}=s(24);function i(){let e=Date.now()-this.lastRotateTimestampMillis;for(;e>this.durationBetweenRotatesMillis&&this.shouldRotate;)this.ringBuffer[this.currentBuffer]=new r,++this.currentBuffer>=this.ringBuffer.length&&(this.currentBuffer=0),e-=this.durationBetweenRotatesMillis,this.lastRotateTimestampMillis+=this.durationBetweenRotatesMillis;return this.ringBuffer[this.currentBuffer]}e.exports=class{constructor(e,t){this.maxAgeSeconds=e||0,this.ageBuckets=t||0,this.shouldRotate=e&&t,this.ringBuffer=Array(t).fill(new r),this.currentBuffer=0,this.lastRotateTimestampMillis=Date.now(),this.durationBetweenRotatesMillis=1e3*e/t||1/0}percentile(e){return i.call(this).percentile(e)}push(e){i.call(this),this.ringBuffer.forEach(t=>{t.push(e)})}reset(){this.ringBuffer.forEach(e=>{e.reset()})}compress(){this.ringBuffer.forEach(e=>{e.compress()})}}},function(e,t,s){var r=s(25).RBTree;function i(e,t,s){this.discrete=!1===e,this.delta=e||.01,this.K=void 0===t?25:t,this.CX=void 0===s?1.1:s,this.centroids=new r(n),this.nreset=0,this.reset()}function n(e,t){return e.mean>t.mean?1:e.mean<t.mean?-1:0}function o(e,t){return e.mean_cumn-t.mean_cumn}function a(e){this.config=e||{},this.mode=this.config.mode||"auto",i.call(this,"cont"===this.mode&&e.delta),this.digest_ratio=this.config.ratio||.9,this.digest_thresh=this.config.thresh||1e3,this.n_unique=0}i.prototype.reset=function(){this.centroids.clear(),this.n=0,this.nreset+=1,this.last_cumulate=0},i.prototype.size=function(){return this.centroids.size},i.prototype.toArray=function(e){var t=[];return e?(this._cumulate(!0),this.centroids.each(function(e){t.push(e)})):this.centroids.each(function(e){t.push({mean:e.mean,n:e.n})}),t},i.prototype.summary=function(){return[(this.discrete?"exact ":"approximating ")+this.n+" samples using "+this.size()+" centroids","min = "+this.percentile(0),"Q1 = "+this.percentile(.25),"Q2 = "+this.percentile(.5),"Q3 = "+this.percentile(.75),"max = "+this.percentile(1)].join("\n")},i.prototype.push=function(e,t){t=t||1,e=Array.isArray(e)?e:[e];for(var s=0;s<e.length;s++)this._digest(e[s],t)},i.prototype.push_centroid=function(e){e=Array.isArray(e)?e:[e];for(var t=0;t<e.length;t++)this._digest(e[t].mean,e[t].n)},i.prototype._cumulate=function(e){if(!(this.n===this.last_cumulate||!e&&this.CX&&this.CX>this.n/this.last_cumulate)){var t=0;this.centroids.each(function(e){e.mean_cumn=t+e.n/2,t=e.cumn=t+e.n}),this.n=this.last_cumulate=t}},i.prototype.find_nearest=function(e){if(0===this.size())return null;var t=this.centroids.lowerBound({mean:e}),s=null===t.data()?t.prev():t.data();if(s.mean===e||this.discrete)return s;var r=t.prev();return r&&Math.abs(r.mean-e)<Math.abs(s.mean-e)?r:s},i.prototype._new_centroid=function(e,t,s){var r={mean:e,n:t,cumn:s};return this.centroids.insert(r),this.n+=t,r},i.prototype._addweight=function(e,t,s){t!==e.mean&&(e.mean+=s*(t-e.mean)/(e.n+s)),e.cumn+=s,e.mean_cumn+=s/2,e.n+=s,this.n+=s},i.prototype._digest=function(e,t){var s=this.centroids.min(),r=this.centroids.max(),i=this.find_nearest(e);if(i&&i.mean===e)this._addweight(i,e,t);else if(i===s)this._new_centroid(e,t,0);else if(i===r)this._new_centroid(e,t,this.n);else if(this.discrete)this._new_centroid(e,t,i.cumn);else{var n=i.mean_cumn/this.n;Math.floor(4*this.n*this.delta*n*(1-n))-i.n>=t?this._addweight(i,e,t):this._new_centroid(e,t,i.cumn)}this._cumulate(!1),!this.discrete&&this.K&&this.size()>this.K/this.delta&&this.compress()},i.prototype.bound_mean=function(e){var t=this.centroids.upperBound({mean:e}),s=t.prev();return[s,s.mean===e?s:t.next()]},i.prototype.p_rank=function(e){var t=(Array.isArray(e)?e:[e]).map(this._p_rank,this);return Array.isArray(e)?t:t[0]},i.prototype._p_rank=function(e){if(0!==this.size()){if(e<this.centroids.min().mean)return 0;if(e>this.centroids.max().mean)return 1;this._cumulate(!0);var t=this.bound_mean(e),s=t[0],r=t[1];if(this.discrete)return s.cumn/this.n;var i=s.mean_cumn;return s!==r&&(i+=(e-s.mean)*(r.mean_cumn-s.mean_cumn)/(r.mean-s.mean)),i/this.n}},i.prototype.bound_mean_cumn=function(e){this.centroids._comparator=o;var t=this.centroids.upperBound({mean_cumn:e});this.centroids._comparator=n;var s=t.prev();return[s,s&&s.mean_cumn===e?s:t.next()]},i.prototype.percentile=function(e){var t=(Array.isArray(e)?e:[e]).map(this._percentile,this);return Array.isArray(e)?t:t[0]},i.prototype._percentile=function(e){if(0!==this.size()){this._cumulate(!0);this.centroids.min(),this.centroids.max();var t=this.n*e,s=this.bound_mean_cumn(t),r=s[0],i=s[1];return i===r||null===r||null===i?(r||i).mean:this.discrete?t<=r.cumn?r.mean:i.mean:r.mean+(t-r.mean_cumn)*(i.mean-r.mean)/(i.mean_cumn-r.mean_cumn)}},i.prototype.compress=function(){if(!this.compressing){var e,t,s=this.toArray();for(this.reset(),this.compressing=!0;s.length>0;)this.push_centroid((e=s,t=void 0,t=Math.floor(Math.random()*e.length),e.splice(t,1)[0]));this._cumulate(!0),this.compressing=!1}},a.prototype=Object.create(i.prototype),a.prototype.constructor=a,a.prototype.push=function(e){i.prototype.push.call(this,e),this.check_continuous()},a.prototype._new_centroid=function(e,t,s){this.n_unique+=1,i.prototype._new_centroid.call(this,e,t,s)},a.prototype._addweight=function(e,t,s){1===e.n&&(this.n_unique-=1),i.prototype._addweight.call(this,e,t,s)},a.prototype.check_continuous=function(){return!("auto"!==this.mode||this.size()<this.digest_thresh)&&(this.n_unique/this.size()>this.digest_ratio&&(this.mode="cont",this.discrete=!1,this.delta=this.config.delta||.01,this.compress(),!0))},e.exports={TDigest:i,Digest:a}},function(e,t,s){e.exports={RBTree:s(26),BinTree:s(27)}},function(e,t,s){var r=s(9);function i(e){this.data=e,this.left=null,this.right=null,this.red=!0}function n(e){this._root=null,this._comparator=e,this.size=0}function o(e){return null!==e&&e.red}function a(e,t){var s=e.get_child(!t);return e.set_child(!t,s.get_child(t)),s.set_child(t,e),e.red=!0,s.red=!1,s}function c(e,t){return e.set_child(!t,a(e.get_child(!t),!t)),a(e,t)}i.prototype.get_child=function(e){return e?this.right:this.left},i.prototype.set_child=function(e,t){e?this.right=t:this.left=t},n.prototype=new r,n.prototype.insert=function(e){var t=!1;if(null===this._root)this._root=new i(e),t=!0,this.size++;else{var s=new i(void 0),r=0,n=0,l=null,u=s,h=null,p=this._root;for(u.right=this._root;;){if(null===p?(p=new i(e),h.set_child(r,p),t=!0,this.size++):o(p.left)&&o(p.right)&&(p.red=!0,p.left.red=!1,p.right.red=!1),o(p)&&o(h)){var m=u.right===l;p===h.get_child(n)?u.set_child(m,a(l,!n)):u.set_child(m,c(l,!n))}var f=this._comparator(p.data,e);if(0===f)break;n=r,r=f<0,null!==l&&(u=l),l=h,h=p,p=p.get_child(r)}this._root=s.right}return this._root.red=!1,t},n.prototype.remove=function(e){if(null===this._root)return!1;var t=new i(void 0),s=t;s.right=this._root;for(var r=null,n=null,l=null,u=1;null!==s.get_child(u);){var h=u;n=r,r=s,s=s.get_child(u);var p=this._comparator(e,s.data);if(u=p>0,0===p&&(l=s),!o(s)&&!o(s.get_child(u)))if(o(s.get_child(!u))){var m=a(s,u);r.set_child(h,m),r=m}else if(!o(s.get_child(!u))){var f=r.get_child(!h);if(null!==f)if(o(f.get_child(!h))||o(f.get_child(h))){var d=n.right===r;o(f.get_child(h))?n.set_child(d,c(r,h)):o(f.get_child(!h))&&n.set_child(d,a(r,h));var g=n.get_child(d);g.red=!0,s.red=!0,g.left.red=!1,g.right.red=!1}else r.red=!1,f.red=!0,s.red=!0}}return null!==l&&(l.data=s.data,r.set_child(r.right===s,s.get_child(null===s.left)),this.size--),this._root=t.right,null!==this._root&&(this._root.red=!1),null!==l},e.exports=n},function(e,t,s){var r=s(9);function i(e){this.data=e,this.left=null,this.right=null}function n(e){this._root=null,this._comparator=e,this.size=0}i.prototype.get_child=function(e){return e?this.right:this.left},i.prototype.set_child=function(e,t){e?this.right=t:this.left=t},n.prototype=new r,n.prototype.insert=function(e){if(null===this._root)return this._root=new i(e),this.size++,!0;for(var t=0,s=null,r=this._root;;){if(null===r)return r=new i(e),s.set_child(t,r),ret=!0,this.size++,!0;if(0===this._comparator(r.data,e))return!1;t=this._comparator(r.data,e)<0,s=r,r=r.get_child(t)}},n.prototype.remove=function(e){if(null===this._root)return!1;var t=new i(void 0),s=t;s.right=this._root;for(var r=null,n=null,o=1;null!==s.get_child(o);){r=s,s=s.get_child(o);var a=this._comparator(e,s.data);o=a>0,0===a&&(n=s)}return null!==n&&(n.data=s.data,r.set_child(r.right===s,s.get_child(null===s.left)),this._root=t.right,this.size--,!0)},e.exports=n},function(e,t,s){"use strict";const r=s(29),i=s(30),n=s(31),{globalRegistry:o}=s(1);function a(e,t,s,o){const a=r.parse(this.gatewayUrl),c=`${a.pathname&&"/"!==a.pathname?a.pathname:""}/metrics/job/${encodeURIComponent(t)}${function(e){if(!e)return"";return Object.keys(e).map(t=>`/${encodeURIComponent(t)}/${encodeURIComponent(e[t])}`).join("")}(s)}`,l=r.resolve(this.gatewayUrl,c),u=r.parse(l),h=-1!==u.href.search(/^https/)?n:i;const p=Object.assign(u,this.requestOptions,{method:e}),m=h.request(p,e=>{let t="";e.setEncoding("utf8"),e.on("data",e=>{t+=e}),e.on("end",()=>{o(null,e,t)})});m.on("error",e=>{o(e)}),"DELETE"!==e&&m.write(this.registry.metrics({timestamps:!1})),m.end()}e.exports=class{constructor(e,t,s){s||(s=o),this.registry=s,this.gatewayUrl=e,this.requestOptions=Object.assign({},t)}pushAdd(e,t){if(!e||!e.jobName)throw new Error("Missing jobName parameter");a.call(this,"POST",e.jobName,e.groupings,t)}push(e,t){if(!e||!e.jobName)throw new Error("Missing jobName parameter");a.call(this,"PUT",e.jobName,e.groupings,t)}delete(e,t){if(!e||!e.jobName)throw new Error("Missing jobName parameter");a.call(this,"DELETE",e.jobName,e.groupings,t)}}},function(e,t){e.exports=require("url")},function(e,t){e.exports=require("http")},function(e,t){e.exports=require("https")},function(e,t,s){"use strict";const r=s(33),i=s(34),n=s(35),o=s(37),a=s(39),c=s(40),l=s(41),u=s(42),h=s(43),p=s(44),m=s(46),{globalRegistry:f}=s(1),{printDeprecationCollectDefaultMetricsNumber:d}=s(2),g={processCpuTotal:r,processStartTime:i,osMemoryHeap:n,processOpenFileDescriptors:o,processMaxFileDescriptors:a,eventLoopLag:c,processHandles:l,processRequests:u,heapSizeAndUsed:h,heapSpacesSizeAndUsed:p,version:m},_=Object.keys(g);let b=null,y=!0;e.exports=function(e){let t=e;"number"==typeof e&&(d(e),t={timeout:e}),t=Object.assign({timeout:1e4},t),null!==b&&clearInterval(b);const s=_.map(s=>{const r=g[s];return y||r.metricNames.map(f.removeSingleMetric,f),r(t.register,e)});function r(){s.forEach(e=>e.call())}return r(),b=setInterval(r,t.timeout).unref(),y=!1,b},e.exports.metricsList=_},function(e,t,s){"use strict";const r=s(8);e.exports=(e,t={})=>{if("function"!=typeof process.cpuUsage)return()=>{};const s=e?[e]:void 0,i=t.prefix?t.prefix:"",n=new r({name:i+"process_cpu_user_seconds_total",help:"Total user CPU time spent in seconds.",registers:s}),o=new r({name:i+"process_cpu_system_seconds_total",help:"Total system CPU time spent in seconds.",registers:s}),a=new r({name:i+"process_cpu_seconds_total",help:"Total user and system CPU time spent in seconds.",registers:s});let c=process.cpuUsage();return()=>{const e=process.cpuUsage(),t=Date.now(),s=e.user-c.user,r=e.system-c.system;c=e,n.inc(s/1e6,t),o.inc(r/1e6,t),a.inc((s+r)/1e6,t)}},e.exports.metricNames=["process_cpu_user_seconds_total","process_cpu_system_seconds_total","process_cpu_seconds_total"]},function(e,t,s){"use strict";const r=s(0),i=Math.round(Date.now()/1e3-process.uptime());e.exports=(e,t={})=>{const s=t.prefix?t.prefix:"",n=new r({name:s+"process_start_time_seconds",help:"Start time of the process since unix epoch in seconds.",registers:e?[e]:void 0,aggregator:"omit"});let o=!1;return()=>{o||(n.set(i),o=!0)}},e.exports.metricNames=["process_start_time_seconds"]},function(e,t,s){"use strict";const r=s(0),i=s(36),n=s(11),o="process_resident_memory_bytes";e.exports=(e,t)=>"linux"===process.platform?i(e,t):function(e,t={}){const s=t.prefix?t.prefix:"",i=new r({name:s+o,help:"Resident memory size in bytes.",registers:e?[e]:void 0});return()=>{const e=n();e&&i.set(e.rss,Date.now())}}(e,t),e.exports.metricNames="linux"===process.platform?i.metricNames:[o]},function(e,t,s){"use strict";const r=s(0),i=s(5),n=["VmSize","VmRSS","VmData"];e.exports=(e,t={})=>{const s=e?[e]:void 0,o=t.prefix?t.prefix:"",a=new r({name:o+"process_resident_memory_bytes",help:"Resident memory size in bytes.",registers:s}),c=new r({name:o+"process_virtual_memory_bytes",help:"Virtual memory size in bytes.",registers:s}),l=new r({name:o+"process_heap_bytes",help:"Process heap size in bytes.",registers:s});return()=>{i.readFile("/proc/self/status","utf8",(e,t)=>{if(e)return;const s=Date.now(),r=function(e){const t={};return e.split("\n").filter(e=>n.some(t=>0===e.indexOf(t))).forEach(e=>{const s=e.split(":");let r=s[1].trim();r=r.substr(0,r.length-3),r=1024*Number(r),t[s[0]]=r}),t}(t);a.set(r.VmRSS,s),c.set(r.VmSize,s),l.set(r.VmData,s)})}},e.exports.metricNames=["process_resident_memory_bytes","process_virtual_memory_bytes","process_heap_bytes"]},function(e,t,s){"use strict";const r=s(0),i=s(5),n=s(38);e.exports=(e,t={})=>{if("linux"!==n.platform)return()=>{};const s=t.prefix?t.prefix:"",o=new r({name:s+"process_open_fds",help:"Number of open file descriptors.",registers:e?[e]:void 0});return()=>{i.readdir("/proc/self/fd",(e,t)=>{e||o.set(t.length-1,Date.now())})}},e.exports.metricNames=["process_open_fds"]},function(e,t){e.exports=require("process")},function(e,t,s){"use strict";const r=s(0),i=s(5);e.exports=(e,t={})=>{let s=!1;if("linux"!==process.platform)return()=>{};const n=t.prefix?t.prefix:"",o=new r({name:n+"process_max_fds",help:"Maximum number of open file descriptors.",registers:e?[e]:void 0});return()=>{s||i.readFile("/proc/sys/fs/file-max","utf8",(e,t)=>{e||(s=!0,o.set(Number(t)))})}},e.exports.metricNames=["process_max_fds"]},function(e,t,s){"use strict";const r=s(0);function i(e,t){const s=process.hrtime(e),r=(1e9*s[0]+s[1])/1e9;t.set(r,Date.now())}e.exports=(e,t={})=>{const s=t.prefix?t.prefix:"",n=new r({name:s+"nodejs_eventloop_lag_seconds",help:"Lag of event loop in seconds.",registers:e?[e]:void 0,aggregator:"average"});return()=>{const e=process.hrtime();setImmediate(i,e,n)}},e.exports.metricNames=["nodejs_eventloop_lag_seconds"]},function(e,t,s){"use strict";const r=s(0);e.exports=(e,t={})=>{if("function"!=typeof process._getActiveHandles)return()=>{};const s=t.prefix?t.prefix:"",i=new r({name:s+"nodejs_active_handles_total",help:"Number of active handles.",registers:e?[e]:void 0});return()=>{i.set(process._getActiveHandles().length,Date.now())}},e.exports.metricNames=["nodejs_active_handles_total"]},function(e,t,s){"use strict";const r=s(0);e.exports=(e,t={})=>{if("function"!=typeof process._getActiveRequests)return()=>{};const s=t.prefix?t.prefix:"",i=new r({name:s+"nodejs_active_requests_total",help:"Number of active requests.",registers:e?[e]:void 0});return()=>{i.set(process._getActiveRequests().length,Date.now())}},e.exports.metricNames=["nodejs_active_requests_total"]},function(e,t,s){"use strict";const r=s(0),i=s(11);e.exports=(e,t={})=>{if("function"!=typeof process.memoryUsage)return()=>{};const s=e?[e]:void 0,n=t.prefix?t.prefix:"",o=new r({name:n+"nodejs_heap_size_total_bytes",help:"Process heap size from node.js in bytes.",registers:s}),a=new r({name:n+"nodejs_heap_size_used_bytes",help:"Process heap size used from node.js in bytes.",registers:s});let c;const l=i();return l&&l.external&&(c=new r({name:n+"nodejs_external_memory_bytes",help:"Nodejs external memory size in bytes.",registers:s})),()=>{const e=i();if(e){const t=Date.now();o.set(e.heapTotal,t),a.set(e.heapUsed,t),e.external&&c&&c.set(e.external,t)}return{total:o,used:a,external:c}}},e.exports.metricNames=["nodejs_heap_size_total_bytes","nodejs_heap_size_used_bytes","nodejs_external_memory_bytes"]},function(e,t,s){"use strict";const r=s(0);let i;try{i=s(45)}catch(e){}const n=["total","used","available"],o={};n.forEach(e=>{o[e]=`nodejs_heap_space_size_${e}_bytes`}),e.exports=(e,t={})=>{if(void 0===i||"function"!=typeof i.getHeapSpaceStatistics)return()=>{};const s=e?[e]:void 0,a=t.prefix?t.prefix:"",c={};return n.forEach(e=>{c[e]=new r({name:a+o[e],help:`Process heap space size ${e} from node.js in bytes.`,labelNames:["space"],registers:s})}),()=>{const e={total:{},used:{},available:{}},t=Date.now();return i.getHeapSpaceStatistics().forEach(s=>{const r=s.space_name.substr(0,s.space_name.indexOf("_space"));e.total[r]=s.space_size,e.used[r]=s.space_used_size,e.available[r]=s.space_available_size,c.total.set({space:r},s.space_size,t),c.used.set({space:r},s.space_used_size,t),c.available.set({space:r},s.space_available_size,t)}),e}},e.exports.metricNames=n.map(e=>o[e])},function(e,t){e.exports=require("v8")},function(e,t,s){"use strict";const r=s(0),i=process.version,n=i.slice(1).split(".").map(Number);e.exports=(e,t={})=>{const s=t.prefix?t.prefix:"",o=new r({name:s+"nodejs_version_info",help:"Node.js version info.",labelNames:["version","major","minor","patch"],registers:e?[e]:void 0,aggregator:"first"});let a=!1;return()=>{a||(o.labels(i,n[0],n[1],n[2]).set(1),a=!0)}},e.exports.metricNames=["nodejs_version_info"]},function(e,t,s){"use strict";const r=s(48),i=s(1),{Grouper:n}=s(2),{aggregators:o}=s(12),a="prom-client:getMetricsReq",c="prom-client:getMetricsRes";let l=[i.globalRegistry],u=0,h=!1;const p=new Map;class m extends i{constructor(){super(),function(){if(h)return;h=!0,r.isMaster&&r.on("message",(e,t)=>{if(t.type===c){const e=p.get(t.requestId);if(t.metrics.forEach(t=>e.responses.push(t)),e.pending--,0===e.pending){if(p.delete(t.requestId),clearTimeout(e.errorTimeout),e.failed)return;const s=m.aggregate(e.responses),r=s.metrics();e.done(null,r)}}})}()}clusterMetrics(e){const t=u++;return new Promise((s,i)=>{function n(t,r){"function"==typeof e?e(t,r):t?i(t):s(r)}const o={responses:[],pending:0,done:n,errorTimeout:setTimeout(()=>{o.failed=!0;const e=new Error("Operation timed out.");o.done(e)},5e3),failed:!1};p.set(t,o);const c={type:a,requestId:t};for(const e in r.workers)r.workers[e].isConnected()&&(r.workers[e].send(c),o.pending++);0===o.pending&&(clearTimeout(o.errorTimeout),process.nextTick(()=>n(null,"")))})}static aggregate(e){const t=new i,s=new n;return e.forEach(e=>{e.forEach(e=>{s.add(e.name,e)})}),s.forEach(e=>{const s=e[0].aggregator,r=o[s];if("function"!=typeof r)throw new Error(`'${s}' is not a defined aggregator.`);const i=r(e);if(i){const e=Object.assign({get:()=>i},i);t.registerMetric(e)}}),t}static setRegistries(e){Array.isArray(e)||(e=[e]),e.forEach(e=>{if(!(e instanceof i))throw new TypeError(`Expected Registry, got ${typeof e}`)}),l=e}}r.isWorker&&process.on("message",e=>{e.type===a&&process.send({type:c,requestId:e.requestId,metrics:l.map(e=>e.getMetricsAsJSON())})}),e.exports=m},function(e,t){e.exports=require("cluster")},function(e,t,s){"use strict";e.exports=function(e){return function(){return new Promise((t,s)=>{const r=Array.prototype.slice.call(arguments);r.push((e,r)=>{e&&s(e),t(r)}),e.apply(e,r)})}}}])}); | ||
//# sourceMappingURL=opossum.min.map |
20
index.js
'use strict'; | ||
const CircuitBreaker = require('./lib/circuit'); | ||
const circuits = []; | ||
@@ -66,3 +67,6 @@ const defaults = { | ||
function factory (action, options) { | ||
return new CircuitBreaker(action, Object.assign({}, defaults, options)); | ||
const circuit = new CircuitBreaker(action, | ||
Object.assign({}, defaults, options)); | ||
circuits.push(circuit); | ||
return circuit; | ||
} | ||
@@ -84,2 +88,16 @@ | ||
factory.promisify = require('./lib/promisify'); | ||
/** | ||
* Get the Prometheus metrics for all circuits. | ||
* @function factory.metrics | ||
* @return {String} the metrics for all circuits | ||
*/ | ||
factory.metrics = function metrics() { | ||
// Just get the metrics for the last circuit that was created | ||
// since prom-client is additive | ||
const lastCircuit = circuits[circuits.length - 1]; | ||
if (lastCircuit && lastCircuit.metrics) | ||
return lastCircuit.metrics.metrics; | ||
} | ||
let warningIssued = false; | ||
@@ -86,0 +104,0 @@ Object.defineProperty(factory, 'stats', { |
@@ -113,3 +113,3 @@ 'use strict'; | ||
this.options.errorFilter = options.errorFilter || (_ => false); | ||
this.semaphore = new Semaphore(this.options.capacity); | ||
@@ -317,3 +317,3 @@ | ||
} | ||
/** | ||
@@ -476,3 +476,3 @@ * Get the hystrixStats. | ||
this.semaphore.release(); | ||
this.emit('timeout', error, latency); | ||
this.emit('timeout', error, latency, args); | ||
resolve(handleError( | ||
@@ -644,3 +644,3 @@ error, this, timeout, args, latency, resolve, reject)); | ||
*/ | ||
circuit.emit('failure', err, latency); | ||
circuit.emit('failure', err, latency, args); | ||
if (circuit.warmUp) return; | ||
@@ -647,0 +647,0 @@ |
{ | ||
"name": "opossum", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"author": "Red Hat, Inc.", | ||
@@ -51,3 +51,3 @@ "license": "Apache-2.0", | ||
"documentation": "^11.0.0", | ||
"nyc": "~14.0.0", | ||
"nyc": "~14.1.1", | ||
"opener": "1.5.1", | ||
@@ -59,3 +59,3 @@ "serve": "^11.0.0", | ||
"tape": "~4.10.1", | ||
"webpack": "~4.32.0", | ||
"webpack": "~4.33.0", | ||
"webpack-cli": "~3.3.0" | ||
@@ -62,0 +62,0 @@ }, |
@@ -240,4 +240,28 @@ # opossum [![CircleCI](https://circleci.com/gh/nodeshift/opossum/tree/master.svg?style=svg&circle-token=0742302baa8c95cef354997ea52a383d3d078ff1)](https://circleci.com/gh/nodeshift/opossum/tree/master) | ||
### Hystrix Metrics | ||
### Metrics | ||
#### Prometheus | ||
Provide `{ usePrometheus: true }` in the options when creating a circuit to produce | ||
metrics that are consumable by Prometheus. These metrics include information about | ||
the circuit itself, for example how many times it has opened, as well as general Node.js | ||
statistics, for example event loop lag. To get consolidated metrics for all circuits in your | ||
application, use the `metrics()` function on the factory. | ||
```js | ||
const opossum = require('opossum'); | ||
// create a circuit | ||
const circuit = opossum(functionThatMightFail, { usePrometheus: true }); | ||
// In an express app, expose the metrics to the Prometheus server | ||
app.use('/metrics', (req, res) => { | ||
res.type('text/plain'); | ||
res.send(opossum.metrics()); | ||
}); | ||
``` | ||
#### Hystrix | ||
**NOTE: Hystrix metrics are deprecated** | ||
A Hystrix Stream is available for use with a Hystrix Dashboard using the `circuitBreaker.hystrixStats.getHystrixStream` method. | ||
@@ -244,0 +268,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1229475
13544
293