diff --git a/.changesets/implement-cpu-count-configuration-option.md b/.changesets/implement-cpu-count-configuration-option.md index 1774a303..b2f5aacd 100644 --- a/.changesets/implement-cpu-count-configuration-option.md +++ b/.changesets/implement-cpu-count-configuration-option.md @@ -5,6 +5,5 @@ type: "add" 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. -To set it, use the `APPSIGNAL_CPU_COUNT` environment variable, the `cpu_count` -configuration option in the Ruby, Elixir or Python integrations, the `cpuCount` attribute in the Node.js instrumentation, or the `cpu_count` configuration option in the stand-alone agent TOML configuration file. +To set it, use the `cpuCount` configuration option, or the `APPSIGNAL_CPU_COUNT` environment variable. diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index dc9c5425..fc56a99a 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -129,11 +129,15 @@ describe("Configuration", () => { process.env["APPSIGNAL_ENABLE_STATSD"] = "true" process.env["APPSIGNAL_ENABLE_HOST_METRICS"] = "false" process.env["APPSIGNAL_DNS_SERVERS"] = "8.8.8.8,8.8.4.4" + process.env["APPSIGNAL_CPU_COUNT"] = "1.5" + const envOptions = { enableStatsd: true, enableHostMetrics: false, - dnsServers: ["8.8.8.8", "8.8.4.4"] + dnsServers: ["8.8.8.8", "8.8.4.4"], + cpuCount: 1.5 } + const expectedConfig = { ...expectedDefaultConfig, ...envOptions @@ -319,6 +323,7 @@ describe("Configuration", () => { expect(env("_APPSIGNAL_APP_NAME")).toBeUndefined() expect(env("_APPSIGNAL_BIND_ADDRESS")).toBeUndefined() expect(env("_APPSIGNAL_CA_FILE_PATH")).toMatch(/cert\/cacert\.pem$/) + expect(env("_APPSIGNAL_CPU_COUNT")).toBeUndefined() expect(env("_APPSIGNAL_DNS_SERVERS")).toBeUndefined() expect(env("_APPSIGNAL_ENABLE_HOST_METRICS")).toEqual("true") expect(env("_APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP")).toEqual("true") @@ -367,6 +372,7 @@ describe("Configuration", () => { name, active: true, bindAddress: "0.0.0.0", + cpuCount: 1.5, pushApiKey, dnsServers: ["8.8.8.8", "8.8.4.4"], enableHostMetrics: false, @@ -397,6 +403,7 @@ describe("Configuration", () => { expect(env("_APPSIGNAL_ACTIVE")).toEqual("true") expect(env("_APPSIGNAL_APP_NAME")).toEqual(name) expect(env("_APPSIGNAL_BIND_ADDRESS")).toEqual("0.0.0.0") + expect(env("_APPSIGNAL_CPU_COUNT")).toEqual("1.5") expect(env("_APPSIGNAL_DNS_SERVERS")).toEqual("8.8.8.8,8.8.4.4") expect(env("_APPSIGNAL_ENABLE_HOST_METRICS")).toEqual("false") expect(env("_APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP")).toEqual("false") diff --git a/src/config.ts b/src/config.ts index c9f97966..2de5fdef 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,7 +11,8 @@ import { BOOL_KEYS, STRING_KEYS, LIST_KEYS, - LIST_OR_BOOL_KEYS + LIST_OR_BOOL_KEYS, + FLOAT_KEYS } from "./config/configmap" /** @@ -214,6 +215,18 @@ export class Configuration { } }) + FLOAT_KEYS.forEach(k => { + const current = process.env[k] + + if (current) { + const parsed = parseFloat(current) + + if (!isNaN(parsed)) { + conf[ENV_TO_KEY_MAPPING[k]] = parsed + } + } + }) + return conf } diff --git a/src/config/configmap.ts b/src/config/configmap.ts index 26425d25..4787c35a 100644 --- a/src/config/configmap.ts +++ b/src/config/configmap.ts @@ -6,6 +6,7 @@ export const ENV_TO_KEY_MAPPING: Record = { APPSIGNAL_APP_NAME: "name", APPSIGNAL_BIND_ADDRESS: "bindAddress", APPSIGNAL_CA_FILE_PATH: "caFilePath", + APPSIGNAL_CPU_COUNT: "cpuCount", APPSIGNAL_DISABLE_DEFAULT_INSTRUMENTATIONS: "disableDefaultInstrumentations", APPSIGNAL_DNS_SERVERS: "dnsServers", APPSIGNAL_ENABLE_HOST_METRICS: "enableHostMetrics", @@ -46,6 +47,7 @@ export const PRIVATE_ENV_MAPPING: Record = { _APPSIGNAL_APP_NAME: "name", _APPSIGNAL_BIND_ADDRESS: "bindAddress", _APPSIGNAL_CA_FILE_PATH: "caFilePath", + _APPSIGNAL_CPU_COUNT: "cpuCount", _APPSIGNAL_DNS_SERVERS: "dnsServers", _APPSIGNAL_ENABLE_HOST_METRICS: "enableHostMetrics", _APPSIGNAL_ENABLE_OPENTELEMETRY_HTTP: "enableOpentelemetryHttp", @@ -80,6 +82,7 @@ export const JS_TO_RUBY_MAPPING: Record = { bindAddress: "bind_address", pushApiKey: "push_api_key", caFilePath: "ca_file_path", + cpuCount: "cpu_count", disableDefaultInstrumentations: "disable_default_instrumentations", dnsServers: "dns_servers", enableHostMetrics: "enable_host_metrics", @@ -163,3 +166,5 @@ export const LIST_KEYS: string[] = [ export const LIST_OR_BOOL_KEYS: string[] = [ "APPSIGNAL_DISABLE_DEFAULT_INSTRUMENTATIONS" ] + +export const FLOAT_KEYS: string[] = ["APPSIGNAL_CPU_COUNT"] diff --git a/src/config/options.ts b/src/config/options.ts index 81efb03b..7e24b5cd 100644 --- a/src/config/options.ts +++ b/src/config/options.ts @@ -4,6 +4,7 @@ export type AppsignalOptions = { active: boolean bindAddress: string caFilePath: string + cpuCount: number disableDefaultInstrumentations: DefaultInstrumentationName[] | boolean dnsServers: string[] enableHostMetrics: boolean