Skip to content

Commit cd62201

Browse files
authored
log-server: fix log number being exported (#186)
* log-server: fix log number being exported fixes #185 * changeset
1 parent 0a34617 commit cd62201

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

.changeset/lucky-emus-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lightmill/log-server': patch
3+
---
4+
5+
Fix extra column "number" being exported

packages/log-server/__tests__/app.test.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ describe('logs', () => {
648648
[
649649
{
650650
"experimentId": "getLogs:experimentId-1",
651-
"number": 1,
652651
"runId": "getLogs:runId-1",
653652
"type": "getLogs:type-1",
654653
"values": {
@@ -658,7 +657,6 @@ describe('logs', () => {
658657
},
659658
{
660659
"experimentId": "getLogs:experimentId-2",
661-
"number": 2,
662660
"runId": "getLogs:runId-2",
663661
"type": "getLogs:type-2",
664662
"values": {
@@ -683,7 +681,6 @@ describe('logs', () => {
683681
[
684682
{
685683
"experimentId": "getLogs:experimentId-1",
686-
"number": 1,
687684
"runId": "getLogs:runId-1",
688685
"type": "getLogs:type-1",
689686
"values": {
@@ -693,7 +690,6 @@ describe('logs', () => {
693690
},
694691
{
695692
"experimentId": "getLogs:experimentId-2",
696-
"number": 2,
697693
"runId": "getLogs:runId-2",
698694
"type": "getLogs:type-2",
699695
"values": {
@@ -715,9 +711,9 @@ describe('logs', () => {
715711
.expect(200);
716712
expect(store.getLogs).toHaveBeenCalledWith({ experimentId: 'exp' });
717713
expect(result.text).toMatchInlineSnapshot(`
718-
"type,run_id,mock_col1,mock_col2,mock_col3,number
719-
getLogs:type-1,getLogs:runId-1,log1-mock-value1,log1-mock-value2,,1
720-
getLogs:type-2,getLogs:runId-2,log2-mock-value1,log2-mock-value2,log2-mock-value3,2
714+
"type,run_id,mock_col1,mock_col2,mock_col3
715+
getLogs:type-1,getLogs:runId-1,log1-mock-value1,log1-mock-value2,
716+
getLogs:type-2,getLogs:runId-2,log2-mock-value1,log2-mock-value2,log2-mock-value3
721717
"
722718
`);
723719
});
@@ -731,7 +727,6 @@ describe('logs', () => {
731727
[
732728
{
733729
"experimentId": "getLogs:experimentId-1",
734-
"number": 1,
735730
"runId": "getLogs:runId-1",
736731
"type": "getLogs:type-1",
737732
"values": {
@@ -741,7 +736,6 @@ describe('logs', () => {
741736
},
742737
{
743738
"experimentId": "getLogs:experimentId-2",
744-
"number": 2,
745739
"runId": "getLogs:runId-2",
746740
"type": "getLogs:type-2",
747741
"values": {

packages/log-server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@types/supertest": "^2.0.16",
3737
"@types/yargs": "^17.0.32",
3838
"cross-env": "^7.0.3",
39+
"string-dedent": "^3.0.1",
3940
"supertest": "^6.3.3",
4041
"tsx": "^4.2.0",
4142
"type-fest": "^4.8.2",

packages/log-server/src/export.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ import { mapKeys, pickBy, pipe } from 'remeda';
44
import { Log, Store } from './store.js';
55
import { toSnakeCase } from './utils.js';
66

7-
const logColumns: Array<keyof Log> = ['type', 'experimentId', 'runId'];
7+
const csvLogColumns: Array<keyof Log> = ['type', 'experimentId', 'runId'];
8+
const jsonLogColumns: Array<keyof Log> = [
9+
'type',
10+
'experimentId',
11+
'runId',
12+
'values',
13+
];
814
const renamedLogColumns: Partial<Record<keyof Log, string>> = {};
9-
const ignoredLogValues: Array<keyof Log> = ['values'];
1015

1116
export function csvExportStream(
12-
store: Store,
17+
store: Pick<Store, 'getLogs' | 'getLogValueNames'>,
1318
filter: Parameters<Store['getLogs']>[0] &
14-
Parameters<Store['getLogValueNames']>[0],
19+
Parameters<Store['getLogValueNames']>[0] = {},
1520
): Readable {
1621
return pipeline(
1722
async function* () {
@@ -21,9 +26,9 @@ export function csvExportStream(
2126
(filter?.type == null || columnName !== 'type') &&
2227
(filter?.experimentId == null || columnName !== 'experimentId') &&
2328
(filter?.runId == null || columnName !== 'runId') &&
24-
!ignoredLogValues.includes(columnName);
29+
csvLogColumns.includes(columnName);
2530
let columns = [
26-
...logColumns
31+
...csvLogColumns
2732
.filter(logColumnFilter)
2833
.map((c) => renamedLogColumns[c] ?? c),
2934
...valueColumns,
@@ -65,8 +70,8 @@ export function csvExportStream(
6570
}
6671

6772
export function jsonExportStream(
68-
store: Store,
69-
filter: Parameters<Store['getLogs']>[0],
73+
store: Pick<Store, 'getLogs'>,
74+
filter: Parameters<Store['getLogs']>[0] = {},
7075
) {
7176
return Readable.from(stringifyLogs(store.getLogs(filter)));
7277
}
@@ -78,7 +83,11 @@ async function* stringifyLogs(logs: AsyncIterable<Log>) {
7883
yield started ? ',' : '';
7984
started = true;
8085
yield JSON.stringify(
81-
mapKeys(log, (key) => renamedLogColumns[key] ?? key),
86+
pipe(
87+
log,
88+
pickBy((v, k) => jsonLogColumns.includes(k)),
89+
mapKeys((key) => renamedLogColumns[key] ?? key),
90+
),
8291
stringifyDateSerializer,
8392
);
8493
}

pnpm-lock.yaml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)