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

Adds deprecation logging to ScriptDocValues#getValues. #34279

Merged
merged 7 commits into from Nov 27, 2018

Conversation

j-haj
Copy link
Contributor

@j-haj j-haj commented Oct 3, 2018

First commit addressing issue #22919.

ScriptDocValues#getValues was added for backwards compatibility but no
longer needed. Scripts using the syntax doc.foo.values.bar should be
using doc.foo.bar instead.

rjernst
rjernst previously requested changes Oct 3, 2018
Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

Unfortunately this won't work as is. Due to scripts running with reduced permissions, the call to the logger needs to be wrapped with an AccessController.doPrivileged call. See the other deprecation examples in ScriptDocValues. We also need a test for this, preferably for each subclass.

@j-haj
Copy link
Contributor Author

j-haj commented Oct 3, 2018

Thanks for the fast response -- I will review the examples and update accordingly

@colings86 colings86 added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Oct 4, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@nik9000
Copy link
Member

nik9000 commented Oct 4, 2018

It is sneaky how it won't work too. For the most part it only fails when the log call happens to roll the log file.

@j-haj
Copy link
Contributor Author

j-haj commented Oct 4, 2018

Ok I've updated with an initial attempt at a fix. I think using the BiConsumer is a little awkward but it seemed clearer than using a standard Consumer and doing some currying to apply the log key to deprecatedAnMaybeLog.

I will think about how testing for each class in the meantime.

@nik9000
Copy link
Member

nik9000 commented Oct 5, 2018

The fix looks right to me. I agree on the BiConsumer being better here, at least with the field being call deprecationCallback.

@rjernst
Copy link
Member

rjernst commented Oct 14, 2018

I think what is still missing from here is a test for each doc value type.

@j-haj
Copy link
Contributor Author

j-haj commented Oct 14, 2018

@rjernst it is at the top of my todo list! Had some other items I had to take care of last week.

@j-haj
Copy link
Contributor Author

j-haj commented Oct 22, 2018

Two quick questions:

  1. Should I rebase this PR off of 6.4? My current branch is from master.
  2. What is the preferred style for final variables? I've seen both deprecationLogger and DEPRECATION_LOGGER, although DEPRECATION_LOGGER seems to be more popular and consistent with common Java style (although I am certainly far from an expert here)

Otherwise I hope to have an updated PR with tests in the next day or two. Again, sorry about the delay!

@rjernst
Copy link
Member

rjernst commented Oct 22, 2018

  • master is the correct branch. We do all PRs against there, and then backport as appropriate.
  • Final static variables should be in all uppercase, which all deprecation loggers that I know of are. Where have you seen it in camelCase (we should fix any such cases, separately from this PR)?

@jasontedor
Copy link
Member

Final static variables should be in all uppercase

If and only if they represent constants (e.g., a primitive type, or an immutable reference type like a String). For example, a private static final AtomicInteger representing a counter of foos should be named fooCounter, not FOO_COUNTER.

It's genuinely an interesting discussion point whether or not a deprecation logger represents a constant. I would say that it does not, since it is mutable internal state that is visible.

Given this, I would say the right name is deprecationLogger.

@j-haj
Copy link
Contributor Author

j-haj commented Oct 22, 2018

I count about 58 occurrences of deprecationLogger and about 96 DEPRECATION_LOGGER. This PR uses deprecationLogger - I'll leave it for now unless told to change it. If you all want, I can submit a separate issue to spark discussion.

@nik9000
Copy link
Member

nik9000 commented Oct 25, 2018

If you all want, I can submit a separate issue to spark discussion.

We just had the same discussion on another issue. So an issue sounds good to me!

@j-haj
Copy link
Contributor Author

j-haj commented Oct 25, 2018

@nik9000 Done. See #34872.

@nik9000
Copy link
Member

nik9000 commented Oct 25, 2018

@nik9000 Done. See #34872.

Thanks!

@j-haj j-haj force-pushed the issue-22919 branch 2 times, most recently from 970c3e1 to d643b9e Compare October 25, 2018 21:12
@j-haj
Copy link
Contributor Author

j-haj commented Oct 25, 2018

I've added an initial attempt at the tests. There are a few things I am unsure on:

  • I only found tests for the concrete classes Dates, Longs, and GeoPoints. However, there are additional concrete implementations which don't have any tests (e.g., Doubles and Boolean). Do we want to test all concrete types?
  • There are tests for ScriptDocValueDates in the 6.4 branch but not in master. I created the file and per @rjernst 's comment I figure we can handle the merge when the time comes.
  • There is a lot of duplicate code in the various concrete type tests. There must be a better way to approach this but it isn't obvious to me at the moment.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

Thanks for the tests! This looks good, except one nit about the deprecation message.

First commit addressing issue elastic#22919.

`ScriptDocValues#getValues` was added for backwards compatibility but no
longer needed. Scripts using the syntax `doc['foo'].values` when
`doc['foo']` is a list should be using `doc['foo']` instead.
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@nik9000
Copy link
Member

nik9000 commented Nov 2, 2018

@elasticmachine test this please.

@j-haj
Copy link
Contributor Author

j-haj commented Nov 8, 2018

I merged master into my branch but ./gradlew check is failing at TcpTransportTests#testCompressRequest. I am looking into the cause so I would hold off on rerunning the build.

@nik9000
Copy link
Member

nik9000 commented Nov 8, 2018

I am looking into the cause so I would hold off on rerunning the build.

I've seen this fail once or twice in our builds. I suspect it is flaky these past few days.

@j-haj
Copy link
Contributor Author

j-haj commented Nov 17, 2018

