Skip to content

Commit 91b38b5

Browse files
committed
feat: add event utilities
1 parent bc94e30 commit 91b38b5

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

src/events.utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import http, { RefinedResponse, ResponseType } from "k6/http";
2+
import { getHeaders } from "./user.utils";
3+
import { fail } from "k6";
4+
//@ts-ignore
5+
import { FormData } from "https://jslib.k6.io/formdata/0.0.2/index.js";
6+
import {
7+
EventDTO,
8+
} from "./models";
9+
10+
const rootUrl = __ENV.ROOT_URL;
11+
12+
export function getLastEvents(since: number, type: 'events' | 'traces' = 'events'): RefinedResponse<ResponseType | undefined> {
13+
let headers = getHeaders();
14+
return http.get(`${rootUrl}/infra/v2/event/list/${type}/${since}`, { headers });
15+
}
16+
17+
export function getLastEventsOrFail(since: number, type: 'events' | 'traces' = 'events'): EventDTO[] {
18+
const res = getLastEvents(since, type);
19+
if (res.status !== 200) {
20+
fail(`Failed to get last events since ${since} of type ${type}`);
21+
}
22+
return JSON.parse(res.body as string) as EventDTO[];
23+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export * from "./userbook.utils";
1919
export * from "./ws.utils";
2020
export * from "./archive.utils";
2121
export * from "./explorer.utils";
22+
export * from "./events.utils";

src/models.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,19 @@ export type AppImportResult = {
301301
resourcesIdsMap: Record<string, Record<string, string>>;
302302
duplicatesNumberMap: Record<string, number>;
303303
};
304+
305+
306+
export type EventDTO = {
307+
_id: string;
308+
resource: string;
309+
"event-type": string;
310+
module: string;
311+
date: number;
312+
userId: string;
313+
profil: string;
314+
structures: string[];
315+
classes: string[];
316+
groups: string[];
317+
referer: string;
318+
sessionId: string;
319+
};

0 commit comments

Comments
 (0)