Skip to content

Commit 555e4d2

Browse files
authored
Merge pull request #1003 from appsignal/bump-agent-and-implement-cpu-count
Bump agent and implement CPU count
2 parents 1915610 + 051a79a commit 555e4d2

File tree

6 files changed

+83
-22
lines changed

6 files changed

+83
-22
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
bump: "patch"
3+
type: "add"
4+
---
5+
6+
Implement CPU count configuration option. Use it to override the auto-detected, cgroups-provided number of CPUs that is used to calculate CPU usage percentages.
7+
8+
To set it, use the `cpuCount` configuration option, or the `APPSIGNAL_CPU_COUNT` environment variable.
9+

scripts/extension/support/constants.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// appsignal-agent repository.
44
// Modifications to this file will be overwritten with the next agent release.
55

6-
const AGENT_VERSION = "0.34.0"
6+
const AGENT_VERSION = "0.34.1"
77
const MIRRORS = [
88
"https://appsignal-agent-releases.global.ssl.fastly.net",
99
"https://d135dj0rjqvssy.cloudfront.net"
@@ -12,67 +12,67 @@ const MIRRORS = [
1212
const TRIPLES = {
1313
"x86_64-darwin": {
1414
checksum:
15-
"a6c7f10f8efc09f007306189e8af7a2f5335ffec181f76677fa8548f12b8b774",
15+
"351f3dae916d3e84177d8cc35eaeaca5345f4deca9e0925a29353915cc0530d2",
1616
filename: "appsignal-x86_64-darwin-all-static.tar.gz"
1717
},
1818
"universal-darwin": {
1919
checksum:
20-
"a6c7f10f8efc09f007306189e8af7a2f5335ffec181f76677fa8548f12b8b774",
20+
"351f3dae916d3e84177d8cc35eaeaca5345f4deca9e0925a29353915cc0530d2",
2121
filename: "appsignal-x86_64-darwin-all-static.tar.gz"
2222
},
2323
"aarch64-darwin": {
2424
checksum:
25-
"3c019c103d86b6d3a60d4da5fe5f9449d9980c6087d0f1494e24f91cd045d1d6",
25+
"fd7359232fbd65f10ee565fcf65f4afa6d7a2ba1a8dead200c34736ca942df16",
2626
filename: "appsignal-aarch64-darwin-all-static.tar.gz"
2727
},
2828
"arm64-darwin": {
2929
checksum:
30-
"3c019c103d86b6d3a60d4da5fe5f9449d9980c6087d0f1494e24f91cd045d1d6",
30+
"fd7359232fbd65f10ee565fcf65f4afa6d7a2ba1a8dead200c34736ca942df16",
3131
filename: "appsignal-aarch64-darwin-all-static.tar.gz"
3232
},
3333
"arm-darwin": {
3434
checksum:
35-
"3c019c103d86b6d3a60d4da5fe5f9449d9980c6087d0f1494e24f91cd045d1d6",
35+
"fd7359232fbd65f10ee565fcf65f4afa6d7a2ba1a8dead200c34736ca942df16",
3636
filename: "appsignal-aarch64-darwin-all-static.tar.gz"
3737
},
3838
"aarch64-linux": {
3939
checksum:
40-
"6025983af8d38ba9265795f5b384bc78421f0641a93b749d8aa941881c818199",
40+
"dfbab18b7faa24684bf0ab57666b6b493356a3da43ecdba2e992b2d6d513cf31",
4141
filename: "appsignal-aarch64-linux-all-static.tar.gz"
4242
},
4343
"i686-linux": {
4444
checksum:
45-
"99556d16c59053cb79d1fa7b88a60cb6b2881daac9e9e5789546c9799bdef658",
45+
"ce4a819f3eaa4590795497915e4a20b3fe281a0821364b80d26ffd1391af67a8",
4646
filename: "appsignal-i686-linux-all-static.tar.gz"
4747
},
4848
"x86-linux": {
4949
checksum:
50-
"99556d16c59053cb79d1fa7b88a60cb6b2881daac9e9e5789546c9799bdef658",
50+
"ce4a819f3eaa4590795497915e4a20b3fe281a0821364b80d26ffd1391af67a8",
5151
filename: "appsignal-i686-linux-all-static.tar.gz"
5252
},
5353
"x86_64-linux": {
5454
checksum:
55-
"48ace6181571418a8e8236f8180345f8c97ac152953741b0c394019d0bbefb63",
55+
"e55f9ecb4e4b51e9232918216487712b63a7cfea9710763f61077e8d40d53dbe",
5656
filename: "appsignal-x86_64-linux-all-static.tar.gz"
5757
},
5858
"x86_64-linux-musl": {
5959
checksum:
60-
"cb0b388ea1275f8b28547bf79bd127ceaba9b32027426f66eb45de8418a9592d",
60+
"8963ebc98405648205a6d8aa371bafa49cb33cd104e0c3e6cc1856ba41fe3d8c",
6161
filename: "appsignal-x86_64-linux-musl-all-static.tar.gz"
6262
},
6363
"aarch64-linux-musl": {
6464
checksum:
65-
"571fc4749c22701a6e9e4c68d1fa9fcad0c443e62c6125c1ef57fb9735d93659",
65+
"34bb72678b896a2a8289a97611a61a297b5a0e6110f5085a683ad93857cdf26c",
6666
filename: "appsignal-aarch64-linux-musl-all-static.tar.gz"
6767
},
6868
"x86_64-freebsd": {
6969
checksum:
70-
"5f47f08d1373a6d3e7ee579389a60780508b9a5ae6c69883c8a13a0ae6e09da7",
70+
"68e882ba3bc87328953d9bfbb676b00d4199756a7090d5cdc265a4b32d857cc5",
7171
filename: "appsignal-x86_64-freebsd-all-static.tar.gz"
7272
},
7373
"amd64-freebsd": {
7474
checksum:
75-
"5f47f08d1373a6d3e7ee579389a60780508b9a5ae6c69883c8a13a0ae6e09da7",
75+
"68e882ba3bc87328953d9bfbb676b00d4199756a7090d5cdc265a4b32d857cc5",
7676
filename: "appsignal-x86_64-freebsd-all-static.tar.gz"
7777
}
7878
}

src/__tests__/config.test.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import fs from "fs"
33

44
import { VERSION } from "../version"
55
import { Configuration } from "../config"
6+
import {
7+
ENV_TO_KEY_MAPPING,
8+
BOOL_KEYS,
9+
FLOAT_KEYS,
10+
LIST_KEYS,
11+
LIST_OR_BOOL_KEYS,
12+
STRING_KEYS
13+
} from "../config/configmap"
614

715
describe("Configuration", () => {
816
const name = "TEST APP"
@@ -73,6 +81,22 @@ describe("Configuration", () => {
7381
resetEnv()
7482
})
7583

84+
it("knows how to transform all environment variables into options", () => {
85+
const allKeys = Object.keys(ENV_TO_KEY_MAPPING).sort()
86+
87+
const allKeyTransformations = [
88+
BOOL_KEYS,
89+
STRING_KEYS,
90+
LIST_KEYS,
91+
LIST_OR_BOOL_KEYS,
92+
FLOAT_KEYS
93+
]
94+
.flat()
95+
.sort()
96+
97+
expect(allKeys).toEqual(allKeyTransformations)
98+
})
99+
76100
describe("with only default options", () => {
77101
it("loads all default options", () => {
78102
config = new Configuration({})
@@ -129,11 +153,15 @@ describe("Configuration", () => {
129153
process.env["APPSIGNAL_ENABLE_STATSD"] = "true"
130154
process.env["APPSIGNAL_ENABLE_HOST_METRICS"] = "false"
131155
process.env["APPSIGNAL_DNS_SERVERS"] = "8.8.8.8,8.8.4.4"
156+
process.env["APPSIGNAL_CPU_COUNT"] = "1.5"
157+
132158
const envOptions = {
133159
enableStatsd: true,
134160
enableHostMetrics: false,
135-
dnsServers: ["8.8.8.8", "8.8.4.4"]
161+
dnsServers: ["8.8.8.8", "8.8.4.4"],
162+
cpuCount: 1.5
136163
}
164+
137165
const expectedConfig = {
138166
...expectedDefaultConfig,
139167
...envOptions
@@ -319,6 +347,7 @@ describe("Configuration", () => {
319347
expect(env("_APPSIGNAL_APP_NAME")).toBeUndefined()
320348
expect(env("_APPSIGNAL_BIND_ADDRESS")).toBeUndefined()
321349
expect(env("_APPSIGNAL_CA_FILE_PATH")).toMatch(/cert\/cacert\.pem$/)
350+
expect(env("_APPSIGNAL_CPU_COUNT")).toBeUndefined()
322351
expect(env("_APPSIGNAL_DNS_SERVERS")).toBeUndefined()
323352
expect(env("_APPSIGNAL_ENABLE_HOST_METRICS")).toEqual("true")
324353
expect(env("_APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP")).toEqual("true")
@@ -367,6 +396,7 @@ describe("Configuration", () => {
367396
name,
368397
active: true,
369398
bindAddress: "0.0.0.0",
399+
cpuCount: 1.5,
370400
pushApiKey,
371401
dnsServers: ["8.8.8.8", "8.8.4.4"],
372402
enableHostMetrics: false,
@@ -397,6 +427,7 @@ describe("Configuration", () => {
397427
expect(env("_APPSIGNAL_ACTIVE")).toEqual("true")
398428
expect(env("_APPSIGNAL_APP_NAME")).toEqual(name)
399429
expect(env("_APPSIGNAL_BIND_ADDRESS")).toEqual("0.0.0.0")
430+
expect(env("_APPSIGNAL_CPU_COUNT")).toEqual("1.5")
400431
expect(env("_APPSIGNAL_DNS_SERVERS")).toEqual("8.8.8.8,8.8.4.4")
401432
expect(env("_APPSIGNAL_ENABLE_HOST_METRICS")).toEqual("false")
402433
expect(env("_APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP")).toEqual("false")

src/config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
BOOL_KEYS,
1212
STRING_KEYS,
1313
LIST_KEYS,
14-
LIST_OR_BOOL_KEYS
14+
LIST_OR_BOOL_KEYS,
15+
FLOAT_KEYS
1516
} from "./config/configmap"
1617

1718
/**
@@ -214,6 +215,18 @@ export class Configuration {
214215
}
215216
})
216217

218+
FLOAT_KEYS.forEach(k => {
219+
const current = process.env[k]
220+
221+
if (current) {
222+
const parsed = parseFloat(current)
223+
224+
if (!isNaN(parsed)) {
225+
conf[ENV_TO_KEY_MAPPING[k]] = parsed
226+
}
227+
}
228+
})
229+
217230
return conf
218231
}
219232

src/config/configmap.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { AppsignalOptions } from "./options"
22

3-
export const ENV_TO_KEY_MAPPING: Record<string, keyof AppsignalOptions> = {
3+
export const ENV_TO_KEY_MAPPING = {
44
APPSIGNAL_ACTIVE: "active",
55
APPSIGNAL_APP_ENV: "environment",
66
APPSIGNAL_APP_NAME: "name",
77
APPSIGNAL_BIND_ADDRESS: "bindAddress",
88
APPSIGNAL_CA_FILE_PATH: "caFilePath",
9+
APPSIGNAL_CPU_COUNT: "cpuCount",
910
APPSIGNAL_DISABLE_DEFAULT_INSTRUMENTATIONS: "disableDefaultInstrumentations",
1011
APPSIGNAL_DNS_SERVERS: "dnsServers",
1112
APPSIGNAL_ENABLE_HOST_METRICS: "enableHostMetrics",
@@ -38,14 +39,15 @@ export const ENV_TO_KEY_MAPPING: Record<string, keyof AppsignalOptions> = {
3839
APPSIGNAL_STATSD_PORT: "statsdPort",
3940
APPSIGNAL_WORKING_DIRECTORY_PATH: "workingDirectoryPath",
4041
APP_REVISION: "revision"
41-
}
42+
} satisfies Record<string, keyof AppsignalOptions>
4243

4344
export const PRIVATE_ENV_MAPPING: Record<string, keyof AppsignalOptions> = {
4445
_APPSIGNAL_ACTIVE: "active",
4546
_APPSIGNAL_APP_ENV: "environment",
4647
_APPSIGNAL_APP_NAME: "name",
4748
_APPSIGNAL_BIND_ADDRESS: "bindAddress",
4849
_APPSIGNAL_CA_FILE_PATH: "caFilePath",
50+
_APPSIGNAL_CPU_COUNT: "cpuCount",
4951
_APPSIGNAL_DNS_SERVERS: "dnsServers",
5052
_APPSIGNAL_ENABLE_HOST_METRICS: "enableHostMetrics",
5153
_APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP: "enableOpentelemetryHttp",
@@ -80,6 +82,7 @@ export const JS_TO_RUBY_MAPPING: Record<keyof AppsignalOptions, string> = {
8082
bindAddress: "bind_address",
8183
pushApiKey: "push_api_key",
8284
caFilePath: "ca_file_path",
85+
cpuCount: "cpu_count",
8386
disableDefaultInstrumentations: "disable_default_instrumentations",
8487
dnsServers: "dns_servers",
8588
enableHostMetrics: "enable_host_metrics",
@@ -115,7 +118,7 @@ export const JS_TO_RUBY_MAPPING: Record<keyof AppsignalOptions, string> = {
115118
workingDirectoryPath: "working_directory_path"
116119
}
117120

118-
export const BOOL_KEYS: string[] = [
121+
export const BOOL_KEYS: (keyof typeof ENV_TO_KEY_MAPPING)[] = [
119122
"APPSIGNAL_ACTIVE",
120123
"APPSIGNAL_ENABLE_HOST_METRICS",
121124
"APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP",
@@ -129,7 +132,7 @@ export const BOOL_KEYS: string[] = [
129132
"APPSIGNAL_SEND_SESSION_DATA"
130133
]
131134

132-
export const STRING_KEYS: string[] = [
135+
export const STRING_KEYS: (keyof typeof ENV_TO_KEY_MAPPING)[] = [
133136
"APPSIGNAL_APP_ENV",
134137
"APPSIGNAL_APP_NAME",
135138
"APPSIGNAL_BIND_ADDRESS",
@@ -150,7 +153,7 @@ export const STRING_KEYS: string[] = [
150153
"APP_REVISION"
151154
]
152155

153-
export const LIST_KEYS: string[] = [
156+
export const LIST_KEYS: (keyof typeof ENV_TO_KEY_MAPPING)[] = [
154157
"APPSIGNAL_DNS_SERVERS",
155158
"APPSIGNAL_FILTER_PARAMETERS",
156159
"APPSIGNAL_FILTER_SESSION_DATA",
@@ -160,6 +163,10 @@ export const LIST_KEYS: string[] = [
160163
"APPSIGNAL_REQUEST_HEADERS"
161164
]
162165

163-
export const LIST_OR_BOOL_KEYS: string[] = [
166+
export const LIST_OR_BOOL_KEYS: (keyof typeof ENV_TO_KEY_MAPPING)[] = [
164167
"APPSIGNAL_DISABLE_DEFAULT_INSTRUMENTATIONS"
165168
]
169+
170+
export const FLOAT_KEYS: (keyof typeof ENV_TO_KEY_MAPPING)[] = [
171+
"APPSIGNAL_CPU_COUNT"
172+
]

src/config/options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type AppsignalOptions = {
44
active: boolean
55
bindAddress: string
66
caFilePath: string
7+
cpuCount: number
78
disableDefaultInstrumentations: DefaultInstrumentationName[] | boolean
89
dnsServers: string[]
910
enableHostMetrics: boolean

0 commit comments

Comments
 (0)