dynatrace-api-balancer
Version:
A wrapper around Axios that balances and throttles requests across tenants, clusters and cluster nodes.
834 lines (216 loc) • 11.9 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: BalancedAPIRequest</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: BalancedAPIRequest</h1>
<section>
<header>
<h2><span class="attribs"><span class="type-signature"></span></span>BalancedAPIRequest<span class="signature">(limits, tenants)</span><span class="type-signature"></span></h2>
<div class="class-description"><p>The BalancedAPIRequest class enriches the functionality of <a href="DirectAPIRequest.html"><code>DirectAPIRequest</code></a>
with an efficient load balancing, queuing and request throttling layer that protects
the Dynatrace cluster from request overload while ensuring that for each request the
best (most available) cluster node is selected to handle that request. Additionally,
it provides a simple way to cancel any request if the caller is no longer interested
in the response.</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="BalancedAPIRequest"><span class="type-signature"></span>new BalancedAPIRequest<span class="signature">(limits, tenants)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Creates a pool of connections to reach multiple tenants and clusters.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>limits</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Default values for <code>retryLimit</code>, <code>retryAfter</code> and <code>timeout</code>.</p></td>
</tr>
<tr>
<td class="name"><code>tenants</code></td>
<td class="type">
<span class="param-type">Array.<<a href="global.html#TenantConfig">TenantConfig</a>></span>
</td>
<td class="description last"><p>The configurations for the tenants.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_BalancedAPIRequest.js.html">lib/BalancedAPIRequest.js</a>, <a href="lib_BalancedAPIRequest.js.html#line16">line 16</a>
</li></ul></dd>
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="fetch"><span class="type-signature">(async) </span>fetch<span class="signature">(options, onDone<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="CancellableEventEmitter.html">CancellableEventEmitter</a>|<a href="CancellablePromise.html">CancellablePromise</a>}</span></h4>
<div class="description">
<p>Note that in this class the <a href="global.html#RequestOptions"><code>RequestOptions</code></a> object also supports the <code>noQueue</code> property.</p>
<p>Required properties in the <a href="global.html#RequestOptions"><code>RequestOptions</code></a> object (unless an alias is used - see below):</p>
<ul>
<li><code>url</code>: URL relative to the <code>tenant</code>. Ex.: <code>'/api/v2/entities'</code>.</li>
<li><code>tenant</code>: Name of the Dynatrace tenant. Ex.: <code>'PROD'</code>.</li>
</ul>
<p>For convenience aliases have been provided for the following request methods:</p>
<ul>
<li><code>get(url, options[, onDone])</code></li>
<li><code>delete(url, options[, onDone])</code></li>
<li><code>post(url, data, options[, onDone])</code></li>
<li><code>put(url, data, options[, onDone])</code></li>
</ul>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type"><a href="global.html#RequestOptions">RequestOptions</a></span>
</td>
<td class="attributes">
</td>
<td class="description last"><p>The request options, Axios-style.</p></td>
</tr>
<tr>
<td class="name"><code>onDone</code></td>
<td class="type">
<span class="param-type"><a href="global.html#RequestCallback">RequestCallback</a></span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>Callback that handles the result (alternative to using a Promise).</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_BalancedAPIRequest.js.html">lib/BalancedAPIRequest.js</a>, <a href="lib_BalancedAPIRequest.js.html#line49">line 49</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>If <code>onDone</code> is provided, this method returns a <a href="CancellableEventEmitter.html"><code>CancellableEventEmitter</code></a>.
Else, this method returns a <a href="CancellablePromise.html"><code>CancellablePromise</code></a>.</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="CancellableEventEmitter.html">CancellableEventEmitter</a></span>
|
<span class="param-type"><a href="CancellablePromise.html">CancellablePromise</a></span>
</dd>
</dl>
<h4 class="name" id="getHealthMetrics"><span class="type-signature"></span>getHealthMetrics<span class="signature">(frequency<span class="signature-attributes">opt</span>, callback<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
<div class="description">
<p>Report the health of the connection pool. If no parameters are specified, the health
report will be returned. If both parameters are specified, the callback will be called
with the health report as its only parameter, per the specified frequency.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>frequency</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>The requency with which the health of the
connection pool should be reported.</p></td>
</tr>
<tr>
<td class="name"><code>callback</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="description last"><p>The function that consumes the health report.</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_BalancedAPIRequest.js.html">lib/BalancedAPIRequest.js</a>, <a href="lib_BalancedAPIRequest.js.html#line72">line 72</a>
</li></ul></dd>
</dl>
<h4 class="name" id="restart"><span class="type-signature"></span>restart<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Cancel all running and/or queued requests and reset the connection pool.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_BalancedAPIRequest.js.html">lib/BalancedAPIRequest.js</a>, <a href="lib_BalancedAPIRequest.js.html#line55">line 55</a>
</li></ul></dd>
</dl>
<h4 class="name" id="shutdown"><span class="type-signature"></span>shutdown<span class="signature">()</span><span class="type-signature"></span></h4>
<div class="description">
<p>Cancel all running and/or queued requests and delete the connection pool.</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="lib_BalancedAPIRequest.js.html">lib/BalancedAPIRequest.js</a>, <a href="lib_BalancedAPIRequest.js.html#line61">line 61</a>
</li></ul></dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BalancedAPIRequest.html">BalancedAPIRequest</a></li><li><a href="CancellableEventEmitter.html">CancellableEventEmitter</a></li><li><a href="CancellablePromise.html">CancellablePromise</a></li><li><a href="DirectAPIRequest.html">DirectAPIRequest</a></li><li><a href="Throttle.html">Throttle</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Sun Dec 19 2021 10:28:40 GMT-0600 (Central Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>