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

Deprecate using "interval" configuration for date histograms aggregations #1874

Closed

Conversation

romainneutron
Copy link
Contributor

@romainneutron romainneutron commented Nov 23, 2020

The combined interval field has been deprecated in favor of fixed_interval or calendar_interval. See https://www.elastic.co/guide/en/elasticsearch/reference/7.2/search-aggregations-bucket-datehistogram-aggregation.html

Copy link
Collaborator

@deguif deguif left a comment

Choose a reason for hiding this comment

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

👍

src/QueryBuilder/DSL/Aggregation.php Show resolved Hide resolved
@deguif
Copy link
Collaborator

deguif commented Nov 23, 2020

Thanks @romainneutron
Would you be able to add a unit test to ensure deprecation is triggered? See https://github.com/ruflin/Elastica/blob/master/tests/IndexTest.php#L604 for example

@romainneutron romainneutron force-pushed the add-interval-deprecation branch 8 times, most recently from f8e4111 to 5b97e70 Compare November 23, 2020 12:05
@romainneutron romainneutron changed the title Deprecate using "interval" configuration for histograms aggregations Deprecate using "interval" configuration for date histograms aggregations Nov 23, 2020
@@ -7,10 +7,67 @@
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html
*/
class DateHistogram extends Histogram
class DateHistogram extends AbstractSimpleAggregation
Copy link
Collaborator

Choose a reason for hiding this comment

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

That would be a BC break.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought BC breaks were allowed

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sometimes but should not ;)
I think in this case, we can avoid it or I'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so, what should we do?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this be helpful (#1874 (comment)) to avoid changing the inheritance?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok I think I got the point.
DateHistogram interval parameter is deprecated but still useful for Histogram.
Can you confirm it's what you're addressing by changing the inheritance chain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes. We could move methods if we want to keep those implementation.
Maintaining BC on interfaces and userland API yes, but should we maintain BC on abstract internal classes?

Comment on lines 21 to 27
$this->_checkVersion('7.2');

$agg = new DateHistogram('hist', 'created');
$agg->setFixedInterval('1h');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$this->_checkVersion('7.2');
$agg = new DateHistogram('hist', 'created');
$agg->setFixedInterval('1h');
$version = $this->_getVersion();
if (\version_compare($version, '7.2') < 0) {
$this->expectDeprecation('Since ruflin/elastica 7.1.0: The "Elastica\Aggregation\DateHistogram::setInterval()" method is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.');
$agg = (new DateHistogram('hist', 'created'))
->setInterval('1h')
;
} else {
$agg = (new DateHistogram('hist', 'created'))
->setFixedInterval('1h')
;
}

Cannot we use a code like this to test on version lower than 7.2?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
$this->_checkVersion('7.2');
$agg = new DateHistogram('hist', 'created');
$agg->setFixedInterval('1h');
$version = $this->_getVersion();
if (\version_compare($version, '7.2') < 0) {
$agg = (new DateHistogram('hist', 'created'))
->setParam('interval', '1h')
;
} else {
$agg = (new DateHistogram('hist', 'created'))
->setFixedInterval('1h')
;
}

Or like this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe the deprecation is a little too violent, as this can't be fixed for versions lower than 7.2 unless using setParam() directly? WDYT @ruflin @thePanz ? Is there any advices/hints for this kind of deprecations?

Not sure if it's a blocker as the deprecation is also very helpful for upper compatibility.

@romainneutron romainneutron force-pushed the add-interval-deprecation branch 2 times, most recently from 2747dac to 4fcbfe1 Compare November 23, 2020 18:26
@romainneutron
Copy link
Contributor Author

PR udpated.
I dont think we should consider still consider using Histogram as base for DateHistogram. They're both histogram but differ on some of their behavior.

@romainneutron romainneutron force-pushed the add-interval-deprecation branch 2 times, most recently from 785d5bc to 2831bd5 Compare November 23, 2020 18:35
@ruflin
Copy link
Owner

ruflin commented Nov 25, 2020

If understand it there are 2 things here:

  • Changing the inheritance of DateHistogram
  • Deprecating interval

We need the first one to only deprecate interval for DateHistogram?

It seems the current code change is backward compatible expect in the case someone checked for specifically inherited classes? Is there more the could break users code?

@romainneutron
Copy link
Contributor Author

PR rebased

@ruflin
Copy link
Owner

ruflin commented Dec 8, 2020

Seems like one of the tests fail because of the deprecation :-) Can you fix it and also rebased the changelog?

@romainneutron
Copy link
Contributor Author

