fluentd-node
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -32,2 +32,20 @@ import EventTime from "./event_time"; | ||
}; | ||
export declare type SendQueueLimit = { | ||
/** | ||
* The queue size limit (memory) | ||
* | ||
* This checks the memory size of the queue, which is only useful with `PackedForward` and `PackedForwardCompressed`. | ||
* | ||
* Defaults to +Infinity | ||
*/ | ||
size: number; | ||
/** | ||
* The queue length limit (# of entries) | ||
* | ||
* This checks the number of events in the queue, which is useful with all event modes. | ||
* | ||
* Defaults to +Infinity | ||
*/ | ||
length: number; | ||
}; | ||
/** | ||
@@ -68,31 +86,25 @@ * The constructor options passed to the client | ||
* | ||
* This checks the memory size of the queue, which is only useful with `PackedForward` and `PackedForwardCompressed`. | ||
* | ||
* Useful with flushInterval to limit the size of the queue | ||
*/ | ||
sendQueueFlushSize?: number; | ||
/** | ||
* The limit at which the queue needs to be flushed. | ||
* | ||
* This checks the number of events in the queue, which is useful with all event modes. | ||
* | ||
* Useful with flushInterval to limit the size of the queue | ||
* See the subtype for defaults | ||
*/ | ||
sendQueueFlushLength?: number; | ||
sendQueueFlushLimit?: Partial<SendQueueLimit>; | ||
/** | ||
* The limit at which we start dropping events | ||
* | ||
* This checks the memory size of the queue, which is only useful with `PackedForward` and `PackedForwardCompressed`. | ||
* Prevents the queue from growing to an unbounded size and exhausting memory. | ||
* | ||
* Prevents the queue from growing to an unbounded size and exhausting memory. | ||
* See the subtype for defaults | ||
*/ | ||
sendQueueMaxSize?: number; | ||
sendQueueMaxLimit?: Partial<SendQueueLimit>; | ||
/** | ||
* The limit at which we start dropping events | ||
* The limit at which we start dropping events when we're not writable | ||
* | ||
* This checks the number of events in the queue, which is useful with all event modes. | ||
* Prevents the queue from growing too much when fluentd is down for an extended period | ||
* | ||
* Prevents the queue from growing to an unbounded size and exhausting memory. | ||
* Defaults to null (no limit) | ||
* | ||
* See the subtype for defaults | ||
*/ | ||
sendQueueMaxLength?: number; | ||
sendQueueNotFlushableLimit?: Partial<SendQueueLimit>; | ||
/** | ||
@@ -127,6 +139,5 @@ * An error handler which will receive socket error events | ||
private flushInterval; | ||
private sendQueueFlushSize; | ||
private sendQueueFlushLength; | ||
private sendQueueMaxSize; | ||
private sendQueueMaxLength; | ||
private sendQueueFlushLimit; | ||
private sendQueueMaxLimit; | ||
private sendQueueNotFlushableLimit; | ||
private nextFlushTimeoutId; | ||
@@ -247,2 +258,8 @@ private flushing; | ||
/** | ||
* Drops events until the send queue is below the specified limits | ||
* | ||
* @param limit The limit to enforce | ||
*/ | ||
private dropLimit; | ||
/** | ||
* Send the front item of the queue to the socket | ||
@@ -249,0 +266,0 @@ * @returns True if there was something to send |
@@ -57,6 +57,19 @@ "use strict"; | ||
this.flushInterval = options.flushInterval || 0; | ||
this.sendQueueFlushSize = options.sendQueueFlushSize || +Infinity; | ||
this.sendQueueFlushLength = options.sendQueueFlushLength || +Infinity; | ||
this.sendQueueMaxSize = options.sendQueueMaxSize || +Infinity; | ||
this.sendQueueMaxLength = options.sendQueueMaxLength || +Infinity; | ||
this.sendQueueFlushLimit = { | ||
size: +Infinity, | ||
length: +Infinity, | ||
...(options.sendQueueFlushLimit || {}), | ||
}; | ||
this.sendQueueMaxLimit = { | ||
size: +Infinity, | ||
length: +Infinity, | ||
...(options.sendQueueMaxLimit || {}), | ||
}; | ||
this.sendQueueNotFlushableLimit = options.sendQueueNotFlushableLimit | ||
? { | ||
size: +Infinity, | ||
length: +Infinity, | ||
...options.sendQueueNotFlushableLimit, | ||
} | ||
: null; | ||
this.socket = this.createSocket(options.security, options.socket); | ||
@@ -154,12 +167,3 @@ this.socket.on("writable", () => this.handleWritable()); | ||
const promise = this.sendQueue.push(tag, time, data); | ||
if (this.sendQueue.queueSize > this.sendQueueMaxSize) { | ||
while (this.sendQueue.queueSize > this.sendQueueMaxSize) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
if (this.sendQueue.queueLength > this.sendQueueMaxLength) { | ||
while (this.sendQueue.queueLength > this.sendQueueMaxLength) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
this.dropLimit(this.sendQueueMaxLimit); | ||
this.maybeFlush(); | ||
@@ -288,2 +292,5 @@ return promise; | ||
if (!this.socket.writable()) { | ||
if (this.sendQueueNotFlushableLimit) { | ||
this.dropLimit(this.sendQueueNotFlushableLimit); | ||
} | ||
return; | ||
@@ -293,4 +300,5 @@ } | ||
if (this.flushInterval > 0) { | ||
const limit = this.sendQueueFlushLimit; | ||
if (this.sendQueue.queueSize !== -1 && | ||
this.sendQueue.queueSize >= this.sendQueueFlushSize) { | ||
this.sendQueue.queueSize >= limit.size) { | ||
// If the queue has hit the memory flush limit | ||
@@ -300,3 +308,3 @@ this.flush(); | ||
else if (this.sendQueue.queueLength !== -1 && | ||
this.sendQueue.queueLength >= this.sendQueueFlushLength) { | ||
this.sendQueue.queueLength >= limit.length) { | ||
// If the queue has hit the length flush limit | ||
@@ -318,2 +326,19 @@ this.flush(); | ||
/** | ||
* Drops events until the send queue is below the specified limits | ||
* | ||
* @param limit The limit to enforce | ||
*/ | ||
dropLimit(limit) { | ||
if (this.sendQueue.queueSize > limit.size) { | ||
while (this.sendQueue.queueSize > limit.size) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
if (this.sendQueue.queueLength > limit.length) { | ||
while (this.sendQueue.queueLength > limit.length) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
} | ||
/** | ||
* Send the front item of the queue to the socket | ||
@@ -320,0 +345,0 @@ * @returns True if there was something to send |
@@ -7,4 +7,4 @@ export { FluentClient } from "./client"; | ||
export type { EventRetryOptions } from "./event_retrier"; | ||
export type { FluentClientOptions, Timestamp, AckOptions, EventModes, } from "./client"; | ||
export type { FluentClientOptions, Timestamp, AckOptions, EventModes, SendQueueLimit, } from "./client"; | ||
export type { FluentServerOptions, FluentServerSecurityOptions } from "./server"; | ||
export * as FluentError from "./error"; |
{ | ||
"name": "fluentd-node", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A fluent protocol implementation in node", | ||
@@ -28,3 +28,3 @@ "main": "./build/src/index.js", | ||
"bugs": "https://github.com/jamiees2/fluentd-node/issues", | ||
"homepage": "https://github.com/jamiees2/fluentd-node", | ||
"homepage": "https://jamiees2.github.io/fluentd-node/", | ||
"engines": { | ||
@@ -31,0 +31,0 @@ "node": ">=12" |
# fluentd-node | ||
[![Build Status](https://github.com/jamiees2/fluentd-node/actions/workflows/main.yml/badge.svg)](https://github.com/jamiees2/fluentd-node/actions) | ||
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) | ||
[![Docs](https://img.shields.io/badge/Docs-latest-green)](https://jamiees2.github.io/fluentd-node/) | ||
[![Docs](https://img.shields.io/badge/Docs-latest-informational)](https://jamiees2.github.io/fluentd-node/) | ||
@@ -11,3 +11,2 @@ [Fluent Forward Protocol](https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1) implementation for Node.js. | ||
## Install | ||
@@ -17,8 +16,11 @@ | ||
## Prerequisites | ||
## Client | ||
`fluentd-node` provides a fully functional client that implements the Forward protocol. It supports reconnection, acknowledgements, timeouts, event retries, and more, and exposes its functionality through simple typed Promise interface. | ||
The fluent daemon should be listening on a TCP port. | ||
For a full list of the client options and methods, see the [FluentClient docs](https://jamiees2.github.io/fluentd-node/classes/fluentclient.html) | ||
Simple configuration is following: | ||
### Prerequisites | ||
The fluent daemon should be listening in forward mode. | ||
A simple starting configuration is the following: | ||
```aconf | ||
@@ -35,5 +37,5 @@ <source> | ||
## Usage | ||
See the [FluentD docs](https://docs.fluentd.org/input/forward) for more info. | ||
### Send an event record to Fluentd | ||
### Sending an event record to Fluentd | ||
@@ -177,3 +179,3 @@ ```js | ||
FYI: You can generate certificates using fluent-ca-generate command since Fluentd 1.1.0. | ||
FYI: You can generate certificates using the `fluent-ca-generate` command since Fluentd 1.1.0. | ||
@@ -232,3 +234,3 @@ See also [How to enable TLS/SSL encryption](https://docs.fluentd.org/input/forward#how-to-enable-tls-encryption). | ||
We can also specify [EventTime](https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1#eventtime-ext-format) as timestamp. | ||
We can also specify [EventTime](https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1#eventtime-ext-format) as timestamp. See the [EventTime docs](https://jamiees2.github.io/fluentd-node/classes/eventtime.html) | ||
@@ -256,3 +258,3 @@ ```js | ||
onSocketError: (err: Error) => { | ||
console.log("error!", err) | ||
console.error("error!", err) | ||
} | ||
@@ -271,6 +273,3 @@ }); | ||
### Client Options | ||
For a full list of the client options and methods, see the [FluentClient docs](https://jamiees2.github.io/fluentd-node/classes/fluentclient.html) | ||
### Server | ||
## Server | ||
`fluentd-node` includes a fully functional forward server which can be used as a downstream Fluent sink. | ||
@@ -308,2 +307,4 @@ | ||
See the [FluentD docs](https://docs.fluentd.org/output/forward) for more info. | ||
For a full list of the server options and methods, see the [FluentServer docs](https://jamiees2.github.io/fluentd-node/classes/fluentserver.html) | ||
@@ -310,0 +311,0 @@ |
@@ -61,2 +61,21 @@ import { | ||
export type SendQueueLimit = { | ||
/** | ||
* The queue size limit (memory) | ||
* | ||
* This checks the memory size of the queue, which is only useful with `PackedForward` and `PackedForwardCompressed`. | ||
* | ||
* Defaults to +Infinity | ||
*/ | ||
size: number; | ||
/** | ||
* The queue length limit (# of entries) | ||
* | ||
* This checks the number of events in the queue, which is useful with all event modes. | ||
* | ||
* Defaults to +Infinity | ||
*/ | ||
length: number; | ||
}; | ||
/** | ||
@@ -97,31 +116,26 @@ * The constructor options passed to the client | ||
* | ||
* This checks the memory size of the queue, which is only useful with `PackedForward` and `PackedForwardCompressed`. | ||
* | ||
* Useful with flushInterval to limit the size of the queue | ||
*/ | ||
sendQueueFlushSize?: number; | ||
/** | ||
* The limit at which the queue needs to be flushed. | ||
* | ||
* This checks the number of events in the queue, which is useful with all event modes. | ||
* | ||
* Useful with flushInterval to limit the size of the queue | ||
* See the subtype for defaults | ||
*/ | ||
sendQueueFlushLength?: number; | ||
sendQueueFlushLimit?: Partial<SendQueueLimit>; | ||
/** | ||
* The limit at which we start dropping events | ||
* | ||
* This checks the memory size of the queue, which is only useful with `PackedForward` and `PackedForwardCompressed`. | ||
* Prevents the queue from growing to an unbounded size and exhausting memory. | ||
* | ||
* Prevents the queue from growing to an unbounded size and exhausting memory. | ||
* See the subtype for defaults | ||
*/ | ||
sendQueueMaxSize?: number; | ||
sendQueueMaxLimit?: Partial<SendQueueLimit>; | ||
/** | ||
* The limit at which we start dropping events | ||
* The limit at which we start dropping events when we're not writable | ||
* | ||
* This checks the number of events in the queue, which is useful with all event modes. | ||
* Prevents the queue from growing too much when fluentd is down for an extended period | ||
* | ||
* Prevents the queue from growing to an unbounded size and exhausting memory. | ||
* Defaults to null (no limit) | ||
* | ||
* See the subtype for defaults | ||
*/ | ||
sendQueueMaxLength?: number; | ||
sendQueueNotFlushableLimit?: Partial<SendQueueLimit>; | ||
/** | ||
@@ -159,8 +173,6 @@ * An error handler which will receive socket error events | ||
private flushInterval: number; | ||
private sendQueueFlushSize: number; | ||
private sendQueueFlushLength: number; | ||
private sendQueueFlushLimit: SendQueueLimit; | ||
private sendQueueMaxLimit: SendQueueLimit; | ||
private sendQueueNotFlushableLimit: SendQueueLimit | null; | ||
private sendQueueMaxSize: number; | ||
private sendQueueMaxLength: number; | ||
private nextFlushTimeoutId: null | NodeJS.Timeout = null; | ||
@@ -207,6 +219,19 @@ private flushing = false; | ||
this.flushInterval = options.flushInterval || 0; | ||
this.sendQueueFlushSize = options.sendQueueFlushSize || +Infinity; | ||
this.sendQueueFlushLength = options.sendQueueFlushLength || +Infinity; | ||
this.sendQueueMaxSize = options.sendQueueMaxSize || +Infinity; | ||
this.sendQueueMaxLength = options.sendQueueMaxLength || +Infinity; | ||
this.sendQueueFlushLimit = { | ||
size: +Infinity, | ||
length: +Infinity, | ||
...(options.sendQueueFlushLimit || {}), | ||
}; | ||
this.sendQueueMaxLimit = { | ||
size: +Infinity, | ||
length: +Infinity, | ||
...(options.sendQueueMaxLimit || {}), | ||
}; | ||
this.sendQueueNotFlushableLimit = options.sendQueueNotFlushableLimit | ||
? { | ||
size: +Infinity, | ||
length: +Infinity, | ||
...options.sendQueueNotFlushableLimit, | ||
} | ||
: null; | ||
@@ -368,12 +393,3 @@ this.socket = this.createSocket(options.security, options.socket); | ||
const promise = this.sendQueue.push(tag, time, data); | ||
if (this.sendQueue.queueSize > this.sendQueueMaxSize) { | ||
while (this.sendQueue.queueSize > this.sendQueueMaxSize) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
if (this.sendQueue.queueLength > this.sendQueueMaxLength) { | ||
while (this.sendQueue.queueLength > this.sendQueueMaxLength) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
this.dropLimit(this.sendQueueMaxLimit); | ||
this.maybeFlush(); | ||
@@ -510,2 +526,5 @@ return promise; | ||
if (!this.socket.writable()) { | ||
if (this.sendQueueNotFlushableLimit) { | ||
this.dropLimit(this.sendQueueNotFlushableLimit); | ||
} | ||
return; | ||
@@ -515,5 +534,6 @@ } | ||
if (this.flushInterval > 0) { | ||
const limit = this.sendQueueFlushLimit; | ||
if ( | ||
this.sendQueue.queueSize !== -1 && | ||
this.sendQueue.queueSize >= this.sendQueueFlushSize | ||
this.sendQueue.queueSize >= limit.size | ||
) { | ||
@@ -524,3 +544,3 @@ // If the queue has hit the memory flush limit | ||
this.sendQueue.queueLength !== -1 && | ||
this.sendQueue.queueLength >= this.sendQueueFlushLength | ||
this.sendQueue.queueLength >= limit.length | ||
) { | ||
@@ -542,2 +562,20 @@ // If the queue has hit the length flush limit | ||
/** | ||
* Drops events until the send queue is below the specified limits | ||
* | ||
* @param limit The limit to enforce | ||
*/ | ||
private dropLimit(limit: SendQueueLimit): void { | ||
if (this.sendQueue.queueSize > limit.size) { | ||
while (this.sendQueue.queueSize > limit.size) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
if (this.sendQueue.queueLength > limit.length) { | ||
while (this.sendQueue.queueLength > limit.length) { | ||
this.sendQueue.dropEntry(); | ||
} | ||
} | ||
} | ||
/** | ||
* Send the front item of the queue to the socket | ||
@@ -544,0 +582,0 @@ * @returns True if there was something to send |
@@ -13,2 +13,3 @@ export {FluentClient} from "./client"; | ||
EventModes, | ||
SendQueueLimit, | ||
} from "./client"; | ||
@@ -15,0 +16,0 @@ |
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
No website
QualityPackage does not have a website.
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
284455
6737
316
2