10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.25k stars 311 forks source link

Apply ElasticPress filters to the requests in status and stats CLI commands #3928

Open edpittol opened 4 months ago

edpittol commented 4 months ago

Is your enhancement related to a problem? Please describe.

The request to the _recovery endpoint in the CLI status command and to _stats in stats are not executed in the ElasticPress\Elasticsearch::remote_request method.

In my context, I am using the ep_pre_request_args hook to add the sslverify argument to false to the Opensearch service in my local environment. As the request is made from the wp_remote_get function, the hook call is not made in this case.

Designs

No response

Describe alternatives you've considered

I changed the line to run with ElasticPress\Elasticsearch::remote_request and it works in my context.

Status

$request = Elasticsearch::factory()->remote_request( $index_names_imploded . '/_recovery/?pretty' );
$ wp elasticpress status
====== Status ======
{
  ".plugins-ml-config" : {
    "shards" : [
      {
        "id" : 0,
        "type" : "EMPTY_STORE",
        "stage" : "DONE",
        "primary" : true,
        "start_time_in_millis" : 1717684688893,
...
Complete output

``` ====== Status ====== { ".plugins-ml-config" : { "shards" : [ { "id" : 0, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717684688893, "stop_time_in_millis" : 1717684688993, "total_time_in_millis" : 99, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 42, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 35 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } } ] }, ".opensearch-observability" : { "shards" : [ { "id" : 0, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717684679247, "stop_time_in_millis" : 1717684679508, "total_time_in_millis" : 260, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 81, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 122 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } } ] }, "examplecomwp-post-1" : { "shards" : [ { "id" : 0, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717685318138, "stop_time_in_millis" : 1717685318215, "total_time_in_millis" : 77, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 44, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 23 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } }, { "id" : 1, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717685318147, "stop_time_in_millis" : 1717685318228, "total_time_in_millis" : 80, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 45, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 24 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } }, { "id" : 2, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717685318157, "stop_time_in_millis" : 1717685318246, "total_time_in_millis" : 88, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 44, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 32 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } }, { "id" : 3, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717685318168, "stop_time_in_millis" : 1717685318260, "total_time_in_millis" : 91, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 50, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 30 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } }, { "id" : 4, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717685318315, "stop_time_in_millis" : 1717685318372, "total_time_in_millis" : 57, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 30, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 14 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } } ] }, "security-auditlog-2024.06.06" : { "shards" : [ { "id" : 0, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717685013609, "stop_time_in_millis" : 1717685013675, "total_time_in_millis" : 66, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 31, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 20 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } } ] }, ".opendistro_security" : { "shards" : [ { "id" : 0, "type" : "EMPTY_STORE", "stage" : "DONE", "primary" : true, "start_time_in_millis" : 1717684679943, "stop_time_in_millis" : 1717684680025, "total_time_in_millis" : 81, "source" : { }, "target" : { "id" : "Qcb3vlTNQpaGmXpY9l8AoQ", "host" : "192.168.48.2", "transport_address" : "192.168.48.2:9300", "ip" : "192.168.48.2", "name" : "d6560c4dfeb3" }, "index" : { "size" : { "total_in_bytes" : 0, "reused_in_bytes" : 0, "recovered_in_bytes" : 0, "percent" : "0.0%" }, "files" : { "total" : 0, "reused" : 0, "recovered" : 0, "percent" : "0.0%" }, "total_time_in_millis" : 38, "source_throttle_time_in_millis" : 0, "target_throttle_time_in_millis" : 0 }, "translog" : { "recovered" : 0, "total" : 0, "percent" : "100.0%", "total_on_start" : 0, "total_time_in_millis" : 27 }, "verify_index" : { "check_index_time_in_millis" : 0, "total_time_in_millis" : 0 } } ] } } ====== End Status ====== ```

Stats

$request = Elasticsearch::factory()->remote_request( $index_names_imploded . '/_stats/?pretty' );
$ wp elasticpress stats
====== Stats for: localhostwp-post-1 ======
Documents:  871
Index Size: 609,44 KB
Index Size (including replicas): 609,44 KB
====== End Stats ======

I believe that this solution was designed this way because some part of ElasticPress\Elasticsearch::remote_request cannot be executed. that's right, the solution might be add this method's filter hooks to these requests.

Code of Conduct

felipeelia commented 4 months ago

Hi @edpittol, thank you very much for opening the issue (always good to see familiar faces around!) Would you mind opening a PR changing those wp_remote_get calls to Elasticsearch::remote_request? Thanks!

edpittol commented 3 months ago

It will be a pleasure to contribute a little more. I spent a time setting up the environment to run the tests. My expectation is to open the PR in a few days.