Skip to content

Commit

Permalink
feat: container-info for AWS ECS/Fargate; [5s,1d] guard on central co…
Browse files Browse the repository at this point in the history
…nfig re-fetch interval (#3008)

Update elastic-apm-http-client to get these changes.
This also drops using 'container-info' directly in this repo's tests.
Given that the impl in that module and in the http-client might
diverge over time, it isn't necessarily valid to use 'container-info'
here.

Closes: #2914
Closes: #2941
  • Loading branch information
trentm authored Oct 27, 2022
1 parent b9b2d18 commit 350e750
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 39 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,28 @@ Notes:
==== Unreleased
* Enable support for redis v4 ({pull}2945[#2945])
[float]
===== Breaking changes
[float]
===== Features
* Enable support for redis v4 ({pull}2945[#2945])
* Improve container-info gathering to support AWS ECS/Fargate environments.
({issues}2914[#2914])
[float]
===== Bug fixes
[float]
===== Chores
* Add guards to ensure that a crazy `Cache-Control: max-age=...` response
header cannot accidentally result in inappropriate intervals for fetching
central config. The re-fetch delay is clamped to `[5 seconds, 1 day]`.
({issues}2941[#2941])
[[release-notes-3.39.0]]
==== 3.39.0 2022/10/17
Expand Down
27 changes: 7 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"basic-auth": "^2.0.1",
"cookie": "^0.5.0",
"core-util-is": "^1.0.2",
"elastic-apm-http-client": "11.0.1",
"elastic-apm-http-client": "11.0.2",
"end-of-stream": "^1.4.4",
"error-callsites": "^2.0.4",
"error-stack-parser": "^2.0.6",
Expand Down Expand Up @@ -139,7 +139,6 @@
"clone": "^2.0.0",
"columnify": "^1.5.4",
"connect": "^3.7.0",
"container-info": "^1.0.1",
"dashdash": "^2.0.0",
"dependency-check": "^4.1.0",
"diagnostics_channel": "^1.1.0",
Expand Down
28 changes: 13 additions & 15 deletions test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ var http = require('http')
var path = require('path')
var os = require('os')

var { sync: containerInfo } = require('container-info')
var test = require('tape')

const Agent = require('../lib/agent')
Expand All @@ -26,8 +25,6 @@ const { MockAPMServer } = require('./_mock_apm_server')
const { NoopTransport } = require('../lib/noop-transport')
var packageJson = require('../package.json')

var inContainer = 'containerId' in (containerInfo() || {})

// Options to pass to `agent.start()` to turn off some default agent behavior
// that is unhelpful for these tests.
const agentOpts = {
Expand Down Expand Up @@ -57,19 +54,20 @@ function assertMetadata (t, payload) {
t.deepEqual(payload.service.runtime, { name: 'node', version: process.versions.node }, 'metadata: service.runtime')
t.deepEqual(payload.service.agent, { name: 'nodejs', version: packageJson.version }, 'metadata: service.agent')

const expectedSystemKeys = ['hostname', 'architecture', 'platform']
if (inContainer) expectedSystemKeys.push('container')

t.deepEqual(Object.keys(payload.system), expectedSystemKeys, 'metadata: system')
t.strictEqual(payload.system.hostname, os.hostname(), 'metadata: system.hostname')
t.strictEqual(payload.system.architecture, process.arch, 'metadata: system.architecture')
t.strictEqual(payload.system.platform, process.platform, 'metadata: system.platform')

if (inContainer) {
t.deepEqual(Object.keys(payload.system.container), ['id'], 'metadata: system.container')
t.strictEqual(typeof payload.system.container.id, 'string', 'metadata: system.container.id is a string')
t.ok(/^[\da-f]{64}$/.test(payload.system.container.id), 'metadata: system.container.id')
const system = Object.assign({}, payload.system)
t.strictEqual(system.hostname, os.hostname(), 'metadata: system.hostname')
delete system.hostname
t.strictEqual(system.architecture, process.arch, 'metadata: system.architecture')
delete system.architecture
t.strictEqual(system.platform, process.platform, 'metadata: system.platform')
delete system.platform
if (system.container) {
t.deepEqual(Object.keys(system.container), ['id'], 'metadata: system.container')
t.strictEqual(typeof system.container.id, 'string', 'metadata: system.container.id is a string')
t.ok(/^[\da-f]{64}$/.test(system.container.id), 'metadata: system.container.id')
delete system.container
}
t.equal(Object.keys(system).length, 0, 'metadata: system, no unexpected keys: ' + JSON.stringify(system))

t.ok(payload.process, 'metadata: process')
t.strictEqual(payload.process.pid, process.pid, 'metadata: process.pid')
Expand Down

0 comments on commit 350e750

Please sign in to comment.