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

Handle Elastica Transport errors #1465

Merged
merged 11 commits into from Jan 29, 2019
Merged

Handle Elastica Transport errors #1465

merged 11 commits into from Jan 29, 2019

Conversation

jandom
Copy link
Contributor

@jandom jandom commented Oct 28, 2018

This PR attempts to address problem described in ruflin/Elastica#1508

Transport errors don't throw exceptions but are handled by ruflin/Elastica, however FOSElasticaBundle was never checking if there was a transport error detected by ruflin/Elastica

This PR goes hand-in-hand with the PR here, which improves NullTransport in ruflin/Elastica

ruflin/Elastica#1529

@jandom
Copy link
Contributor Author

jandom commented Nov 4, 2018

Updated the repo to not point at my personal fork, tests should pass now

@jandom
Copy link
Contributor Author

jandom commented Nov 4, 2018

Hmm almost cleaned that up – any idea how to make php-5.6 tests to pass? do i have to back-port into the 5.x branch?

composer.json Outdated
@@ -19,7 +19,7 @@
"symfony/property-access": "^3.2|^4",
"pagerfanta/pagerfanta": "^1.0.5|^2.0",
"psr/log": "^1.0",
"ruflin/elastica": "^5.2.1|^6.0"
"ruflin/elastica": "dev-master"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would like to keep stable packages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely agreed, alas last release from ruflin/elastica is from waaay back

Release 6.0.2 @ruflin ruflin released this on May 29 · 8 commits to master since this release

See link for reference https://github.com/ruflin/Elastica/releases

And the commit that's needed for this PR, is a fairly recent one on master

ruflin/Elastica@d6f1475

I'm not sure what's the best way around this? ask ruflin to release a new version?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jandom Is a new release needed from master?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruflin nothing would make me more happy – but i'm not sure what your release cycle is like/don't want to bother if you're waiting for something else to merge in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruflin yeah let's have a new ruflin/Elastica release, if that's okay – it'll push this PR forward

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next week is totally appropriate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruflin super-gentle nudge if there are any updates on the new release of ruflin/Elastica?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the nudge ;-) Just opened the PR to prepare the release. Now I only need a review for it: ruflin/Elastica#1547

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yaaas thank you!

@@ -24,6 +24,8 @@
*/
class Client extends BaseClient
{
private $forbiddenHttpCodes = [403, 404, 400];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make this configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, let me implement this and add some tests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that by intercepting 404 you break various exists functions in Elastica which send HEAD requests and check for 200 vs 404 responses.

  • Elastica\Type::exists()
  • Elastica\Index::exists()
  • Elastica\IndexTemplate::exists()

Put in configuration instead of hard-coding in the Client class
Unit test the configuration
Defaults are 400, 403, 404
Refactor unit tests and mocks for the Client
if (isset($transportInfo['http_code']) && in_array($transportInfo['http_code'], $forbiddenHttpCodes, true)) {
$body = isset($transportInfo['body']) ? $transportInfo['body'] : 'blank';
$message = sprintf('Error in transportInfo: response code is %s, response body is %s', $transportInfo['http_code'], $body);
throw new \Exception($message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For debugging reasons we should throw a different exception. Maybe one of https://github.com/ruflin/Elastica/tree/master/lib/Elastica/Exception ? @ruflin ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM. The part I'm worried here is that this could be a breaking change in Elastica? Want to open a PR against Elastica to discuss it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the exception from the global Exception to ClientException, good point!

Gents, thank you both so much for your help and let me know if something more is needed

@XWB
Copy link
Member

XWB commented Dec 11, 2018

@jandom The latest changes are OK, but some tests are still failing:

Fatal error: Call to undefined method Elastica\Transport\NullTransport::setResponse() in /home/travis/build/FriendsOfSymfony/FOSElasticaBundle/tests/Unit/Elastica/ClientTest.php on line 38

@jandom
Copy link
Contributor Author

jandom commented Jan 13, 2019

Yeah, you're right – let me have a look

@jandom
Copy link
Contributor Author

jandom commented Jan 13, 2019

okay, i think i know what's going on – the test fail with the "prefer lowest" which causes the ruflin/elastica version 5.2.1 to be installed. The version obviously doesn't have the improvements I shipped – these are only present in the 6.x branch – I'd have to backport my changes into the other branch.

@XWB is that what has to get done to get this over the line?

@jandom
Copy link
Contributor Author

jandom commented Jan 13, 2019

Backported the changes to ruflin/Elastica 5.x branch – as far as I can tell this is the only way to get the CI green here

ruflin/Elastica#1592

@jandom
Copy link
Contributor Author

jandom commented Jan 22, 2019

Here is some discussion that lead to the latest commits ruflin/Elastica#1592

src/Elastica/Client.php Outdated Show resolved Hide resolved
@XWB
Copy link
Member

XWB commented Jan 25, 2019

@jandom PR looks good. If @ruflin is willing to make another release then we can bump the minimum Elastica dependency to 5.3.5.

@jandom
Copy link
Contributor Author

jandom commented Jan 26, 2019

@XWB awesome – thanks for guiding the process!

@ruflin if it's not a problem, we'll be all merry and dancing here as soon as the versions are bumped on Elastica master and 5.x branches ;-)

@ruflin
Copy link

ruflin commented Jan 28, 2019

As @thePanz handles mostly 5.x release I'll ping him here. On the master side I think we can to a 6.1.1 (@p365labs objects?).

@jandom I assume that would solve your issues here?

@jandom
Copy link
Contributor Author

jandom commented Jan 28, 2019

@ruflin thanks so much – yes that is correct!

@thePanz
Copy link

thePanz commented Jan 28, 2019

@jandom I prepared the changes for the new release v5.3.5. as soon as I'll get @ruflin OK, I'll tag it.
Get ready for your dances ;)

@jandom merged, and tagged 5.3.5. (nice gif 🤣 )

@jandom
Copy link
Contributor Author

jandom commented Jan 28, 2019

giphy

@ruflin
Copy link

ruflin commented Jan 29, 2019

Here you go with the 6.1.1 release: https://github.com/ruflin/Elastica/releases/tag/6.1.1

@jandom
Copy link
Contributor Author

jandom commented Jan 29, 2019

@ruflin thank you so much #SparklesOfJoy #HappyTimes

@jandom
Copy link
Contributor Author

jandom commented Jan 29, 2019

Updated the composer.json with the new dependency tags

@XWB XWB changed the title Issue/1508 aws credentials 403 errors Handle Elastic Transport errors Jan 29, 2019
@XWB XWB changed the title Handle Elastic Transport errors Handle Elastica Transport errors Jan 29, 2019
@XWB XWB merged commit 8b30ba6 into FriendsOfSymfony:master Jan 29, 2019
@XWB
Copy link
Member

XWB commented Jan 29, 2019

Thanks for all the effort guys :)

@jandom
Copy link
Contributor Author

jandom commented Jan 29, 2019

Wooohooo, thanks to @XWB for closing 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants