Skip to content

Commit

Permalink
Merge pull request #34 from BedrockStreaming/feat/add-codeowner-and-u…
Browse files Browse the repository at this point in the history
…pdate-ci

feat: add codeowner & use GHA for CI
  • Loading branch information
lnahiro committed Mar 14, 2022
2 parents 81dbf1c + 4d6c07e commit b11db95
Show file tree
Hide file tree
Showing 23 changed files with 153 additions and 214 deletions.
9 changes: 0 additions & 9 deletions .coke

This file was deleted.

1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @BedrockStreaming/cache-db
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Continuous Integration
on: [push, pull_request]

jobs:
tests:
name: Tests
runs-on: ubuntu-20.04
strategy:
matrix:
php-version: [ '7.4', '8.0', '8.1' ]
symfony-version: ['^4.4', '^5.0', '^5.3']
fail-fast: false
steps:
- uses: actions/checkout@master
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: xdebug2
extensions: apcu
ini-values: apc.enable_cli=1
- name: Install symfony version from matrix
env:
SYMFONY_VERSION: ${{ matrix.symfony-version }}
run: composer require symfony/symfony:$SYMFONY_VERSION --no-update
- name: Install dependencies
run: composer update --prefer-dist --no-interaction
- name: Unit tests
run: |-
vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --verbose
vendor/bin/atoum
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
vendor
composer.lock
.php-cs-fixer.cache
13 changes: 13 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(
[
__DIR__.'/src',
]
);

$config = new M6Web\CS\Config\BedrockStreaming();
$config->setFinder($finder);

return $config;
25 changes: 0 additions & 25 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# ElasticsearchBundle [![Build Status](https://travis-ci.org/M6Web/ElasticsearchBundle.png?branch=master)](https://travis-ci.org/M6Web/ElasticsearchBundle)
# ElasticsearchBundle [![Build Status](https://github.com/BedrockStreaming/ElasticsearchBundle/actions/workflows/ci.yml/badge.svg)](https://github.com/BedrockStreaming/ElasticsearchBundle/actions/workflows/ci.yml) [![Total Downloads](https://poser.pugx.org/m6web/elasticsearch-bundle/downloads.svg)](https://packagist.org/packages/m6web/elasticsearch-bundle) [![License](http://poser.pugx.org/m6web/elasticsearch-bundle/license)](https://packagist.org/packages/m6web/elasticsearch-bundle) [![PHP Version Require](http://poser.pugx.org/m6web/elasticsearch-bundle/require/php)](https://packagist.org/packages/m6web/elasticsearch-bundle)


Integration of the [Elasticsearch official PHP client](http://github.com/elasticsearch/elasticsearch-php) within a Symfony Project.

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.4",
"ext-json": "*",
"elasticsearch/elasticsearch": "^5.1.0||^6.0.0||^7.0"
},
"require-dev": {
"atoum/atoum": "^4.0",
"m6web/coke": "~1.2.0",
"m6web/symfony2-coding-standard": "~1.2.0",
"m6web/php-cs-fixer-config": "^2.0",
"symfony/dependency-injection": "^4.4||^5.0",
"symfony/event-dispatcher": "^4.4||^5.0",
"symfony/config": "^4.4||^5.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,18 @@ public function __construct()
$this->reset();
}


