Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a trace viewer in the execution page with timeseries data #7889

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bduffany
Copy link
Member

@bduffany bduffany commented Nov 13, 2024

  • Show a trace viewer in the execution page including event spans (flame chart) and timeseries data
    • The trace is built on the server from the ExecutedActionMetadata and is streamed to the client over the /file/download endpoint using the JSON Trace Event Format
  • There are a couple reasons to use the trace viewer:
    • It's more consistent with the invocation Timing profile and lets us get rid of some custom UI code for the execution timeline
    • It already supports rendering nice timeseries charts
    • It's interactive
    • It will allow adding support for more fine-grained trace spans (e.g. download snapshot). Jaeger trace spans would also be super useful to display in this chart (if the execution was traced)
  • Only CPU timeseries data is shown for now, but memory usage, and IO rops, wops, wbytes, rbytes are in the works.

image

@bduffany bduffany force-pushed the execution-ui-updates branch 2 times, most recently from 5cba57a to a7368f6 Compare November 13, 2024 05:01
@bduffany bduffany marked this pull request as ready for review November 13, 2024 15:24
@bduffany bduffany marked this pull request as draft November 13, 2024 15:24
//
// The format is documented here:
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU
package trace_events
Copy link
Member Author

@bduffany bduffany Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally tried using https://github.com/omaskery/teffy instead of writing this package, but ultimately didn't like how it turned out:

  • The library nicely models the Trace Event Format from a correctness standpoint. It "makes invalid states unrepresentable" to a strict degree, splitting out the different "types" of events into separate structs rather than using a single flat struct with a "type" field (i.e. the "ph" / "phase" field in the JSON object). But the library heavily relies on struct embedding, which I found overly verbose and confusing since it suggests nesting that doesn't actually exist in the format. (It's confusing both when reading the call-sites and when reading the library implementation.) The JSON representation is also hidden in a separate "io" package which made it harder to mentally map the structs to the actual Trace Event Format. For example, the Counter event has a Values field which actually maps to "args" in the JSON representation, which was confusing to me and took a minute to grok.
  • The StreamingWriter implementation doesn't append newlines between each JSON object which makes it non-browser-friendly. In the browser we rely on the newline to separate objects, since the browser doesn't have a streaming JSON parser built in. (This is somewhat minor though and could be patched in if we really wanted it.)

@bduffany bduffany marked this pull request as ready for review November 13, 2024 16:43
@bduffany bduffany changed the title Show a trace viewer in the execution page Show a trace viewer in the execution page with timeseries data Nov 13, 2024
Copy link
Member

@jdhollen jdhollen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like @tylerwilliams has more opinions about the structure of file requests in buildbuddy_server than i do, so i'm really just focusing on the ts stuff, which all seems fine, just some dumb little nits.

"stream"
)
.then((response) => {
if (!response.body) throw new Error("failed to read profile: response body is null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal pet peeve: could be empty, probably is undefined.

Copy link
Member Author

@bduffany bduffany Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsc says the type of response.body is ReadableStream<Uint8Array<ArrayBufferLike>> | null in this case, so I think this is correct. Checked === null explicitly though to limit the type-narrowing magic here

}

getExecutionId() {
return this.props.search.get("executionId") || this.state.executionId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition feels backward to me? i guess they shouldn't mismatch and one just shows up later?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a clarifying comment

})}
{this.state.profile ? (
<TraceViewer profile={this.state.profile} fitToContent filterHidden />
) : this.state.profileLoading ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order seems wrong to me here (i.e., we should always show a spinner if profileLoading == true)--i assume it's because we always clear profile when we have something pending.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, the logic is technically correct but I do think it's more clear to swap the order here (done)

@@ -62,11 +63,14 @@ const TIME_SERIES_EVENT_NAMES_AND_ARG_KEYS: Map<string, string> = new Map([
["System load average", "load"],
["Network Up usage (total)", "system network up (Mbps)"],
["Network Down usage (total)", "system network down (Mbps)"],

// Executor
["CPU usage", "cpu"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe update the comment above to explain where these values come from + why we don't need "CPU Usage" for "Bazel" (which has "CPU usage (Bazel)") but do for "Executor"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some more detail to the comments but not sure if I totally understood the concern - lmk if it's still unclear?

Copy link
Member Author

@bduffany bduffany Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw I don't know the original context for this (maybe @luluz66 remembers) but I think we could potentially remove this explicit list and just render all of the timeseries, which are identified by "ph": "C" ("Counter") in the JSON objects. (Spans have "ph":"X" and timeseries have "ph":"C")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. this list is used as a filter when parsing trace events.

const panels = [
buildEventsPanel(trace.traceEvents, fitToContent),
buildLinePlotsPanel(trace.traceEvents, fitToContent),
].filter((panel) => panel.sections.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it mean to have a panel with no sections / why do we need to guard for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment

@bduffany bduffany force-pushed the execution-ui-updates branch 3 times, most recently from 1528328 to dffb288 Compare November 13, 2024 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants