Fix stale field mapping in external chart api (#247)

This commit is contained in:
Mike Shi 2024-01-18 15:15:01 -08:00 committed by GitHub
parent c5b10759ff
commit 9c666fb915
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -0,0 +1,6 @@
---
'@hyperdx/api': patch
---
Fixed /api/v1/logs/chart from returning null values due to stale property type
mappings

View file

@ -9,6 +9,7 @@ import * as clickhouse from '@/clickhouse';
import { getTeam } from '@/controllers/team';
import { validateUserAccessKey } from '@/middleware/auth';
import { Api400Error, Api403Error } from '@/utils/errors';
import logger from '@/utils/logger';
import rateLimiter from '@/utils/rateLimiter';
import { SimpleCache } from '@/utils/redis';
@ -115,6 +116,17 @@ router.get(
endTimeNum,
);
// TODO: hacky way to make sure the cache is update to date
if (
!clickhouse.doesLogsPropertyExist(field, propertyTypeMappingsModel) ||
!clickhouse.doesLogsPropertyExist(groupBy, propertyTypeMappingsModel)
) {
logger.warn({
message: `getChart: Property type mappings cache is out of date (${field}, ${groupBy}})`,
});
await propertyTypeMappingsModel.refresh();
}
// TODO: expose this to the frontend ?
const MAX_NUM_GROUPS = 20;