-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## 📝 Summary <!-- Provide a concise summary of what this pull request is addressing. If this PR fixes any issues, list them here by number (e.g., Fixes #123). --> Fixes #2898. A v1 tracing panel for observability efforts https://github.com/user-attachments/assets/1c042e0b-2f70-4ec0-ad63-a0c59d5a89a4 ## 🔍 Description of Changes <!-- Detail the specific changes made in this pull request. Explain the problem addressed and how it was resolved. If applicable, provide before and after comparisons, screenshots, or any relevant details to help reviewers understand the changes easily. --> - view cell runs, status, code snippet and timestamps - hover sync between react components and vega chart - supports dark theme - each run now has a run_id context from the backend - note: the timestamps here should be 'more accurate' than the frontend timers since they come from code execution in the backend. Hence, there can also be a small discrepancy btwn them. ## 📋 Checklist - [X] I have read the [contributor guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md). - [X] For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on [Discord](https://marimo.io/discord?ref=pr), or the community [discussions](https://github.com/marimo-team/marimo/discussions) (Please provide a link if applicable). - [X] I have added tests for the changes made. - [X] I have run the code and verified that it works as expected. ## 📜 Reviewers <!-- Tag potential reviewers from the community or maintainers who might be interested in reviewing this pull request. Your PR will be reviewed more quickly if you can figure out the right person to tag with @ --> @akshayka OR @mscolnick --------- Co-authored-by: Myles Scolnick <[email protected]>
- Loading branch information
1 parent
e1b33c2
commit f332b70
Showing
23 changed files
with
1,178 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
|
||
import { cn } from "@/utils/cn"; | ||
|
||
interface ClearButtonProps { | ||
className?: string; | ||
dataTestId?: string; | ||
onClick: () => void; | ||
} | ||
|
||
export const ClearButton: React.FC<ClearButtonProps> = (props) => ( | ||
<button | ||
type="button" | ||
data-testid={props.dataTestId} | ||
className={cn( | ||
"text-xs font-semibold text-accent-foreground", | ||
props.className, | ||
)} | ||
onClick={props.onClick} | ||
> | ||
Clear | ||
</button> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
frontend/src/components/editor/chrome/panels/tracing-panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { Tracing } from "@/components/tracing/tracing"; | ||
import React from "react"; | ||
|
||
export const TracingPanel: React.FC = () => { | ||
return <Tracing />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import type { CellId } from "@/core/cells/ids"; | ||
import type { CellRun } from "@/core/cells/runs"; | ||
import type { ResolvedTheme } from "@/theme/useTheme"; | ||
import type { TopLevelSpec } from "vega-lite"; | ||
|
||
export const REACT_HOVERED_CELLID = "hoveredCellId"; | ||
export const VEGA_HOVER_SIGNAL = "cellHover"; | ||
|
||
export type ChartPosition = "sideBySide" | "above"; | ||
export interface ChartValues { | ||
cell: CellId; | ||
cellNum: number; | ||
startTimestamp: string; | ||
endTimestamp: string; | ||
elapsedTime: string; | ||
status: CellRun["status"]; | ||
} | ||
|
||
const cellNumField = "cellNum" satisfies keyof ChartValues; | ||
const cellField = "cell" satisfies keyof ChartValues; | ||
const startTimestampField = "startTimestamp" satisfies keyof ChartValues; | ||
const endTimestampField = "endTimestamp" satisfies keyof ChartValues; | ||
const statusField = "status" satisfies keyof ChartValues; | ||
|
||
export function createGanttBaseSpec( | ||
chartValues: ChartValues[], | ||
hiddenInputElementId: string, | ||
chartPosition: ChartPosition, | ||
theme: ResolvedTheme, | ||
): TopLevelSpec { | ||
return { | ||
$schema: "https://vega.github.io/schema/vega-lite/v5.json", | ||
background: theme === "dark" ? "black" : undefined, | ||
mark: { | ||
type: "bar", | ||
cornerRadius: 2, | ||
}, | ||
params: [ | ||
{ | ||
name: REACT_HOVERED_CELLID, | ||
bind: { element: `#${hiddenInputElementId}` }, | ||
}, | ||
{ | ||
name: VEGA_HOVER_SIGNAL, | ||
select: { | ||
type: "point", | ||
on: "mouseover", | ||
fields: [cellField], | ||
clear: "mouseout", | ||
}, | ||
}, | ||
], | ||
height: { step: 23 }, | ||
encoding: { | ||
y: { | ||
field: cellNumField, | ||
scale: { paddingInner: 0.2 }, | ||
sort: { field: cellNumField }, | ||
title: "cell", | ||
axis: chartPosition === "sideBySide" ? null : undefined, | ||
}, | ||
x: { | ||
field: startTimestampField, | ||
type: "temporal", | ||
axis: { orient: "top", title: null }, | ||
}, | ||
x2: { | ||
field: endTimestampField, | ||
type: "temporal", | ||
}, | ||
tooltip: [ | ||
{ | ||
field: startTimestampField, | ||
type: "temporal", | ||
timeUnit: "dayhoursminutesseconds", | ||
title: "Start", | ||
}, | ||
{ | ||
field: endTimestampField, | ||
type: "temporal", | ||
timeUnit: "dayhoursminutesseconds", | ||
title: "End", | ||
}, | ||
], | ||
size: { | ||
value: { | ||
expr: `${REACT_HOVERED_CELLID} == toString(datum.cell) ? 19.5 : 18`, | ||
}, | ||
}, | ||
color: { | ||
field: statusField, | ||
scale: { domain: ["success", "error"], range: ["#37BE5F", "red"] }, | ||
legend: null, | ||
}, | ||
}, | ||
data: { | ||
values: chartValues, | ||
}, | ||
config: { | ||
view: { | ||
stroke: "transparent", | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* Copyright 2024 Marimo. All rights reserved. */ | ||
import { describe, it, expect, beforeAll, afterAll, vi } from "vitest"; | ||
import { formatChartTime } from "./tracing"; | ||
|
||
describe("formatChartTime", () => { | ||
beforeAll(() => { | ||
// Mock Date to always use UTC | ||
vi.spyOn(global.Date.prototype, "getFullYear").mockImplementation(function ( | ||
this: Date, | ||
) { | ||
return this.getUTCFullYear(); | ||
}); | ||
vi.spyOn(global.Date.prototype, "getMonth").mockImplementation(function ( | ||
this: Date, | ||
) { | ||
return this.getUTCMonth(); | ||
}); | ||
vi.spyOn(global.Date.prototype, "getDate").mockImplementation(function ( | ||
this: Date, | ||
) { | ||
return this.getUTCDate(); | ||
}); | ||
vi.spyOn(global.Date.prototype, "getHours").mockImplementation(function ( | ||
this: Date, | ||
) { | ||
return this.getUTCHours(); | ||
}); | ||
vi.spyOn(global.Date.prototype, "getMinutes").mockImplementation(function ( | ||
this: Date, | ||
) { | ||
return this.getUTCMinutes(); | ||
}); | ||
vi.spyOn(global.Date.prototype, "getSeconds").mockImplementation(function ( | ||
this: Date, | ||
) { | ||
return this.getUTCSeconds(); | ||
}); | ||
vi.spyOn(global.Date.prototype, "getMilliseconds").mockImplementation( | ||
function (this: Date) { | ||
return this.getUTCMilliseconds(); | ||
}, | ||
); | ||
}); | ||
|
||
afterAll(() => { | ||
vi.restoreAllMocks(); | ||
}); | ||
|
||
it("should handle a timestamp with milliseconds correctly", () => { | ||
const timestamp = 1_704_067_200.123; | ||
const formattedTime = formatChartTime(timestamp); | ||
expect(formattedTime).toBe("2024-01-01 00:00:00.123"); | ||
}); | ||
|
||
it("should handle a timestamp at the start of the year correctly", () => { | ||
const timestamp = 1_704_067_200; | ||
const formattedTime = formatChartTime(timestamp); | ||
expect(formattedTime).toBe("2024-01-01 00:00:00.000"); | ||
}); | ||
|
||
it("should handle a timestamp at the end of the year correctly", () => { | ||
const timestamp = 1_704_067_199; | ||
const formattedTime = formatChartTime(timestamp); | ||
expect(formattedTime).toBe("2023-12-31 23:59:59.000"); | ||
}); | ||
}); |
Oops, something went wrong.