Skip to content

Commit

Permalink
Add --observatory-host switch (flutter#9485)
Browse files Browse the repository at this point in the history
Adds --observatory-host, which allows callers to specify the localhost
IP binding directly. Allows users to set 0.0.0.0 or the host IP address
as is possible in the standalone VM, rather than restricting users to
loopback.

We retain the default behaviour of binding to loopback since the vast
majority of observatory use-cases involve local access (e.g. host tests
on flutter_tester) or port-forwarded local access (e.g. flutter driver
device tests). However, some scenarios, such as QA test labs, may
benefit from binding to a publicly-accessible IP address.
  • Loading branch information
cbracken authored Jun 25, 2019
1 parent 20a76de commit 107fe82
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ std::string Settings::ToString() const {
stream << "enable_dart_profiling: " << enable_dart_profiling << std::endl;
stream << "disable_dart_asserts: " << disable_dart_asserts << std::endl;
stream << "enable_observatory: " << enable_observatory << std::endl;
stream << "observatory_host: " << observatory_host << std::endl;
stream << "observatory_port: " << observatory_port << std::endl;
stream << "ipv6: " << ipv6 << std::endl;
stream << "use_test_fonts: " << use_test_fonts << std::endl;
stream << "enable_software_rendering: " << enable_software_rendering
<< std::endl;
Expand Down
12 changes: 9 additions & 3 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ struct Settings {
std::string advisory_script_entrypoint = "main";

// Observatory settings

// Whether the Dart VM service should be enabled.
bool enable_observatory = false;
// Port on target will be auto selected by the OS. A message will be printed
// on the target with the port after it has been selected.

// The IP address to which the Dart VM service is bound.
std::string observatory_host;

// The port to which the Dart VM service is bound. When set to `0`, a free
// port will be automatically selected by the OS. A message is logged on the
// target indicating the URL at which the VM service can be accessed.
uint32_t observatory_port = 0;
bool ipv6 = false;

// Determines whether an authentication code is required to communicate with
// the VM service.
Expand Down
6 changes: 3 additions & 3 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,9 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(

tonic::DartState::Scope scope(service_isolate);
if (!DartServiceIsolate::Startup(
settings.ipv6 ? "::1" : "127.0.0.1", // server IP address
settings.observatory_port, // server observatory port
tonic::DartState::HandleLibraryTag, // embedder library tag handler
settings.observatory_host, // server IP address
settings.observatory_port, // server observatory port
tonic::DartState::HandleLibraryTag, // embedder library tag handler
false, // disable websocket origin check
settings.disable_service_auth_codes, // disable VM service auth codes
error // error (out)
Expand Down
14 changes: 12 additions & 2 deletions shell/common/switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.enable_observatory =
!command_line.HasOption(FlagForSwitch(Switch::DisableObservatory));

// Set Observatory Host
if (command_line.HasOption(FlagForSwitch(Switch::DeviceObservatoryHost))) {
command_line.GetOptionValue(FlagForSwitch(Switch::DeviceObservatoryHost),
&settings.observatory_host);
}
// Default the observatory port based on --ipv6 if not set.
if (settings.observatory_host.empty()) {
settings.observatory_host =
command_line.HasOption(FlagForSwitch(Switch::IPv6)) ? "::1"
: "127.0.0.1";
}

// Set Observatory Port
if (command_line.HasOption(FlagForSwitch(Switch::DeviceObservatoryPort))) {
if (!GetSwitchValue(command_line, Switch::DeviceObservatoryPort,
Expand All @@ -207,8 +219,6 @@ Settings SettingsFromCommandLine(const fml::CommandLine& command_line) {
settings.disable_dart_asserts =
command_line.HasOption(FlagForSwitch(Switch::DisableDartAsserts));

settings.ipv6 = command_line.HasOption(FlagForSwitch(Switch::IPv6));

settings.start_paused =
command_line.HasOption(FlagForSwitch(Switch::StartPaused));

Expand Down
8 changes: 7 additions & 1 deletion shell/common/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ DEF_SWITCH(DartFlags,
"dart-flags",
"Flags passed directly to the Dart VM without being interpreted "
"by the Flutter shell.")
DEF_SWITCH(DeviceObservatoryHost,
"observatory-host",
"The hostname/IP address on which the Dart Observatory should "
"be served. If not set, defaults to 127.0.0.1 or ::1 depending on "
"whether --ipv6 is specified.")
DEF_SWITCH(DeviceObservatoryPort,
"observatory-port",
"A custom Dart Observatory port. The default is to pick a randomly "
Expand All @@ -71,7 +76,8 @@ DEF_SWITCH(DisableObservatory,
"in release mode.")
DEF_SWITCH(IPv6,
"ipv6",
"Bind to the IPv6 localhost address for the Dart Observatory.")
"Bind to the IPv6 localhost address for the Dart Observatory. "
"Ignored if --observatory-host is set.")
DEF_SWITCH(EnableDartProfiling,
"enable-dart-profiling",
"Enable Dart profiling. Profiling information can be viewed from "
Expand Down

0 comments on commit 107fe82

Please sign in to comment.