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

Already on GitHub? Sign in to your account

Re-merge Elasticsearch branch #3179

Merged
merged 16 commits into from Nov 27, 2017

Conversation

Projects
None yet
8 participants
Owner

elzj commented Nov 22, 2017

Issue

https://otwarchive.atlassian.net/browse/AO3-4815 and others

Purpose

We had to back the code in progress out of master to address time-sensitive issues. This merges it all back together.

WendyBeth and others added some commits Oct 20, 2017

AO3-4815 Update Elasticsearch and filter interface (#3104)
* Upgrades faraday (ran bundle update elasticsearch)

* Adds elasticsearch-model to directly replace tire model

Uses rollout to indicate which module to include in the searchable modules

* Allows application to connect to two ES instances

* Switches version of ES in use by Indexer and Query depending on rollout feature

* Fixes feature failure in importing

The image is rendered with https://, not http://

* Adds awesome_print gem, to make inspecting json easier

* Adds class to recreate indices in upgraded ES instance & reindex from remote

* Removes elasticsearch-model

* Removes rollout code from models

* WIP - Making app compatible with ES 5.5

* WIP - Pulls in elasticsearch overhaul code

Starting to debug elasticsearch overhaul code, both in its incompatibilities
with current ES and its underlying bugs.

* Gets search/works_anonymous feature specs to pass with new ES code

* Gets search/works_tags features to pass with new es code

* Fixes search/works_info spec failures

* Fixes test failures in search/work_stats

* Updates ES version read by Travis

* Updates ES instance to point to the url Travis will recognize

* Fixes some failing feature specs for search

* Fixes admins/admin_works specs

* Fixes bookmark_create and collection_dashboard feature specs

* Fixes importing/archivist feature specs

* Fixes other_a/orphan_work feature specs

Still using Tire, and reindexing with both Tire and elasticsearch will not break
anything and will be useful when running the test suite twice against the two
different ES versions

* Fixes all other other_a feature failures

* Fixes works_anonymous feature failures

* Fixes tag_wrangling_relationships feature failures

* Fixes users feature failures

* Fixes works feature failures

* Adds the new ES indexing code wherever Tire is use in test setup

* Fixes works default rails actions spec failures

* Fixes elasticsearch_upgrade_spec failures and refactors ES refresh code

* Fixes work query spec

* Adds some minor refactoring to tests

* Adds bookmark indexing/query code & fixes associated tests

* Updates BookmarkSearch references to BookmarkSearchForm

* Fixes bookmark_create feature failures

* Fixes admin/admin_works feature failures

* Fixes bookmarks feature spec failures

* Fixes collections feature specs

* Fixes other_a and search failures

* Fixes users feature specs

* Removes refrences to tire from tests and specs for now

* Fixes search steps problem when reindexing models with any? false

* Fixes reindexing models without any records in specs

* Removes outdated use of WorkSearch model in works controller

* Fixes typo

* Fixes failing specs caused by fixes to failing features

* Fixes bugs in bookmark query

* Some feature failure cleanup

* Adds code for Tag search using updated ES

* Adds pseud search code

* Small test fixes

* Fixes some failing tests, and attempts to address Travis issues

* Adds fixes for Travis failures that are repeatable locally

* Fixes problem where bookmarks without works can't be searched for

* Reindexes indexes everywhere they are updated in the features directory

This should remove inconsistent, nearly-unrepeatable errors caused by the fact
that Elasticsearch is asynchronous. Yay!

* Fixes bookmark query spec failure

* Refactors some of the index updating logic in features

* Fixes default rails actions for works spec

* Isolates Tire reindexing to one file in features

* Fixes tags and wrangling test failures

* Distinguishes ES versions in specs

* Fixes some typos

* Updates to catch old ES version no matter the environment

* Attempting a run with old ES version

* Fixes Tire import

* Fixes spec helper method

* Separates ES wrappers based on ES version in controllers

* Fixes use of new ES code in helpers for use_old_search?

* Fixes old ES code usage in bookmarks controller

* Fixes search using old ES for bookmarks

* Removes tests that were catching a bug that is no longer a problem

* Fixes works failures for old es version

* Fixes features failing on Travis

* Fixes spec failures for old ES version

* Sets Travis to dl new version of ES to see how build does

* Attempt with ES 6.0 alpha

* Adds fix for bookmark deletion bug

* Adds missing details to work indexer

* Adds rollout to indexing

* Swaps out 'use_old_search?' with 'use_new_search?'

* Fixes param names in tests

* Adds rollout to application record use_new_search? method

* Fixes small details & removes unused code

* Fixes typo

* Fixes typo

* Fixes typo

* Fixes lack of question mark for rollout.active? method

* Runs Travis build on old ES and sets elasticsearch version with rollout

* Fixes inccorect method invocation

* Fixes incorrect method invocation in people controller

* Fixes works stats feature failures

* Adds fixes for failing specs

* Uses appropriate count method for old es version

* Removes debug line from feature

* Upgrades nokogiri due to security concern

* Makes it so app will respond appropriately to ES version

To run on Travis, all three ES urls need to be the same:
ENV['ELASTICSEARCH_URL'] &
ENV['ELASTICSEARCH_1_URL'] &
ENV['UPGRADED_ELASTICSEARCH_URL']

All need to point to the same thing. Whenever running an instance of the app
with two versions of ES, ENV['ELASTICSEARCH_URL'] and ENV['ELASTICSEARCH_1_URL']
need to point to the old version and ENV['UPGRADED_ELASTICSEARCH_URL'] needs to
point to the new version.

* Second attempt with 6.0.0-alpha1 ES

* For test with ES 6.0.0-alpha1

* Fixes Travis run in 6.0.0-alpha1 ES

* Untar

* Try starting both

* Simple test run

* Differentiate the builds

* Differentiate the builds

* Restore all the tests

* Fixes call to new elasticsearch api perform_request

* Updates to test suite to watch how upgraded es version works on its own

* refactors out index updating methods in feature specs

* Adds rollout specs

* Fixes bug in work search form object

* Matches config to travis

* Removes all but rspec tests from travis for now

* Sets up tests & rollout methods use expected behavior

* Fixes switch from string to text or keyword for index definitions

* Updates index definitions to be compatible with 6.0.0.beta2 ES version

* Changes localhost to home IP for old ES urls

* Does not require old es to work when old es is gone

* Switches ES bool queries to true/false

* Fixes spec failures for ES Group 1

* Adds specific test to ensure old elasticsearch does not index when it's not present

* Moves to new elasticsearch document indexing when old es is gone

* Fixes problem with helper method for specs

* Ensures app never attempts to reindex an old es index in the new es instance

* Makes it so that a user doesn't have to be present if use_new_search is 100% enabled

* Runs ES=1

* Runs ES=2

* Runs ES=3

* Runs ES=4

* Back to rspec

* Removes command to rebuild three times upon failure

* Updates set_rollout script to use global  variable

* Adds rollout definitions to test suite to see if that addresses Travis build problem

* Runs build with ES=1

* Runs all builds

* Adds same assurances to features as specs that ES will work w/ both versions

* Fixes imported image URL in feature spec

* Fixes reference to tire methods when tire is gone in feature support methods

* Runs only ES=4

* Moves es/rollout code for feature specs

* Fixes boolean representation in work search form

* Fixes boolean in ES search in bookmark search form

* Fixes bookmarks feature failures

* Fixes works_restricted feature failures

* Runs all four ES groups

* Runs ES=1 and ES=4

* Comments out test that's breaking due to third-party url bug

* Makes Travis only run 2 trials

1 - With the old Elasticsearch, in which we test that the old Elasticsearch
continues to work while start_new_indexing is true (individual tests also test
that the SearchForm classes continue to work as expected, meaning that the new
Elasticsearch also works in this case when use_new_search is true)

2 - With the new Elasticsearch

* Adds old exlclusion filter code

* Adds tests & code for work filtering with exclusion tags

* Addresses Travis test failures

* Adds bookmark exclusion filters

* Downgrades back to 5.6.1 (latest stable) ES version

* Adds single_mapping => true to ES indices

* Fixes failure to index bookmarks when they do not have a bookmarkable object

* Adds comments to help when removing old code

* Removes rollout manipulation from Travis

This was not actually setting features. All Travis needs to do is install one or
both versions of ES depending on the test group being run.

* Adds test cases for use_new_search? controller method

* Adds tests & fixes bugs for filtering

* Removes default 'true' from use_new_search method

Reverts old styles and scripts to master

* Fixes typos

* Fixes more typos

* Fixes rollout test for works controller

* Fixes works controller mistake

* Ports over ALL js and css changes that effect filters

* Removes useless method

* Removes file that has nothing to do with new search

* Fixes failing filter tests

* Pulls in fix for autocomplete bug from master

* AO3-4815: Fill out new batch indexing code

* Fixes merge clobbering of css & js files
AO3-4815: Add new ES to codeship script and use local.yml instead of … (
#3110)

* AO3-4815: Add new ES to codeship script and use local.yml instead of editing the regular config

* Fix ES download url and load local config when testing
AO3-5213 Index authors on works correctly for sorting (#3114)
AO3-5213 Index authors on works correctly for sorting
AO3-5207 Add StatCounterIndexer and fix order of reindexing. (#3111)
* AO3-5207 First go at StatCounter reindexing.

* AO3-5207 Add RSpec tests to make sure it works.

* AO3-5207 Small fixes to pass tests.

* AO3-5207 Make sure to call original when stubbing.

* AO3-5207 Finally fixed.
AO3-5209 Don't change the appearance of non-work & bookmark filters (#…
…3117)

* AO3-5209 Use old JavaScript and views for old Elasticsearch filters (styling fixes to come)

* AO3-5209 Restyle old filters

* AO3-5209 Ensure new work and bookmark filter styling does not conflict with exisiting collection filter styles
AO3-5216 Fix setting authenticity tokens when cached pages load (#3118)
This was the fix for AO3-5153, which got lost in a merge.
AO3-5208: Fix filtering behavior (#3113)
* AO3-5208: Fix filtering behavior by drilling down and setting facets appropriately.

* AO3-5208: Don't error when there are no filters

* AO3-5208: Ensure excluded tags are visible in filters

* AO3-5208: Make sure bookmark facet query knows about exclusions. Also don't index filters and other bookmarkable fields on the bookmark itself since that's what we're trying to avoid.

* AO3-5208: Dry up some tag-related query methods, reduce number of db requests, only exclude children of Character tags, and make exclusion work for bookmark tags again

* AO3-5208: Update some tests to match new behavior

* AO3-5208: Put excluded bookmark tags in the right filter bucket

* AO3-5208: Remove sub tag exclusion code, since the meta tag id is already indexed on works

* AO3-5208: Comment out tests for types of exclusion filtering we aren't currently doing for bookmarks

* AO3-5208: Enable querying on both parent and child bookmark fields and reflect queries in bookmark filters

* AO3-5208: Update tests for bookmark search syntax change and bookmarker indexing encompassing user name

* AO3-5208: Make 'other tags' filtering work for noncanonical tags as well

* AO3-5223: Fix id on bookmarks exclude field

* AO3-5208: Remove child exclusion from filters and enable inclusion for noncanonical tags

* AO3-5220 and AO3-5224: Fix searching bookmarks by notes and tag names and index bookmarkable date for sorting

* AO3-5220: Update old bookmark search code for notes fix, fix spacing in module
AO3-5225 Fix sidebar counts and scope by user id if a user is present (
…#3119)

* AO3-5225: Fix sidebar counts and scope by user id if a user is present

* AO3-5225: Update user dashboard feature to check counts in multiple places
end
- describe "when searching restricted works" do
+ describe '#search_results' do
@houndci-bot

houndci-bot Nov 22, 2017

Block has too many lines. [173/25]

+
+ # ES UPGRADE TRANSITION #
+ # Remove $rollout activation & unless block
+ $rollout.activate :start_new_indexing
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+ # Remove $rollout activation & unless block
+ $rollout.activate :start_new_indexing
+
+ unless elasticsearch_enabled?($elasticsearch)
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+ $rollout.activate :start_new_indexing
+
+ unless elasticsearch_enabled?($elasticsearch)
+ $rollout.activate :stop_old_indexing
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+
+ unless elasticsearch_enabled?($elasticsearch)
+ $rollout.activate :stop_old_indexing
+ $rollout.activate :use_new_search
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

- Bookmark.tire.index.delete
- Bookmark.create_elasticsearch_index
+ ['work', 'bookmark', 'pseud', 'tag'].each do |index|
@houndci-bot

houndci-bot Nov 22, 2017

Use %w or %W for an array of words.

+# ES UPGRADE TRANSITION #
+# Remove method
+def elasticsearch_enabled?(elasticsearch_instance)
+ elasticsearch_instance.cluster.health rescue nil
@houndci-bot

houndci-bot Nov 22, 2017

Avoid using rescue in its modifier form.

+# ES UPGRADE TRANSITION #
+# Remove method
+def deprecate_old_elasticsearch_test
+ deprecate_unless(elasticsearch_enabled?($elasticsearch)) do
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+def update_and_refresh_indexes(klass_name)
+ # ES UPGRADE TRANSITION #
+ # Remove block
+ if elasticsearch_enabled?($elasticsearch)
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+ indexer = indexer_class.new(klass_name.capitalize.constantize.all.pluck(:id))
+ indexer.index_documents if klass_name.capitalize.constantize.any?
+
+ $new_elasticsearch.indices.refresh(index: "ao3_test_#{klass_name}s")
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+end
+
+def refresh_index_without_updating(klass_name)
+ $new_elasticsearch.indices.refresh(index: "ao3_test_#{klass_name}s")
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+def delete_index(index)
+ # ES UPGRADE TRANSITION #
+ # Remove block
+ if elasticsearch_enabled?($elasticsearch)
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+
+ # NEW ES
+ index_name = "ao3_test_#{index}s"
+ if $new_elasticsearch.indices.exists? index: index_name
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+ # NEW ES
+ index_name = "ao3_test_#{index}s"
+ if $new_elasticsearch.indices.exists? index: index_name
+ $new_elasticsearch.indices.delete index: index_name
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+end
+
+def delete_test_indices
+ indices = $new_elasticsearch.indices.get_mapping.keys.select { |key| key.match("test") }
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

+def delete_test_indices
+ indices = $new_elasticsearch.indices.get_mapping.keys.select { |key| key.match("test") }
+ indices.each do |index|
+ $new_elasticsearch.indices.delete(index: index)
@houndci-bot

houndci-bot Nov 22, 2017

Do not introduce global variables.

Made a few comments and ignored a bunch of single quotes introduced by the changes for no good reason 🙈 - but the tests pass and I'm willing to believe that all is well since we already tested some of this, so I'm happy to approve if my comments/questions aren't relevant

- options.merge!(page: params[:page])
+ if params[:include_bookmark_search].present?
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

Would this be an opportunity to use safe navigation (i.e.: params[:include_bookmark_search]&.keys.each) or would that not work in this case? If it would - same for the next block too and the similar code in the WorkController. Just to save some lines of code...

- bookmarkable_type: {
- type: 'string',
- index: 'not_analyzed'
+ "properties" => {
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

I suppose this could use the new Ruby 1.9 syntax like the equivalent block in the Works indexer

}
},
- mappings: mapping
+ mappings: mapping,
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

Is this dangling comma okay in Ruby?

mapping do
indexes :id, index: :not_analyzed
- indexes :name, analyzer: 'snowball', boost: 100
+ indexes :name#, analyzer: 'snowball', boost: 100
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

I initially though the hash to comment out the snowball analyser was part of the name - maybe add a space so it's more obvious that it's starting a comment, or remove the commented out code altogether since this is the legacy code block anyway - though I'm not clear why we'd want to change it at this stage

- audio_ids = [70308] # Podfic
- art_ids = [7844, 125758] # Fanart, Arts
+ audio_ids = [70308, 1098169] # Podfic, Audio Content
+ art_ids = [7844, 125758, 3863] # Fanart, Arts
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

What is tag 3863?

+@no-txn @bookmarks @search
+Feature: Browse Bookmarks
+
+ Scenario: Bookmarks appear on both the user's bookmark page and on the bookmark page for the pseud they used create the bookmark
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

"they used to create the bookmark"

When I follow "first.fandom"
Then I should see "This tag belongs to the Fandom Category"
- When I am on the search tags page
+ # If this was a bug, it's fixed now?
@ariana-paris

ariana-paris Nov 23, 2017

Contributor

Maybe this is an opportunity to remove that?

Contributor

redsummernight commented Nov 23, 2017

Can you add 1414ade (#3126) to this PR? We missed it when making the ES branch.

elzj added some commits Nov 27, 2017

Merge branch 'AO3-5231-search-headers' into es_branch_2017
Seems to have been dropped in the rollback

@zz9pzza zz9pzza merged commit e2c284a into otwcode:master Nov 27, 2017

3 of 4 checks passed

codeclimate 98 issues to fix
Details
Scrutinizer 84 new issues, 170 updated code elements
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
hound 488 violations found.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment