-
Notifications
You must be signed in to change notification settings - Fork 472
Add internal profiling to debug tool #32423
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
base: main
Are you sure you want to change the base?
Conversation
7a2d70c
to
754036d
Compare
- Instead of waiting until port forwarding, we read from stderr until we know for sure port forwarding has started - Renamed `create_kubectl_port_forwarder` to `create_pg_wire_port_forwarder` since we'll be port forwarding more than once - Removed the retry mechanism given we don't see the port forwarding disconnecting too often and we can't do it AND initial acknowledgement together easily - Tie child process to a struct instead of a tokio spawn.
We create an initialization function that preprocesses as much as possible and maps args to context values.
I kept the trait but realized the enum is a bit redundant, especially since we have the Context enum
754036d
to
a2867a8
Compare
Given we're always creating a PathBuf from start time, it makes sense to just pass the PathBuf itself
- Use stdout instead of stderr - Remove sharing of context - Fix bug where process was being killed on connecting to port forward
- Introduced InternalHttpDumpClient for downloading and saving heap profile data and Prometheus metrics from internal HTTP endpoints. - Changes service for port forwarding from balancerd to environmentd for better consistency with metrics - Refactor "find" methods for port forwarding to be more modular. Separates out port finding / port forwarder creation from service finding
- Introduced a new asynchronous function `get_container_ip` to fetch the IP address of a Docker container using its ID. Doing this means we don't need the user to map ports when doing `DOCKER RUN` - Changes mz_connection_url for the emulator to an optional argument and global now that we have the container's IP
- Update CLI flags in docs and clippy/lint errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs part lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet!
@@ -1,7 +1,7 @@ | |||
[package] | |||
name = "mz-debug" | |||
description = "Debug tool for self-managed Materialize." | |||
version = "0.1.0" | |||
version = "0.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumping the version like this is a good habit, but out of curiosity is it necessary? do we publish it anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not necessary, just something manual I do whenever I decide to publish haha. We do publish it as a curl
able binary that we expose via the docs!
static INTERNAL_HOST_ADDRESS: &str = "127.0.0.1"; | ||
static INTERNAL_HTTP_PORT: i32 = 6878; | ||
|
||
/// A struct that handles downloading and saving profile data from HTTP endpoints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we always try to end comments with periods, in other words, make them complete sentences.
output_path: &Path, | ||
) -> Result<(), anyhow::Error> { | ||
// Try HTTPS first, then fall back to HTTP if that fails | ||
let mut url = format!("https://{}", relative_url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of manually formatting the URL like this I would opt to use the url
crate and then the set_scheme(...)
method on the Url
type
|
||
/// Downloads and saves heap profile data | ||
pub async fn dump_heap_profile(&self, relative_url: &str, service_name: &str) -> Result<()> { | ||
let output_dir = self.context.base_path.join("profiles"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe these directory names should be constants that are grouped at the top of the file? That way it's easier to determine what folders the debug tool might create? Not blocking but just a thought
ContainerServiceDumper::Docker(dumper) => dumper.dump_container_resources().await, | ||
} | ||
} | ||
enum DebugModeContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I like how this turned out!
See commit messages for details
Motivation
"Scrape prometheus metrics" and "Scrape profiling" from https://github.com/MaterializeInc/database-issues/issues/8908
Tips for reviewer
Checklist
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way), then it is tagged with aT-proto
label.