awslabs / aws-embedded-metrics-node

Amazon CloudWatch Embedded Metric Format Client Library
https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html
Apache License 2.0
253 stars 35 forks source link

Add a CircularBuffer in AgentSink #36

Open jaredcnance opened 4 years ago

jaredcnance commented 4 years ago

Description

Currently, if the agent is down or has not started, metrics can be dropped. It's currently up to the caller of logger.flush to handle retries. There are 2 options:

  1. Backpressure the caller of logger.flush. This could negatively impact request latencies.
  2. On error, enqueue to a circular buffer. The trick here is we will need to retry this queue on an interval which changes the model from an async/await to a purely async one. This is a departure from the current design and will need to be turned on via feature flag.

The symptoms of this are:

  1. The first metrics during initialization of the app may not appear
  2. The following error message will be in your app logs:
(node:1) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 172.17.0.2:25888
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)

Tasks

Example Usage

AWS_EMF_AGENT_RETRY_STRATEGY="ExponentialBackoff"
// or
Configuration.agentRetryStrategy = RetryStrategy.ExponentialBackoff;
// or 
Configuration.agentRetryStrategy = (...) => customRetryStratgy();

// ...
await logger.flush();
// execution control is returned when logs have been successfully flushed or enqueued for retry

Open Question

davidtheclark commented 4 years ago

@jaredcnance is there any likelihood that this feature will be released in the near future?

jaredcnance commented 4 years ago

@davidtheclark the current priority for this repo is #54 and then this issue. The earliest I could probably complete this issue would be ~5-6 weeks from now.

heldersepu commented 1 year ago

Any updates on this?