Skip to content

Commit

Permalink
Add service_port_delta config for livehandler
Browse files Browse the repository at this point in the history
Instead of hard-coding the service port delta for the livehandler, make
the service port delta configurable while still defaulting to the expected
value of 2. This allows cloud and/or containerized setups to access the
web UI through a non-standard port while continuing to access the
livehandler through a reverse proxy just by setting the service port
delta to 0.

Issue: https://progress.opensuse.org/issues/153499
  • Loading branch information
deborahbrouwer committed Feb 1, 2024
1 parent 34cd7cf commit 07543d2
Show file tree
Hide file tree
Showing 16 changed files with 34 additions and 13 deletions.
8 changes: 1 addition & 7 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,7 @@ function makeWsUrlAbsolute(url, servicePortDelta) {
// don't put a port in the URL if there's no explicit port
port = '';
} else {
if (port !== 80 || port !== 443) {
// if not using default ports we assume we're not accessing the web UI via Apache/NGINX
// reverse proxy
// -> so if not specified otherwise, we're further assuming a connection to the livehandler
// daemon which is supposed to run under the <web UI port> + 2
port += servicePortDelta ? servicePortDelta : 2;
}
if (port !== 80 || port !== 443) port += servicePortDelta;
port = ':' + port;
}

Expand Down
4 changes: 3 additions & 1 deletion assets/javascripts/running.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ var developerMode = {
// state of the page elements and the web socket connection to web UI
develWsUrl: undefined, // URL for developer session web socket connection
statusOnlyWsUrl: undefined, // URL for status-only web socket connection
servicePortDelta: undefined, // delta from web UI port on which to directly connect to livehandler
wsConnection: undefined, // current WebSocket object
hasWsError: false, // whether an web socket error occurred (cleared when we finally receive a message from os-autoinst)
useDeveloperWsRoute: undefined, // whether the developer web socket route is used
Expand Down Expand Up @@ -544,6 +545,7 @@ function setupDeveloperPanel() {
// find URLs for web socket connections
developerMode.develWsUrl = panel.data('developer-url');
developerMode.statusOnlyWsUrl = panel.data('status-only-url');
developerMode.servicePortDelta = panel.data('service-port-delta');

// setup toggle for body
var panelHeader = panel.find('.card-header');
Expand Down Expand Up @@ -973,7 +975,7 @@ function setupWebsocketConnection() {
developerMode.useDeveloperWsRoute = false;
url = developerMode.statusOnlyWsUrl;
}
url = makeWsUrlAbsolute(url);
url = makeWsUrlAbsolute(url, developerMode.servicePortDelta);

// establish ws connection
console.log('Establishing ws connection to ' + url);
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/ws_console.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function setupWebSocketConsole() {
if (!url.length) {
return;
}
url = makeWsUrlAbsolute(url);
url = makeWsUrlAbsolute(url, form.data('service-port-delta'));

// establish and handle web socket connection
window.wsUrl = url;
Expand Down
7 changes: 7 additions & 0 deletions etc/openqa/openqa.ini
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
## collapsing parallel children by default completely)
#parallel_children_collapsable_results = passed softfailed

## For the developer mode panel: if not accessing the web UI via Apache/NGINX reverse
## proxy, then connect to the livehandler daemon at the <web UI port> + service_port_delta.
## The livehandler daemon is supposed to run under the <web UI port> + 2.
## If you want to keep using a reverse proxy while accessing the web UI through a custom port
## (e.g. 8080) then just set `service_port_delta = 0`.
# service_port_delta = 2

#[scm git]
# name of remote to get updates from before committing changes (e.g. origin, leave out-commented to disable remote update)
#update_remote = origin
Expand Down
1 change: 1 addition & 0 deletions lib/OpenQA/Setup.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ sub read_config ($app) {
auto_clone_limit => 20,
force_result_regex => '',
parallel_children_collapsable_results => join(' ', OK_RESULTS),
service_port_delta => 2,
},
rate_limits => {
search => 5,
Expand Down
5 changes: 4 additions & 1 deletion lib/OpenQA/WebAPI/Controller/API/V1/Worker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ sub create {

my %event_data = (id => $id, host => $host, instance => $instance);
$self->emit_event('openqa_worker_register', \%event_data);
$self->render(json => {id => $id});
$self->render(
json => {
id => $id,
service_port_delta => $self->config->{global}->{service_port_delta}});
}

=over 4
Expand Down
6 changes: 5 additions & 1 deletion lib/OpenQA/WebAPI/Controller/Developer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ sub ws_console ($self) {
my $ws_url = $self->determine_os_autoinst_web_socket_url($job);
$ws_url = $ws_url ? determine_web_ui_web_socket_url($job->id) : undef if $use_proxy;

return $self->render(job => $job, ws_url => ($ws_url // ''), use_proxy => $use_proxy);
return $self->render(
job => $job,
ws_url => ($ws_url // ''),
use_proxy => $use_proxy,
service_port_delta => $self->config->{global}->{service_port_delta});
}

1;
1 change: 1 addition & 0 deletions lib/OpenQA/WebAPI/Controller/Test.pm
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ sub live ($self) {
developer_session => $job->developer_session,
is_devel_mode_accessible => $current_user && $current_user->is_operator,
current_user_id => $current_user ? $current_user->id : 'undefined',
service_port_delta => $self->config->{global}->{service_port_delta},
});
$self->render('test/live');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/OpenQA/Worker/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ sub post_upload_progress_to_liveviewhandler {
my $job_id = $self->id;
$self->client->send(
post => "/liveviewhandler/api/v1/jobs/$job_id/upload_progress",
service_port_delta => 2, # liveviewhandler is supposed to run on web UI port + 2
service_port_delta => $self->client->service_port_delta,
json => \%new_progress_info,
non_critical => 1,
callback => sub {
Expand Down
2 changes: 2 additions & 0 deletions lib/OpenQA/Worker/WebUIConnection.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ has 'worker_id'; # the ID the web UI uses to track this worker (populated on
has 'testpool_server'; # testpool server for this web UI host
has 'working_directory'; # share directory for this web UI host
has 'cache_directory'; # cache directory for this web UI host
has 'service_port_delta'; # delta from web UI port on which to directly connect to livehandler

# the websocket connection to receive commands from the web UI and send the status (Mojo::Transaction::WebSockets instance)
has 'websocket_connection';
Expand Down Expand Up @@ -106,6 +107,7 @@ sub register ($self) {
$self->_set_status($status => {error_message => $error_message});
return undef;
}
$self->service_port_delta($json_res->{service_port_delta});
my $worker_id = $json_res->{id};
$self->worker_id($worker_id);
if (!defined $worker_id) {
Expand Down
1 change: 1 addition & 0 deletions t/24-worker-engine.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use OpenQA::Utils qw(testcasedir productdir needledir locate_asset base_host);
use Mojo::Base -base;
has worker_id => 1;
has webui_host => 'localhost';
has service_port_delta => 2;
}

$ENV{OPENQA_CONFIG} = "$FindBin::Bin/data/24-worker-overall";
Expand Down
1 change: 1 addition & 0 deletions t/24-worker-jobs.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ sub wait_until_uploading_logs_and_assets_concluded {
package Test::FakeClient;
use Mojo::Base -base;
has worker_id => 1;
has service_port_delta => 2;
has webui_host => 'not relevant here';
has working_directory => 'not relevant here';
has testpool_server => 'not relevant here';
Expand Down
1 change: 1 addition & 0 deletions t/24-worker-overall.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $ENV{OPENQA_LOGFILE} = undef;
use Mojo::Base -base;
has webui_host => 'fake';
has worker_id => 42;
has service_port_delta => 2;
has api_calls => sub { [] };
sub send {
my ($self, $method, $path, %args) = @_;
Expand Down
3 changes: 3 additions & 0 deletions t/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ subtest 'Test configuration default modes' => sub {
# Test configuration generation with "test" mode
$test_config->{_openid_secret} = $config->{_openid_secret};
$test_config->{logging}->{level} = "debug";
$test_config->{global}->{service_port_delta} = 2;
is ref delete $config->{global}->{auto_clone_regex}, 'Regexp', 'auto_clone_regex parsed as regex';
is_deeply $config, $test_config, '"test" configuration';

Expand All @@ -188,6 +189,7 @@ subtest 'Test configuration default modes' => sub {
$app->mode("development");
$config = read_config($app, 'reading config from default with mode development');
$test_config->{_openid_secret} = $config->{_openid_secret};
$test_config->{global}->{service_port_delta} = 2;
delete $config->{global}->{auto_clone_regex};
is_deeply $config, $test_config, 'right "development" configuration';

Expand All @@ -197,6 +199,7 @@ subtest 'Test configuration default modes' => sub {
$config = read_config($app, 'reading config from default with mode foo_bar');
$test_config->{_openid_secret} = $config->{_openid_secret};
$test_config->{auth}->{method} = "OpenID";
$test_config->{global}->{service_port_delta} = 2;
delete $config->{global}->{auto_clone_regex};
delete $test_config->{logging};
is_deeply $config, $test_config, 'right default configuration';
Expand Down
2 changes: 1 addition & 1 deletion templates/webapi/developer/ws_console.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
%= include 'layouts/info'

<h2>WebSocket console for job <%= $job->name %></h2>
<form id="ws_console_form" data-url="<%= $ws_url %>" data-using-proxy="<%= $use_proxy ? 'true' : 'false' %>" action="#">
<form id="ws_console_form" data-url="<%= $ws_url %>" data-using-proxy="<%= $use_proxy ? 'true' : 'false' %>" data-service-port-delta="<%= $service_port_delta %>" action="#">
% if ($ws_url) {
<p>
% if ($use_proxy) {
Expand Down
1 change: 1 addition & 0 deletions templates/webapi/test/live.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
id="developer-panel"
data-developer-url="<%= $ws_developer_url %>"
data-status-only-url="<%= $ws_status_only_url %>"
data-service-port-delta="<%= $service_port_delta %>"
data-is-accessible="<%= ($is_devel_mode_accessible) ? ('true') : ('false') %>"
data-own-user-id="<%= $current_user_id %>">
<div class="card-header">
Expand Down

0 comments on commit 07543d2

Please sign in to comment.