Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch settings update #2827

Merged
merged 4 commits into from Mar 28, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Expand Up @@ -134,4 +134,6 @@ OSU_RUNNING_COST=
# ES_INDEX_PREFIX=
# ES_CLIENT_TIMEOUT=5
# ES_CLIENT_CONNECT_TIMEOUT=0.5
# ES_DEFAULT_SHARDS=1

SITE_SWITCHER_JS_HASH=
9 changes: 9 additions & 0 deletions app/Libraries/Elasticsearch/Search.php
Expand Up @@ -20,6 +20,7 @@

namespace App\Libraries\Elasticsearch;

use Datadog;
use Elasticsearch\Common\Exceptions\BadRequest400Exception;
use Elasticsearch\Common\Exceptions\Missing404Exception;
use Elasticsearch\Common\Exceptions\NoNodesAvailableException;
Expand Down Expand Up @@ -152,6 +153,14 @@ private function fetch()
$this->error = $e;
}

if (config('datadog-helper.enabled')) {
Datadog::increment(
config('datadog-helper.prefix_web').'.search.errors',
1,
['class' => get_class($error)]
);
}

return SearchResponse::failed();
}
}
21 changes: 11 additions & 10 deletions app/Traits/EsIndexable.php
Expand Up @@ -80,25 +80,26 @@ public function esIndexDocument(array $options = [])

public static function esCreateIndex(string $name = null)
{
$settings = [
'index' => [
'number_of_shards' => config('osu.elasticsearch.number_of_shards'),
],
];

if (method_exists(get_called_class(), 'esAnalysisSettings')) {
$settings['analysis'] = static::esAnalysisSettings();
}

$type = static::esType();
$body = [
'mappings' => [
$type => [
'properties' => static::esMappings(),
],
],
'settings' => $settings,
];

if (method_exists(get_called_class(), 'esAnalysisSettings')) {
$settings = [
'settings' => [
'analysis' => static::esAnalysisSettings(),
],
];

$body = array_merge($body, $settings);
}

$params = [
'index' => $name ?? static::esIndexName(),
'body' => $body,
Expand Down
10 changes: 8 additions & 2 deletions app/helpers.php
Expand Up @@ -141,15 +141,21 @@ function es_search($params)
$error = $e;
}

Log::debug($error);
if (config('datadog-helper.enabled')) {
Datadog::increment(
config('datadog-helper.prefix_web').'.search.errors',
1,
['class' => get_class($error)]
);
}

// default return on failure
return [
'hits' => [
'hits' => [],
'total' => 0,
],
'exception' => $error ?? null,
'exception' => $error,
];
}

Expand Down
1 change: 1 addition & 0 deletions config/osu.php
Expand Up @@ -34,6 +34,7 @@
'user_agent' => env('CLIENT_USER_AGENT', 'osu!'),
],
'elasticsearch' => [
'number_of_shards' => env('ES_DEFAULT_SHARDS', 1),
'prefix' => env('ES_INDEX_PREFIX'),
'index' => [
'wiki_pages' => env('ES_INDEX_PREFIX').'osu:wiki_pages_20171130',
Expand Down