1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-10 07:06:40 +02:00

ElasticSearch v8 support (#1662)

* ElasticSearch v8 support
* CI updates

Co-authored-by: Thomas Müller <mimmi20@live.de>
This commit is contained in:
Jordi Boggiano
2022-05-08 22:23:46 +02:00
committed by GitHub
parent 4c7a12b026
commit bd24765917
27 changed files with 510 additions and 197 deletions

View File

@@ -19,6 +19,9 @@ use Elastica\Client;
use Elastica\Request;
use Elastica\Response;
/**
* @group Elastica
*/
class ElasticaHandlerTest extends TestCase
{
/**
@@ -48,6 +51,13 @@ class ElasticaHandlerTest extends TestCase
->getMock();
}
public function tearDown(): void
{
parent::tearDown();
unset($this->client);
}
/**
* @covers Monolog\Handler\ElasticaHandler::write
* @covers Monolog\Handler\ElasticaHandler::handleBatch
@@ -155,60 +165,6 @@ class ElasticaHandlerTest extends TestCase
];
}
/**
* Integration test using localhost Elastic Search server version <7
*
* @covers Monolog\Handler\ElasticaHandler::__construct
* @covers Monolog\Handler\ElasticaHandler::handleBatch
* @covers Monolog\Handler\ElasticaHandler::bulkSend
* @covers Monolog\Handler\ElasticaHandler::getDefaultFormatter
*/
public function testHandleIntegration()
{
$msg = [
'level' => Logger::ERROR,
'level_name' => 'ERROR',
'channel' => 'meh',
'context' => ['foo' => 7, 'bar', 'class' => new \stdClass],
'datetime' => new \DateTimeImmutable("@0"),
'extra' => [],
'message' => 'log',
];
$expected = $msg;
$expected['datetime'] = $msg['datetime']->format(\DateTime::ISO8601);
$expected['context'] = [
'class' => '[object] (stdClass: {})',
'foo' => 7,
0 => 'bar',
];
$client = new Client();
$handler = new ElasticaHandler($client, $this->options);
try {
$handler->handleBatch([$msg]);
} catch (\RuntimeException $e) {
$this->markTestSkipped("Cannot connect to Elastic Search server on localhost");
}
// check document id from ES server response
$documentId = $this->getCreatedDocId($client->getLastResponse());
$this->assertNotEmpty($documentId, 'No elastic document id received');
// retrieve document source from ES and validate
$document = $this->getDocSourceFromElastic(
$client,
$this->options['index'],
$this->options['type'],
$documentId
);
$this->assertEquals($expected, $document);
// remove test index from ES
$client->request("/{$this->options['index']}", Request::DELETE);
}
/**
* Integration test using localhost Elastic Search server version 7+
*
@@ -237,7 +193,9 @@ class ElasticaHandlerTest extends TestCase
0 => 'bar',
];
$client = new Client();
$clientOpts = ['url' => 'http://elastic:changeme@127.0.0.1:9200'];
$client = new Client($clientOpts);
$handler = new ElasticaHandler($client, $this->options);
try {
@@ -271,9 +229,14 @@ class ElasticaHandlerTest extends TestCase
protected function getCreatedDocId(Response $response)
{
$data = $response->getData();
if (!empty($data['items'][0]['create']['_id'])) {
return $data['items'][0]['create']['_id'];
if (!empty($data['items'][0]['index']['_id'])) {
return $data['items'][0]['index']['_id'];
}
var_dump('Unexpected response: ', $data);
return null;
}
/**