Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing returning NaN when rate metrics change / reset counter #121

Merged
merged 13 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/silent-keys-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/api': patch
---

Filter out NaN values from metric charts
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dev-down:

.PHONY: dev-lint
dev-lint:
./docker/ingestor/run_linting.sh && npx nx run-many -t lint
./docker/ingestor/run_linting.sh && npx nx run-many -t lint:fix

.PHONY: ci-lint
ci-lint:
Expand Down
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"dev:task": "ts-node -r tsconfig-paths/register -r '@hyperdx/node-opentelemetry/build/src/tracing' ./src/tasks/index.ts",
"build": "rimraf ./build && tsc && tsc-alias",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"ci:lint": "yarn lint && yarn tsc --noEmit",
"ci:int": "jest --runInBand --ci --forceExit --coverage",
"dev:int": "jest --watchAll --runInBand --detectOpenHandles",
Expand Down
37 changes: 37 additions & 0 deletions packages/api/src/clickhouse/__tests__/clickhouse.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import * as clickhouse from '..';
import { closeDB, getServer } from '@/fixtures';

describe('clickhouse', () => {
const server = getServer();

beforeAll(async () => {
await server.start();
});

afterAll(async () => {
await server.closeHttpServer();
await closeDB();
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down Expand Up @@ -42,4 +54,29 @@ describe('clickhouse', () => {
expect(clickhouse.client.insert).toHaveBeenCalledTimes(2);
expect.assertions(2);
});

it('getMetricsChart avoids sending NaN to frontend', async () => {
jest
.spyOn(clickhouse.client, 'query')
.mockResolvedValueOnce({ json: () => Promise.resolve({}) } as any);

await clickhouse.getMetricsChart({
aggFn: clickhouse.AggFn.AvgRate,
dataType: clickhouse.MetricsDataType.Sum,
endTime: Date.now(),
granularity: clickhouse.Granularity.OneHour,
name: 'test',
q: '',
startTime: Date.now() - 1000 * 60 * 60 * 24,
teamId: 'test',
});

expect(clickhouse.client.query).toHaveBeenCalledTimes(2);
expect(clickhouse.client.query).toHaveBeenCalledWith(
expect.objectContaining({
jaggederest marked this conversation as resolved.
Show resolved Hide resolved
format: 'JSON',
query: expect.stringContaining('isNaN(rate) = 0'),
}),
);
});
});
5 changes: 2 additions & 3 deletions packages/api/src/clickhouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,6 @@ export const buildLogStreamAdditionalFilters = (
export const healthCheck = () => client.ping();

export const connect = async () => {
if (config.IS_CI) {
return;
}
// FIXME: this is a hack to avoid CI failure
logger.info('Checking connections to ClickHouse...');
// health check
Expand Down Expand Up @@ -814,6 +811,8 @@ FROM
(
?
)
WHERE
isNaN(rate) = 0
`.trim(),
[SqlString.raw(sumMetricSource)],
);
Expand Down
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"build": "next build",
"start": "next start",
"lint": "eslint . --ext .ts,.tsx",
"lint:fix": "eslint . --ext .ts,.tsx --fix",
"ci:lint": "yarn lint && yarn tsc --noEmit",
"ci:unit": "jest --ci --coverage"
},
Expand Down
Loading