/**
* @param ElasticsearchEvent $event
*/
public function handleEvent(ElasticsearchEvent $event)
{
$query = array(
'method' => $event->getMethod(),
'uri' => $event->getUri(),
'headers' => $this->stringifyVariable($event->getHeaders()),
$query = [
'method' => $event->getMethod(),
'uri' => $event->getUri(),
'headers' => $this->stringifyVariable($event->getHeaders()),
'status_code' => $event->getStatusCode(),
'duration' => $event->getDuration(),
'took' => $event->getTook(),
'body' => json_decode($event->getBody()),
'error' => $event->getError(),
);
'duration' => $event->getDuration(),
'took' => $event->getTook(),
'body' => json_decode($event->getBody()),
'error' => $event->getError(),
];
$this->data['queries'][] = $query;
$this->data['total_execution_time'] += $query['duration'];
}
Expand Down Expand Up @@ -81,7 +77,7 @@ public function getTotalExecutionTime()
public function reset()
{
$this->data = [
'queries' => [],
'queries' => [],
'total_execution_time' => 0,
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getConfigTreeBuilder()
->performNoDeepMerging()
->prototype('scalar')->end()
->end()
//@deprecated
// @deprecated
->scalarNode('client_class')->defaultValue('Elasticsearch\Client')->end()
->scalarNode('clientBuilderClass')->defaultValue('Elasticsearch\ClientBuilder')->end()
->scalarNode('connectionPoolClass')->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace M6Web\Bundle\ElasticsearchBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
Expand Down Expand Up @@ -52,9 +52,8 @@ public function getAlias()
/**
* Add a new Elasticsearch client definition in the container
*
* @param ContainerBuilder $container
* @param string $name
* @param array $config
* @param string $name
* @param array $config
*/
protected function createElasticsearchClient(ContainerBuilder $container, $name, $config)
{
Expand All @@ -63,7 +62,7 @@ protected function createElasticsearchClient(ContainerBuilder $container, $name,
$handlerId = $this->createHandler($container, $config, $definitionId);

$clientConfig = [
'hosts' => $config['hosts'],
'hosts' => $config['hosts'],
'handler' => new Reference($handlerId),
];

Expand Down Expand Up @@ -101,16 +100,14 @@ protected function createElasticsearchClient(ContainerBuilder $container, $name,
/**
* Create request handler
*
* @param ContainerBuilder $container
* @param array $config
* @param string $definitionId
* @param string $definitionId
*
* @return string
*/
protected function createHandler(ContainerBuilder $container, array $config, $definitionId)
{
// cURL handler
$singleHandler = (new Definition('GuzzleHttp\Ring\Client\CurlHandler'))
$singleHandler = (new Definition('GuzzleHttp\Ring\Client\CurlHandler'))
->setPublic(false);

$this->setFactoryToDefinition('Elasticsearch\ClientBuilder', 'defaultHandler', $singleHandler);
Expand All @@ -131,7 +128,7 @@ protected function createHandler(ContainerBuilder $container, array $config, $de
$container->setDefinition($headersHandlerId, $headersHandler);

// Event handler
$eventHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\EventHandler'))
$eventHandler = (new Definition('M6Web\Bundle\ElasticsearchBundle\Handler\EventHandler'))
->setPublic(false)
->setArguments([new Reference('event_dispatcher'), new Reference($headersHandlerId)]);
$eventHandlerId = $definitionId.'.event_handler';
Expand All @@ -141,19 +138,15 @@ protected function createHandler(ContainerBuilder $container, array $config, $de
}

/**
* @param string $className
* @param string $method
* @param Definition $definition
* @param string $className
* @param string $method
*/
private function setFactoryToDefinition($className, $method, Definition $definition)
{
$definition
->setFactory([$className, $method]);
}

/**
* @param ContainerBuilder $container
*/
protected function createDataCollector(ContainerBuilder $container)
{
$collectorDefinition = new Definition(
Expand All @@ -163,15 +156,15 @@ protected function createDataCollector(ContainerBuilder $container)
'data_collector',
[
'template' => '@M6WebElasticsearch/Collector/elasticsearch.html.twig',
'id' => 'elasticsearch'
'id' => 'elasticsearch',
]
);

$collectorDefinition->addTag(
'kernel.event_listener',
[
'event' => 'm6web.elasticsearch',
'method' => 'handleEvent'
'method' => 'handleEvent',
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

/**
* Class RandomStickySelector
*
* @package M6Web\Bundle\ElasticsearchBundle\Elasticsearch\ConnectionPool\Selector
*/
class RandomStickySelector implements SelectorInterface
{
Expand All @@ -21,8 +19,6 @@ class RandomStickySelector implements SelectorInterface
* @param ConnectionInterface[] $connections Array of Connection objects
*
* @throws NoNodesAvailableException
*
* @return ConnectionInterface
*/
public function select($connections): ConnectionInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,13 @@
*
* > Extend StaticNoPingConnectionPool and add the ability to remove any failed connection
* from the list of eligible connections to be chosen from by the selector.
*
* @package M6Web\Bundle\ElasticsearchBundle\Elasticsearch\ConnectionPool
*/
class StaticAliveNoPingConnectionPool extends StaticNoPingConnectionPool
{
/**
* @var int
*/
private $pingTimeout = 60;
/** @var int */
private $pingTimeout = 60;

/**
* @var int
*/
/** @var int */
private $maxPingTimeout = 3600;

/**
Expand All @@ -51,6 +45,7 @@ public function setMaxPingTimeout($maxPingTimeout)
* @param bool $force
*
* @return Connection
*
* @throws \Elasticsearch\Common\Exceptions\NoNodesAvailableException
*/
public function nextConnection($force = false): ConnectionInterface
Expand Down Expand Up @@ -78,14 +73,12 @@ function ($baseConnection) use ($connection) {
);
}

throw new NoNodesAvailableException("No alive nodes found in your cluster");
throw new NoNodesAvailableException('No alive nodes found in your cluster');
}

/**
* > Same as parent private method.
*
* @param Connection $connection
*
* @return bool
*/
protected function readyToRevive(Connection $connection)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
<?php


namespace M6Web\Bundle\ElasticsearchBundle\EventDispatcher;


use Symfony\Contracts\EventDispatcher\Event;

/**
* Class ElasticsearchEvent
*
*/
class ElasticsearchEvent extends Event
{
/**
* @var float duration of the Elasticsearch request in milliseconds
*/
/** @var float duration of the Elasticsearch request in milliseconds */
private $duration;

/**
* @var string HTTP method
*/
/** @var string HTTP method */
private $method;

/**
* @var string Elasticsearch URI
*/
/** @var string Elasticsearch URI */
private $uri;

/**
* @var int HTTP status code
*/
/** @var int HTTP status code */
private $statusCode;

/**
Expand All @@ -39,9 +28,7 @@ class ElasticsearchEvent extends Event
*/
private $took;

/**
* @var array
*/
/** @var array */
private $headers;

/**
Expand All @@ -51,9 +38,7 @@ class ElasticsearchEvent extends Event
*/
private $body;

/**
* @var string
*/
/** @var string */
private $error;

/**
Expand Down

0 comments on commit b11db95

Please sign in to comment.