Skip to content

Commit

Permalink
Change upload-all to upload crash reports by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjduffy committed Nov 7, 2023
1 parent ac1d68a commit 27356f1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 16 deletions.
9 changes: 3 additions & 6 deletions packages/replay/src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
MetadataOptions,
Options,
SourcemapUploadOptions,
UploadOptions,
UploadAllOptions,
} from "./types";
import { assertValidBrowserName, fuzzyBrowserName } from "./utils";
import { maybeAuthenticateUser } from "./auth";
Expand Down Expand Up @@ -82,10 +82,7 @@ commandWithGlobalOptions("upload-all")
.option("--api-key <key>", "Authentication API Key")
.option("--filter <filter string>", "String to filter recordings")
.option("--batch-size <batchSize number>", "Number of recordings to upload in parallel (max 25)")
.option(
"--include-in-progress",
"Upload all recordings, including ones with an in progress status"
)
.option("--exclude-crashes", "Do not upload crash reports which are always uploaded by default")
.action(commandUploadAllRecordings);

commandWithGlobalOptions("view <id>")
Expand Down Expand Up @@ -232,7 +229,7 @@ async function commandProcessRecording(id: string, opts: CommandLineOptions) {
}
}

async function commandUploadAllRecordings(opts: CommandLineOptions & UploadOptions) {
async function commandUploadAllRecordings(opts: CommandLineOptions & UploadAllOptions) {
try {
debug("Options", opts);

Expand Down
66 changes: 66 additions & 0 deletions packages/replay/src/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { RecordingEntry, filterRecordings } from "./main";

describe("filterRecordings", () => {
it("excludes crash reports by default", () => {
const recordings: RecordingEntry[] = [
{
status: "crashed",
id: "1",
createTime: new Date(),
metadata: {},
runtime: "chromium",
sourcemaps: [],
},
{
status: "crashUploaded",
id: "2",
createTime: new Date(),
metadata: {},
runtime: "chromium",
sourcemaps: [],
},
{
status: "onDisk",
id: "3",
createTime: new Date(),
metadata: {},
runtime: "chromium",
sourcemaps: [],
},
];

const filtered = filterRecordings(recordings, r => r.id === "3");
expect(filtered).toHaveLength(1);
});
it("inclues crash reports when includeCrashes is set", () => {
const recordings: RecordingEntry[] = [
{
status: "crashed",
id: "1",
createTime: new Date(),
metadata: {},
runtime: "chromium",
sourcemaps: [],
},
{
status: "crashUploaded",
id: "2",
createTime: new Date(),
metadata: {},
runtime: "chromium",
sourcemaps: [],
},
{
status: "onDisk",
id: "3",
createTime: new Date(),
metadata: {},
runtime: "chromium",
sourcemaps: [],
},
];

const filtered = filterRecordings(recordings, r => r.id === "3", true);
expect(filtered).toHaveLength(2);
});
});
31 changes: 22 additions & 9 deletions packages/replay/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
Options,
RecordingEntry,
SourceMapEntry,
UploadOptions,
UploadAllOptions,
} from "./types";
import { add, sanitize, source as sourceMetadata, test as testMetadata } from "../metadata";
import { generateDefaultTitle } from "./generateDefaultTitle";
Expand Down Expand Up @@ -239,22 +239,35 @@ function updateStatus(recording: RecordingEntry, status: RecordingEntry["status"
recording.status = status;
}

function filterRecordings(recordings: RecordingEntry[], filter?: FilterOptions["filter"]) {
export function filterRecordings(
recordings: RecordingEntry[],
filter?: FilterOptions["filter"],
includeCrashes?: boolean
) {
let filteredRecordings = recordings;
debug("Recording log contains %d replays", recordings.length);
if (filter && typeof filter === "string") {
debug("Using filter: %s", filter);
const exp = jsonata(`$filter($, ${filter})[]`);
recordings = exp.evaluate(recordings) || [];
filteredRecordings = exp.evaluate(recordings) || [];

debug("Filtering resulted in %d replays", recordings.length);
debug("Filtering resulted in %d replays", filteredRecordings.length);
} else if (typeof filter === "function") {
debug("Using filter function");
recordings = recordings.filter(filter);
filteredRecordings = recordings.filter(filter);

debug("Filtering resulted in %d replays", filteredRecordings.length);
}

debug("Filtering resulted in %d replays", recordings.length);
if (includeCrashes) {
recordings.forEach(r => {
if (r.status === "crashed" && !filteredRecordings.includes(r)) {
filteredRecordings.push(r);
}
});
}

return recordings;
return filteredRecordings;
}

// Convert a recording into a format for listing.
Expand Down Expand Up @@ -531,11 +544,11 @@ async function processRecording(id: string, opts: Options = {}) {
return succeeded ? recordingId : null;
}

async function uploadAllRecordings(opts: Options & UploadOptions = {}) {
async function uploadAllRecordings(opts: Options & UploadAllOptions = {}) {
const server = getServer(opts);
const dir = getDirectory(opts);
const allRecordings = readRecordings(dir).filter(r => !uploadSkipReason(r));
const recordings = filterRecordings(allRecordings, opts.filter);
const recordings = filterRecordings(allRecordings, opts.filter, !opts.excludeCrashes);

if (recordings.length === 0) {
if (opts.filter && allRecordings.length > 0) {
Expand Down
3 changes: 2 additions & 1 deletion packages/replay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ export interface ListOptions extends FilterOptions {
all?: boolean;
}

export interface UploadOptions extends FilterOptions {
export interface UploadAllOptions extends FilterOptions {
batchSize?: number;
warn?: boolean;
excludeCrashes?: boolean;
}

/**
Expand Down

0 comments on commit 27356f1

Please sign in to comment.