PR rebased, tests are green :)

@ruflin ruflin requested a review from deguif December 10, 2020 13:53
@ruflin
Copy link
Owner

ruflin commented Dec 14, 2020

I'll refer to @deguif on the final 👍 as he had the most interactions here.

@romainneutron
Copy link
Contributor Author

any news?

@ruflin
Copy link
Owner

ruflin commented Jan 4, 2021

@deguif Any chance to have a quick look?

$this->setField($field);

if (null !== $interval) {
trigger_deprecation('ruflin/elastica', '7.1.0', 'Argument 3 passed to "%s()" is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
trigger_deprecation('ruflin/elastica', '7.1.0', 'Argument 3 passed to "%s()" is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__);
trigger_deprecation('ruflin/elastica', '7.1.0', 'Argument 3 passed to "%s()" is deprecated, use "setFixedInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__);

@@ -46,9 +46,12 @@ public function testToArray(): void
*/
public function testMaxAggregation(): void
{
$this->_checkVersion('7.2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cannot we do the same you've done later for DateHistogramTest::testDateHistogramAggregation(), I mean checking the version of elasticsearch and using setInterval() or setFixedInterval() depending the version?

@@ -45,9 +45,12 @@ public function testToArray(): void
*/
public function testMaxAggregation(): void
{
$this->_checkVersion('7.2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here:

Cannot we do the same you've done later for DateHistogramTest::testDateHistogramAggregation(), I mean checking the version of elasticsearch and using setInterval() or setFixedInterval() depending the version?

@@ -20,7 +20,10 @@ class SerialDiffTest extends BaseAggregationTest
*/
public function testSerialDiffAggregation(): void
{
$dateHistogramAggregation = new DateHistogram('measurements', 'measured_at', 'hour');
$this->_checkVersion('7.2');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here:

Cannot we do the same you've done later for DateHistogramTest::testDateHistogramAggregation(), I mean checking the version of elasticsearch and using setInterval() or setFixedInterval() depending the version?

*
* @return $this
*/
public function setOrder(string $order, string $direction): self
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems it can also be a multi-dimensional array?
Like this:

"order": [ { "rock>playback_stats.avg": "desc" }, { "_count": "desc" } ]

*/
public function setInterval($interval): self
{
trigger_deprecation('ruflin/elastica', '7.1.0', 'The "%s()" method is deprecated, use "setDateInterval()" or "setCalendarInterval()" instead. It will be removed in 8.0.', __METHOD__);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm dubious about this deprecation, as interval parameter is still legit for ES version lower than 7.2. It was only deprecated in 7.2 version but is still supported (until at least 8.0).

I think we should remove the deprecation here. But I would let the deprecation in the constructor so that users would be required to update their code to explicitly call setInterval(), setFixedInterval() or setCalendarInterval().

Later when bumping minimum version of ES to a version later than 7.2 (probably when bumping to 8.0) we should be able to drop this method and only let the two others.

Would that make sense? ping @ruflin @thePanz

Copy link
Owner

Choose a reason for hiding this comment

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

There are two different deprecations:

  • Deprecation in Elasticsearch
  • Deprecation in Elastica

In the best case, they are aligned. As Elastica lags behind in releases, we kind of have the option to deprecate things already in older releases, assuming there is already an option available which is not deprecated.

To remove a method in 8.0, we should have it deprecated already in 7.x. I would say the earlier we can tell devs to adjust their code the better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes but that means in this case, that users of version older than 7.2 will get this deprecation but won't be able to remove the deprecation as the parameters (setFixedInterval, setCalendarInterval) can't work with their ES version. But maybe that's not an issue.

Copy link
Owner

Choose a reason for hiding this comment

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

I see. Maybe we can leave in a note in the docs for this. In general it would be great if we can push users to use the newest version of Elastica and the related version of Elasticsearch and would optimise for this. Maybe we could even adjust the README that this version of Elastica is supported for Elasticsearch >= 7.3 or similar. It does not mean, it will not work anymore with the older versions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would add the PHP Doc to the methods, stating that those are not supported by ES >= 8.x
When the library will support ES v8.x only, we can remove those methods.
WDYT?

Copy link
Owner

Choose a reason for hiding this comment

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

No strong preference on my end. SGTM

@VincentLanglet
Copy link
Contributor

This #2099 could be a simpler way to do it, isn't it ?

@thePanz
Copy link
Collaborator

thePanz commented Aug 2, 2022

Fixed in #2099

@thePanz thePanz closed this Aug 2, 2022
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