I have a few more updates I'll push hopefully by Sunday. I merged master again and that seemed to fix the TcpTransportTests errors -- it looks like all that is left is a few occurrences of .values in some of the Painless integration tests.

@nik9000
Copy link
Member

nik9000 commented Nov 19, 2018

Thanks for sticking with this @j-haj!

@j-haj
Copy link
Contributor Author

j-haj commented Nov 20, 2018

@nik9000 My pleasure! I'm seeing a few failures in the ZipClientYamlTestSuitIT integration tests that I am still tracking down.

@j-haj
Copy link
Contributor Author

j-haj commented Nov 26, 2018

I am still seeing some failures when I run gradlew check but am not convinced they are related to this change. The prior failures I was seeing are gone after merging in master.

@nik9000
Copy link
Member

nik9000 commented Nov 27, 2018

@j-haj, what are you seeing fail locally? Everything seems good in CI. I've pulled this locally and am running it on my side just to check.

@j-haj
Copy link
Contributor Author

j-haj commented Nov 27, 2018

@nik9000 I am seeing org.elasticsearch.indices.state.RareClusterStateIT.testDelayedMappingPropagationOnReplica fail locally along with the following slow tests:

org.elasticsearch.cluster.routing.PrimaryAllocationIT
org.elasticsearch.discovery.MasterDisruptionIT
org.elasticsearch.search.aggregations.bucket.MinDocCountIT
org.elasticsearch.discovery.DiscoveryDisruptionIT
org.elasticsearch.discovery.ClusterDisruptionIT

@nik9000
Copy link
Member

nik9000 commented Nov 27, 2018 via email

@j-haj
Copy link
Contributor Author

j-haj commented Nov 27, 2018

@nik9000 sounds great!

@nik9000 nik9000 merged commit 49087f1 into elastic:master Nov 27, 2018
nik9000 pushed a commit that referenced this pull request Nov 28, 2018
`ScriptDocValues#getValues` was added for backwards compatibility but no
longer needed. Scripts using the syntax `doc['foo'].values` when
`doc['foo']` is a list should be using `doc['foo']` instead.

Closes #22919
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Nov 28, 2018
* master:
  DOCS Audit event attributes in new format (elastic#35510)
  Scripting: Actually add joda time back to whitelist (elastic#35965)
  [DOCS] fix HLRC ILM doc misreferenced tag
  Add realm information for Authenticate API (elastic#35648)
  [ILM] add HLRC docs to remove-policy-from-index (elastic#35759)
  [Rollup] Update serialization version after backport
  [Rollup] Add more diagnostic stats to job (elastic#35471)
  Build: Fix gradle build for Mac OS (elastic#35968)
  Adds deprecation logging to ScriptDocValues#getValues. (elastic#34279)
  [Monitoring] Make Exporters Async (elastic#35765)
  [ILM] reduce time restriction on IndexLifecycleExplainResponse (elastic#35954)
  Remove use of AbstractComponent in xpack (elastic#35394)
  Deprecate types in search and multi search templates. (elastic#35669)
  Remove fromXContent from IndexUpgradeInfoResponse (elastic#35934)
@nik9000
Copy link
Member

nik9000 commented Nov 28, 2018

@j-haj, I've merged and backported to 6.x. Thanks so much for working on this!

@j-haj
Copy link
Contributor Author

j-haj commented Nov 28, 2018

@nik9000 Do we need a second PR that removes this functionality? If I recall correctly from the initial discussions, there were two steps: 1) add deprecation logging and 2) remove the methods altogether (or is this what you meant by "backported to 6.x"?).

@nik9000
Copy link
Member

nik9000 commented Nov 28, 2018

@j-haj, yes! We do need another PR to remove the functionality. By backporting to 6.x, I mean that I cherry-picked this change onto the 6.x branch, resolved the conflicts, ran the tests, and pushed it. That is what having the v6.6.0 tag here means. So, yes, we do still need the PR to remove the methods. Would you like to work on PR?

@j-haj
Copy link
Contributor Author

j-haj commented Nov 28, 2018

@nik9000 yes I will take on that PR if it's available. If there is no issue already I am happy to create one.

@rjernst
Copy link
Member

rjernst commented Nov 28, 2018

No need to create an issue. Just reference this PR and the original issue in the new PR.

@nik9000
Copy link
Member

nik9000 commented Nov 28, 2018

No need to create an issue. Just reference this PR and the original issue in the new PR.

Yeah! We build our release notes using the PRs rather than the issues.

nik9000 pushed a commit that referenced this pull request Dec 14, 2018
* Adds deprecation logging to ScriptDocValues#getValues.

First commit addressing issue #22919.

`ScriptDocValues#getValues` was added for backwards compatibility but no
longer needed. Scripts using the syntax `doc['foo'].values` when
`doc['foo']` is a list should be using `doc['foo']` instead.

* Fixes two build errors in #34279

* Removes unused import in ScriptDocValuesDatesTest
* Removes used of `.values` in example in diversified-sampler-aggregation.asciidoc

* Removes use of .values from painless test.

Part of #34279

* Updates tests to use `doc[foo]` syntax rather than `doc[foo].values`.

* Removes use of `getValues()` and replaces use of `doc[foo].values` with `doc[foo]`.

* Indentation fix.

* Remove unnecessary list construction at previous `getValues()` callsite in ScriptDocValues.GeoPoints.

* Update migration doc and add link to `getValue` in ScriptDocValues javadoc.

* Fix compile

* Fix javadoc issue

* Removes ScriptDocValues#getValues usage from painless whitelist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >deprecation v6.6.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants