New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

aws-embedded-metrics

Package Overview
Dependencies
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-embedded-metrics - npm Package Compare versions

Comparing version 2.0.5 to 2.0.6

1

lib/Constants.d.ts

@@ -5,4 +5,5 @@ export declare enum Constants {

MAX_METRICS_PER_EVENT = 100,
MAX_VALUES_PER_METRIC = 100,
DEFAULT_AGENT_HOST = "0.0.0.0",
DEFAULT_AGENT_PORT = 25888
}

@@ -22,4 +22,5 @@ "use strict";

Constants[Constants["MAX_METRICS_PER_EVENT"] = 100] = "MAX_METRICS_PER_EVENT";
Constants[Constants["MAX_VALUES_PER_METRIC"] = 100] = "MAX_VALUES_PER_METRIC";
Constants["DEFAULT_AGENT_HOST"] = "0.0.0.0";
Constants[Constants["DEFAULT_AGENT_PORT"] = 25888] = "DEFAULT_AGENT_PORT";
})(Constants = exports.Constants || (exports.Constants = {}));

39

lib/serializers/LogSerializer.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/*

@@ -16,3 +17,3 @@ * Copyright 2019 Amazon.com, Inc. or its affiliates.

*/
Object.defineProperty(exports, "__esModule", { value: true });
const heap_1 = require("@datastructures-js/heap");
const Constants_1 = require("../Constants");

@@ -54,3 +55,3 @@ /**

const currentMetricsInBody = () => currentBody._aws.CloudWatchMetrics[0].Metrics.length;
const shouldSerialize = () => currentMetricsInBody() === Constants_1.Constants.MAX_METRICS_PER_EVENT;
const hasMaxMetrics = () => currentMetricsInBody() === Constants_1.Constants.MAX_METRICS_PER_EVENT;
// converts the body to JSON and pushes it into the batches

@@ -61,9 +62,29 @@ const serializeCurrentBody = () => {

};
for (const [key, metric] of context.metrics) {
// if there is only one metric value, unwrap it to make querying easier
const metricValue = metric.values.length === 1 ? metric.values[0] : metric.values;
currentBody[key] = metricValue;
currentBody._aws.CloudWatchMetrics[0].Metrics.push({ Name: key, Unit: metric.unit });
if (shouldSerialize()) {
serializeCurrentBody();
const remainingMetrics = heap_1.MaxHeap.heapify(Array.from(context.metrics, ([key, value]) => {
return { name: key, numLeft: value.values.length };
}), metric => metric.numLeft);
let processedMetrics = [];
// Batches the metrics with the most number of values first, such that each metric has no more
// than 100 values, and each batch has no more than 100 metric definitions.
while (!remainingMetrics.isEmpty()) {
const metricProgress = remainingMetrics.extractRoot();
const metric = context.metrics.get(metricProgress.name);
if (metric) {
const startIndex = metric.values.length - metricProgress.numLeft;
// if there is only one metric value, unwrap it to make querying easier
const metricValue = metricProgress.numLeft === 1
? metric.values[startIndex]
: metric.values.slice(startIndex, startIndex + Constants_1.Constants.MAX_VALUES_PER_METRIC);
currentBody[metricProgress.name] = metricValue;
currentBody._aws.CloudWatchMetrics[0].Metrics.push({ Name: metricProgress.name, Unit: metric.unit });
metricProgress.numLeft -= Constants_1.Constants.MAX_VALUES_PER_METRIC;
if (metricProgress.numLeft > 0) {
processedMetrics.push(metricProgress);
}
if (hasMaxMetrics() || remainingMetrics.isEmpty()) {
serializeCurrentBody();
// inserts these metrics back in the heap to be processed in the next iteration.
processedMetrics.forEach(processingMetric => remainingMetrics.insert(processingMetric));
processedMetrics = [];
}
}

@@ -70,0 +91,0 @@ }

@@ -8,2 +8,3 @@ /// <reference types="node" />

constructor(endpoint: IEndpoint);
initialConnect(): Promise<void>;
warmup(): Promise<void>;

@@ -10,0 +11,0 @@ sendMessage(message: Buffer): Promise<void>;

@@ -31,3 +31,3 @@ "use strict";

this.endpoint = endpoint;
this.socket = new net.Socket({ allowHalfOpen: true, writable: false })
this.socket = new net.Socket({ allowHalfOpen: true })
.setEncoding('utf8')

@@ -39,3 +39,17 @@ .setKeepAlive(true)

.on('data', data => Logger_1.LOG('TcpClient received data.', data));
// Used to create an initial connection on the socket right after creation to avoid socket failures.
this.initialConnect.apply(this);
}
initialConnect() {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
this.socket.connect(this.endpoint.port, this.endpoint.host, (err) => {
if (err)
reject(err);
else
resolve();
});
});
});
}
warmup() {

@@ -83,3 +97,3 @@ return __awaiter(this, void 0, void 0, function* () {

return __awaiter(this, void 0, void 0, function* () {
if (!this.socket.writeable || this.socket.readyState !== 'open') {
if (!this.socket.writable || this.socket.readyState !== 'open') {
yield this.establishConnection();

@@ -86,0 +100,0 @@ }

{
"name": "aws-embedded-metrics",
"version": "2.0.5",
"version": "2.0.6",
"description": "AWS Embedded Metrics Client Library",

@@ -31,5 +31,9 @@ "main": "lib/index.js",

"contributors": [
"Jared Nance <jarnance@amazon.com>"
"Jared Nance <jarnance@amazon.com>",
"Mark Kuhn <kuhnmar@amazon.com>"
],
"license": "Apache-2.0",
"dependencies": {
"@datastructures-js/heap": "^4.0.2"
},
"devDependencies": {

@@ -58,4 +62,4 @@ "@types/faker": "^4.1.5",

"volta": {
"node": "10.16.0"
"node": "16.16.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc