Open hussain-t opened 2 weeks ago
Hey @hussain-t, reviewing these AC has made me reconsider the endpoint name. I'd suggest a preferable name would be fpm-server-requirement-status
so we can GET fpm-server-requirement-status
which would be more aligned with the general RESTful approach with the HTTP verb and resource name making semantic sense.
I'd also suggest that it should directly return the is_fpm_health_check_failed
and is_script_access_disabled
properties, that way we can update the client-side state with them directly rather than needing to make another request to the settings endpoint when we call this one.
There's also the outstanding question of whether we actually rename is_fpm_health_check_failed
and is_script_access_disabled
as per https://github.com/google/site-kit-wp/issues/9625#issuecomment-2462850044.
Thanks, @techanvil! Overall, I agree with your suggestions, renaming the properties and the endpoint to fpm-server-requirement-status
to make it clearer. I’d suggest keeping it as a POST
since the endpoint performs checks and updates the server-side properties, even though it’s not directly taking data from the client. Let me know if that works!
Thanks for the suggestions, @techanvil 👍
Thanks @hussain-t, a fair point about the use of POST
. I think it could go either way but I'm happy enough keeping it a POST
.
Thanks, @techanvil. After giving it some more thought, I think a GET
request might suit this endpoint better, given that it retrieves the current server status without taking input from the client.
Thanks @hussain-t. SGTM too, let's go with the GET
, then.
Thanks for updating the AC, @hussain-t. I've noticed there's one additional aspect that could use clarifying and potentially updating.
- Direct PHP Script Access Check: A test should confirm whether the server can directly access PHP files within the wp-content/plugins directory.
As per my comment on the design doc, I'd like to clarify the intention here, essentially I would advise making an HTTP request to check the script accessibility rather than a local filesystem level check, if that's not already the plan.
Thanks, @techanvil. I've updated the AC accordingly.
Thanks @hussain-t!
AC ✅
Hi @techanvil, I’ve updated the AC to include the full URL for the /healthy
endpoint (e.g., https://G-1234.fps.goog/mpath/healthy).
Thanks, @techanvil. The IB LGTM! I've slightly bumped the estimate up to 15.
IB ✅
isFPMHealthy
and isScriptAccessEnabled
properties are true in the response. The isEnabled
property is expected to remain null.googlesitekit_first_party_mode
option is set in the DB with the properties defined as above.QA:eng
to test remaining QAB.
Feature Description
Develop a new
fpm-server-requirement-status
API endpoint within the First-party mode infrastructure to verify connectivity to the FPFE/healthy
endpoint and check direct PHP script access to thewp-content/plugins
. This endpoint should assess whether the WordPress server can support First-party mode by performing the necessary checks.See
fpm-server-requirement-status
from the REST API Controller and Health Check for First-Party Frontend sections for more details.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
GET
REST API endpointfpm-server-requirement-status
should be created in theREST_First_Party_Mode_Settings_Controller
class within the First-party mode infrastructure.fpm-server-requirement-status
endpoint should perform the following checks:/healthy
endpoint (e.g., https://g-1234.fps.goog/mpath/healthy) to verify that the server can make outbound requests required for First-party mode. The endpoint should expect a200
status response with “ok” to confirm successful connectivity.wp-content/plugins/google-site-kit/fpm
directory.googlesitekit_first_party_mode
settings object based on the checks:isFPMHealthy
: Set totrue
if the FPFE health check passes; otherwise, set tofalse
.isScriptAccessEnabled
: Set totrue
if the HTTP request to the PHP script is successful; otherwise, set tofalse
.isFPMHealthy
andisScriptAccessEnabled
to allow the client to update the state directly.Implementation Brief
{plugin root}/fpm/measurement.php
file.healthCheck
query parameter and returnok
if the query parameter is present. If not, it can return an empty response.REST_Route
in theREST_First_Party_Mode_Settings_Controller::get_rest_routes()
method (added via https://github.com/google/site-kit-wp/issues/9625), with the following configuration:core/site/data/fpm-server-requirement-status
WP_REST_Server::READABLE
Permissions::MANAGE_OPTIONS
$is_fpm_healthy
:file_get_contents()
to fetch the contents ofhttps://g-1234.fps.goog/mpath/healthy
.'ok'
, and the response code is200
, set$is_fpm_healthy
totrue
. Otherwise, set it tofalse
.$http_response_header
variable which will be set locally after thefile_get_contents()
call.$is_script_access_enabled
:file_get_contents()
to fetch the contents ofplugins_url( 'fpm/measurement.php', GOOGLESITEKIT_PLUGIN_MAIN_FILE )
with thehealthCheck
query parameter set to a truthy value.'ok'
and the response code is200
, set$is_script_access_enabled
totrue
. Otherwise, set it tofalse
.$is_fpm_healthy
and$is_script_access_enabled
into the FPM settings asisFPMHealthy
andisScriptAccessEnabled
using theFirst_Party_Mode_Settings::merge()
method.isFPMHealthy
andisScriptAccessEnabled
properties.Test Coverage
QA Brief
Happy path
firstPartyMode
feature flag enabled.fpm-server-requirement-status
endpoint:isFPMHealthy
andisScriptAccessEnabled
properties aretrue
in the response. TheisEnabled
property is expected to remainnull
.googlesitekit_first_party_mode
option is set in the DB with the properties defined as above.Unhappy paths
QA:Eng
Note that when testing on a local development environment, the
measurement.php
health check will work for a Local WP install, but it won't work for a WP Local Docker installation, this is because the hostname won't resolve to the correct IP address within the Docker container.The easiest way to test the unhappy path scenarios is to manually modify the requested URLs in
REST_First_Party_Mode_Controller
. However it's also possible to test them by proxying the calls made byfile_get_contents()
. To do this, create a file inmu-plugins
with the following content:Follow the happy path test, but modify the requested URLs or use a proxy to intercept the calls and verify the
isFPMHealthy
andisScriptAccessEnabled
properties are set tofalse
under various erroneous conditions.Changelog entry
fpm-server-requirement-status
API endpoint to verify First-Party Mode readiness by performing FPFE health checks and verifying direct PHP script access.