-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add a meter provider, enable host-metrics; starter metrics impr…
…ovements for mockotlpserver (#25) - This adds some starter improvements to mockotlpserver for handling incoming metrics OTLP requests. The `inspect` printer would already do fine. The `json` printer is slightly improved with some normalization -- though there are still unconverted Long instances that aren't super nice. There is a *start* at `metrics-summary` printer, but it is far from sufficient yet. - The SDK now adds a meter provider (via a periodic exporter via OTLP/proto). By default every 30s. - There is a *lot* of data here from HostMetrics, so we may want to consider limiting that. Note that this is using `@opentelemetry/[email protected]` which doesn't yet have your latest changes, David. IIRC your change will `fix process.cpu.* metrics`, but not reduce the large amount of data (each CPU and each state) coming through. - Another note is that the `http.client.duration` metric has changing values when I send zero requests to the "http-server.js" example script (see below), so I'm not sure if we'll need to sanity check that data. - I've started a couple hack/internal `ETEL_*` :) envvars for configuring things. - See #25 (comment) for details on why we are using `tsc --skipLibCheck` now.
- Loading branch information
Showing
10 changed files
with
3,430 additions
and
6,595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Usage: | ||
// node -r @elastic/opentelemetry-node/start.js http-server.js | ||
// curl -i http://127.0.0.1:3000/ping | ||
|
||
const http = require('http'); | ||
|
||
const server = http.createServer(function onRequest(req, res) { | ||
console.log('incoming request: %s %s %s', req.method, req.url, req.headers); | ||
req.resume(); | ||
req.on('end', function () { | ||
const body = 'pong'; | ||
res.writeHead(200, { | ||
'content-type': 'text/plain', | ||
'content-length': Buffer.byteLength(body), | ||
}); | ||
res.end(body); | ||
}); | ||
}); | ||
|
||
server.listen(3000, '127.0.0.1', function () { | ||
console.log('listening at', server.address()); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* A "Printer" of metrics data that attempts a reasonable short summary. | ||
* | ||
* Dev Notes / Ideas: | ||
*/ | ||
|
||
const {Printer} = require('./printers'); | ||
const {normalizeMetrics} = require('./normalize'); | ||
|
||
class MetricsSummaryPrinter extends Printer { | ||
printMetrics(rawMetrics) { | ||
const metrics = normalizeMetrics(rawMetrics); | ||
|
||
const rendering = []; | ||
// TODO add size of request in bytes, perhaps useful for debugging | ||
// TODO add a summary of service.names (from resource) and scopes to the title line | ||
rendering.push(`------ metrics ------`); | ||
const scopes = []; | ||
for (let resourceMetric of metrics.resourceMetrics) { | ||
for (let scopeMetric of resourceMetric.scopeMetrics || []) { | ||
const scope = `${scopeMetric.scope.name}@${scopeMetric.scope.version}`; | ||
scopes.push(scope); | ||
for (let metric of scopeMetric.metrics) { | ||
if (metric.histogram) { | ||
// TODO do we want to attempt a short summary of histogram buckets? | ||
// TODO handle multiple datapoints, dp per normalized attribute set. Highest prio. Run `node -r @elastic/opentelemetry-node/start.js http-server.js` for example data. | ||
if (metric.histogram.dataPoints.length !== 1) { | ||
this._log.warn( | ||
{metric}, | ||
'metric has other than 1 dataPoint' | ||
); | ||
rendering.push(` ${metric.name} (histogram)`); | ||
} else { | ||
const dp = metric.histogram.dataPoints[0]; | ||
rendering.push( | ||
` ${metric.name} (histogram, ${ | ||
metric.unit | ||
}, ${ | ||
Object.keys(dp.attributes).length | ||
} attrs): min=${dp.min}, max=${dp.max}` | ||
); | ||
} | ||
} else { | ||
// TODO handle other metric types better | ||
rendering.push(` ${metric.name} (type=???)`); | ||
} | ||
} | ||
} | ||
} | ||
|
||
console.log(rendering.join('\n')); | ||
} | ||
} | ||
|
||
module.exports = { | ||
MetricsSummaryPrinter, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.