solr-power icon indicating copy to clipboard operation
solr-power copied to clipboard

SolrPower_Api->get_server_info returns inaccurate server information

Open pavellishin opened this issue 6 years ago • 3 comments

https://github.com/pantheon-systems/solr-power/blob/master/includes/class-solrpower-api.php#L575-L584

get_server_info() assumes that the host name and port are the pantheon environmental variables, but it's possible to override the connection data via filters and constants.

(I'll try to get a PR out for this this week if I can.)

pavellishin avatar May 20 '19 13:05 pavellishin

(I'll try to get a PR out for this this week if I can.)

That'd be great, thanks!

danielbachhuber avatar May 20 '19 13:05 danielbachhuber

I know there's a PR for this right now, but since it hasn't been approved yet, here's another option to solve this:

    public function get_server_info() {
        $connection_options = apply_filters('s4wp_connection_options', [
            'endpoint' => [
                'localhost' => [
                    'host' => getenv( 'PANTHEON_INDEX_HOST' ),
                    'port' => getenv( 'PANTHEON_INDEX_PORT' ),
                    'path' => $this->compute_path()
                ]
            ]
        ]);

        $server_info = [
            'ping_status' => $this->ping_server(),
            'ip_address'  => $connection_options['endpoint']['localhost']['host'],
            'port'        => $connection_options['endpoint']['localhost']['port'],
            'path'        => $connection_options['endpoint']['localhost']['path'],
        ];

        return $server_info;

    }

fembuelita avatar Aug 01 '19 22:08 fembuelita

I was tinkering with code trying to get a slightly better understanding of things as well and one possible way is also by changing the function to something like:

public function get_server_info() {
	return array(
		'ping_status' => $this->ping_server(),
		'ip_address'  => $this->get_solr()->getEndpoint('localhost')->getHost(),
		'port'        => $this->get_solr()->getEndpoint('localhost')->getPort(),
		'path'        => $this->compute_path(),
	);
}

This would also mean changing the get_solr() function but that can be done like:

$host = getenv( 'PANTHEON_INDEX_HOST' ) ? getenv( 'PANTHEON_INDEX_HOST' ) : null;
$port = getenv( 'PANTHEON_INDEX_PORT' ) ? getenv( 'PANTHEON_INDEX_PORT' ) : null;

$solarium_config      = array(
	'endpoint' => array(
		'localhost' => array(
			'host'   => apply_filters( 'solr_power_hostname', $host ),
			'port'   => apply_filters( 'solr_power_port', $port ),
			'scheme' => $this->get_default_scheme(),
			'path'   => $this->compute_path(),
			'ssl'    => array(
				'local_cert' => self::get_cert_path(),
			),
		),
	),
);

Or just not have those *_power_(hostname|port) filters since it can be filtered with the s4wp_connection_options filter that is created here.

jocastaneda avatar May 26 '22 19:05 jocastaneda