Commit e2c68140 authored by Mark Chao's avatar Mark Chao

ES: Fix monkey patch not loaded

GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods is no
longer prepended to the proxies, thus the project’s _id is
incorrectly being set as “1” instead of “project_1". This means
joining would fail.

In the past, in config/initializers/elastic_client_setup.rb:

1. ES::Model::Indexing::InstanceMethods is included in
ES::Model::Proxy::InstanceMethodsProxy

2. Our monkey-patch is then prepended to
Elasticsearch::Model::Indexing::InstanceMethods

Since prepending happens later, our monkey patch would not be part of
ES::Model::Proxy::InstanceMethodsProxy's ancestor.

However it did work, by luck, because ES::Git::Model would
later include ES::Model, which would trigger the second
`include` call, and in turn add prepend modules into the ancestors.

But in previous commit, Elasticsearch::Git::Model is removed,
therefore the monkey patch was no longer included.
parent 38597665
......@@ -7,6 +7,17 @@ require 'gitlab/current_settings'
Gitlab.ee do
require 'elasticsearch/model'
### Monkey patches
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods
Elasticsearch::Model::Adapter::ActiveRecord::Importing.prepend GemExtensions::Elasticsearch::Model::Adapter::ActiveRecord::Importing
Elasticsearch::Model::Client::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model::Client::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model.singleton_class.prepend GemExtensions::Elasticsearch::Model::Client
### Modified from elasticsearch-model/lib/elasticsearch/model.rb
[
......@@ -32,15 +43,4 @@ Gitlab.ee do
target.respond_to?(:as_indexed_json) ? target.__send__(:as_indexed_json, options) : super
end
CODE
### Monkey patches
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods
Elasticsearch::Model::Adapter::ActiveRecord::Importing.prepend GemExtensions::Elasticsearch::Model::Adapter::ActiveRecord::Importing
Elasticsearch::Model::Client::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model::Client::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model::ClassMethods.prepend GemExtensions::Elasticsearch::Model::Client
Elasticsearch::Model.singleton_class.prepend GemExtensions::Elasticsearch::Model::Client
end
# frozen_string_literal: true
require 'spec_helper'
describe GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods do
describe '#index_document' do
let(:project) { Project.new(id: 1) }
it 'overrides _id with type being prepended' do
proxy = Elastic::Latest::ProjectInstanceProxy.new(project)
expect(proxy.client).to receive(:index).with(
index: 'gitlab-test',
type: 'doc',
id: 'project_1',
body: proxy.as_indexed_json
)
proxy.index_document
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment