Skip to content

Commit 369ce34

Browse files
committed
agents: fix http_client percentile calculation
p50 and p99 where flipped. Improved `test/agents/test-grpc-metrics.mjs` to make sure we don't regress. Fixes: #423 PR-URL: #424 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: EHortua <55801532+EHortua@users.noreply.github.com>
1 parent 8ad2641 commit 369ce34

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

agents/otlp/src/otlp_common.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ NSOLID_ENV_METRICS_NUMBERS(V)
347347
use_snake_case ? "http_client" : "httpClient",
348348
kNSMSecs,
349349
InstrumentValueType::kDouble,
350-
{{ 0.5, stor.http_client99_ptile },
351-
{ 0.99, stor.http_client_median }},
350+
{{ 0.5, stor.http_client_median },
351+
{ 0.99, stor.http_client99_ptile }},
352352
attrs);
353353
add_summary(metrics,
354354
process_start,

test/agents/test-grpc-metrics.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ function checkScopeMetrics(scopeMetrics) {
196196
if (dataPoint.quantileValues[1].value) {
197197
validateNumber(dataPoint.quantileValues[1].value, `${name}.quantileValues[1].value`);
198198
}
199+
200+
assert.ok(dataPoint.quantileValues[0].value >= dataPoint.quantileValues[1].value, `p99 ${name} should be >= p50 ${name}`);
199201
} else {
200202
assert.strictEqual(dataPoint.value, expectedMetric[2]);
201203
if (type === 'asInt') {
@@ -235,9 +237,13 @@ async function runTest({ getEnv }) {
235237
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
236238
env,
237239
};
238-
const child = new TestClient([], opts);
240+
const child = new TestClient(['-t', 'http'], opts);
239241
const agentId = await child.id();
240-
const config = await child.config({ app: 'my_app_name', interval: 100 });
242+
const config = await child.config({ app: 'my_app_name' });
243+
for (let i = 0; i < 10; i++) {
244+
await child.trace('http');
245+
}
246+
241247
grpcServer.once('metrics', mustCall(async () => {
242248
const metrics = await child.metrics();
243249
assert.strictEqual(config.app, 'my_app_name');
@@ -258,7 +264,6 @@ const testConfigs = [
258264
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
259265
NSOLID_GRPC_INSECURE: 1,
260266
NSOLID_GRPC: `localhost:${port}`,
261-
NSOLID_INTERVAL: 10000,
262267
};
263268
},
264269
},
@@ -268,7 +273,6 @@ const testConfigs = [
268273
NODE_DEBUG_NATIVE: 'nsolid_grpc_agent',
269274
NSOLID_GRPC_INSECURE: 1,
270275
NSOLID_SAAS: `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbtesting.localhost:${port}`,
271-
NSOLID_INTERVAL: 10000,
272276
};
273277
},
274278
},

0 commit comments

Comments
 (0)