Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Plugin/EmulateElastic/AddTemplateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function run(): Task {
throw new \Exception('Cannot parse request');
}
$patterns = json_encode($request['index_patterns']);
foreach (['index_patterns', 'settings', 'mappings'] as $removeProp) {
foreach (['index_patterns'] as $removeProp) {
if (!isset($request[$removeProp])) {
continue;
}
Expand Down
27 changes: 21 additions & 6 deletions src/Plugin/EmulateElastic/CatHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@

namespace Manticoresearch\Buddy\Base\Plugin\EmulateElastic;

use Manticoresearch\Buddy\Base\Lib\QueryProcessor;
use Manticoresearch\Buddy\Core\ManticoreSearch\Client as HTTPClient;
use Manticoresearch\Buddy\Core\Plugin\BaseHandlerWithClient;
use Manticoresearch\Buddy\Core\Task\Task;
use Manticoresearch\Buddy\Core\Task\TaskResult;

use RuntimeException;

/**
* Handling requests to extract and build info on Kibana entities, like templates, dashboards, etc.
*/
class CatHandler extends BaseHandlerWithClient {

const CAT_ENTITIES = ['templates'];
const CAT_ENTITIES = ['templates', 'plugins'];

/**
* Initialize the executor
Expand Down Expand Up @@ -58,11 +60,10 @@ public function run(): Task {

$catInfo = [];
foreach ($queryResult[0]['data'] as $entityInfo) {
$catInfo[] = [
'name' => $entityInfo['name'],
'order' => 0,
'index_patterns' => simdjson_decode($entityInfo['patterns'], true),
] + simdjson_decode($entityInfo['content'], true);
$catInfo[] = match ($entityTable) {
'_templates' => self::buildCatTemplateRow($entityInfo),
default => [],
};
}

return TaskResult::raw($catInfo);
Expand All @@ -72,4 +73,18 @@ public function run(): Task {
$taskFn, [$this->payload, $this->manticoreClient]
)->run();
}

/**
*
* @param array{name:string,patterns:string,content:string} $entityInfo
* @return array<string,mixed>
*/
private static function buildCatTemplateRow(array $entityInfo): array {
return [
'name' => $entityInfo['name'],
'order' => 0,
'index_patterns' => simdjson_decode($entityInfo['patterns'], true),
] + simdjson_decode($entityInfo['content'], true);
}

}
6 changes: 6 additions & 0 deletions src/Plugin/EmulateElastic/InitKibanaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Manticoresearch\Buddy\Base\Plugin\EmulateElastic;

use Manticoresearch\Buddy\Core\Error\GenericError;
use Manticoresearch\Buddy\Core\ManticoreSearch\Client as HTTPClient;
use Manticoresearch\Buddy\Core\Task\Task;
use Manticoresearch\Buddy\Core\Task\TaskResult;
Expand Down Expand Up @@ -65,6 +66,11 @@ public function run(): Task {
],
'status' => 404,
];
$customError = GenericError::create('', false);
$customError->setResponseErrorBody($resp);
$customError->setResponseErrorCode(404);

throw $customError;
} else {
$resp = [];
foreach ($queryResult[0]['data'] as $entity) {
Expand Down
4 changes: 3 additions & 1 deletion src/Plugin/EmulateElastic/NodesInfoKibanaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*/
class NodesInfoKibanaHandler extends BaseHandlerWithClient {

const DEFAULT_KIBANA_VERSION = '7.6.0';

/**
* Initialize the executor
*
Expand Down Expand Up @@ -58,7 +60,7 @@ public function run(): Task {
'publish_address' => "$ip:$port",
],
'ip' => $ip,
'version' => '7.6.0',
'version' => $settings->searchdKibanaVersionString ?? self::DEFAULT_KIBANA_VERSION,
],
],
]
Expand Down
25 changes: 14 additions & 11 deletions src/Plugin/EmulateElastic/Payload.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Manticoresearch\Buddy\Core\ManticoreSearch\Endpoint;
use Manticoresearch\Buddy\Core\Network\Request;
use Manticoresearch\Buddy\Core\Plugin\BasePayload;
use Manticoresearch\Buddy\Core\Tool\Buddy;

/**
* Prepares payload for Elastic-like queries and determines the appropriate handler for them
Expand All @@ -25,7 +26,7 @@ final class Payload extends BasePayload {

// Endpoint position in Kibana request path
const KIBANA_ENDPOINT_PATH_POS = [
0 => ['_aliases', '_alias', '_cat', '_field_caps', '_template'],
0 => ['_aliases', '_alias', '_cat', '_field_caps', '_template', '_index_template'],
1 => ['_create', '_doc', '_update', '_field_caps'],
];

Expand Down Expand Up @@ -72,6 +73,7 @@ public static function fromRequest(Request $request): static {
$pathParts = explode('/', ltrim($request->path, '/'));
$self->path = $request->path;
self::detectRequestTarget($pathParts, $self);
Buddy::debug(static::$requestTarget);
switch (static::$requestTarget) {
case '_cat':
case '_count':
Expand Down Expand Up @@ -107,6 +109,17 @@ public static function fromRequest(Request $request): static {
$self->table = static::$requestTarget;
$self->body = $request->payload;
break;
case '_index_template':
case '_template':
if ($request->httpMethod !== 'PUT') {
// Need this to avoid sending the 404 response for Elasticdump's requests which causes its failure
$customError = InvalidNetworkRequestError::create('', true);
$customError->setResponseErrorCode(200);
throw $customError;
}
$self->table = end($pathParts);
$self->body = $request->payload;
break;
case '_mapping':
/**
* @var array{
Expand All @@ -125,17 +138,7 @@ public static function fromRequest(Request $request): static {
$self->table = $pathParts[0];
$self->body = $request->payload;
break;
case '_template':
$self->table = end($pathParts);
$self->body = $request->payload;
break;
default:
if ($pathParts[0] === '_index_template') {
// Need this to avoid sending the 404 response for Elasticdump's requests which causes its failure
$customError = InvalidNetworkRequestError::create('', true);
$customError->setResponseErrorCode(200);
throw $customError;
}
throw new Exception("Unsupported request type in {$request->path}: " . static::$requestTarget);
}

Expand Down
Loading