Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def after_audit
index_name "activities"
end

settings index: {
number_of_shards: ENV["NUMBER_OF_SHARDS_ACTIVITY"].to_i,
}

mapping dynamic: "false" do
indexes :id, type: :keyword
indexes :auditable_id, type: :keyword
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/indexable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ def create_template
elsif name == "OtherDoi"
{
index_patterns: ["#{alias_name}*"],
settings: Doi.settings.to_hash,
settings: settings.to_hash,
mappings: Doi.mappings.to_hash,
}
else
Expand Down
4 changes: 4 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ class Event < ApplicationRecord
index_name "events"
end

settings index: {
number_of_shards: ENV["NUMBER_OF_SHARDS_EVENT"].to_i,
}

mapping dynamic: "false" do
indexes :uuid, type: :keyword
indexes :subj_id, type: :keyword
Expand Down
4 changes: 4 additions & 0 deletions app/models/other_doi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ class OtherDoi < Doi
index_name "dois-other"
end

settings index: Doi.settings.to_hash.fetch(:index, {}).merge(
number_of_shards: ENV["NUMBER_OF_SHARDS_OTHER_DOI"].to_i,
)

def client_id=(_value)
write_attribute(:datacentre, 0)
end
Expand Down
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
ENV["ES_PORT"] ||= "80"
ENV["ES_PREFIX"] ||= ""
ENV["NUMBER_OF_SHARDS_DATACITE_DOI"] ||= "5"
ENV["NUMBER_OF_SHARDS_OTHER_DOI"] ||= "5"
ENV["NUMBER_OF_SHARDS_EVENT"] ||= "5"
ENV["NUMBER_OF_SHARDS_ACTIVITY"] ||= "5"
ENV["TRUSTED_IP"] ||= "10.0.40.1"
ENV["MG_FROM"] ||= "support@datacite.org"
ENV["MG_DOMAIN"] ||= "mg.datacite.org"
Expand Down
32 changes: 32 additions & 0 deletions spec/models/activity_shard_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require "rails_helper"

describe "Activity number_of_shards" do
it "defaults to 5 on Activity settings" do
expect(ENV.fetch("NUMBER_OF_SHARDS_ACTIVITY")).to eq("5")
expect(Activity.settings.to_hash.dig(:index, :number_of_shards)).to eq(5)
end

it "does not apply the Activity shard setting to shared Doi settings" do
expect(Doi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
expect(Activity.settings).not_to equal(Event.settings)
expect(Activity.settings).not_to equal(Doi.settings)
expect(Activity.mappings.to_hash[:properties]).to be_present
end

it "uses Activity.settings when building the Activity template" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(Activity.index_name)
expect(args[:body][:index_patterns]).to eq(["#{Activity.index_name}*"])
expect(args[:body][:settings]).to eq(Activity.settings.to_hash)
expect(args[:body][:settings][:index][:number_of_shards]).to eq(5)
expect(args[:body][:mappings]).to eq(Activity.mappings.to_hash)
{ "acknowledged" => true }
end

Activity.create_template
end
end
13 changes: 8 additions & 5 deletions spec/models/datacite_doi_shard_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
expect(DataciteDoi.settings.to_hash.dig(:index, :number_of_shards)).to eq(5)
end

it "does not apply the shard setting to OtherDoi or shared Doi settings" do
it "does not apply the Datacite shard setting to shared Doi settings" do
expect(Doi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
expect(OtherDoi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
expect(DataciteDoi.settings).not_to equal(Doi.settings)
end

it "uses DataciteDoi.settings when building the Datacite template" do
Expand All @@ -29,14 +29,17 @@
DataciteDoi.create_template
end

it "keeps OtherDoi templates free of the Datacite shard setting" do
it "keeps OtherDoi templates on OtherDoi settings, not shared Doi settings" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(OtherDoi.index_name)
expect(args[:body][:index_patterns]).to eq(["#{OtherDoi.index_name}*"])
expect(args[:body][:settings]).to eq(Doi.settings.to_hash)
expect(args[:body][:settings].dig(:index, :number_of_shards)).to be_nil
expect(args[:body][:settings]).to eq(OtherDoi.settings.to_hash)
expect(args[:body][:settings][:index][:number_of_shards]).to eq(
ENV.fetch("NUMBER_OF_SHARDS_OTHER_DOI").to_i,
)
expect(Doi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
{ "acknowledged" => true }
end

Expand Down
32 changes: 32 additions & 0 deletions spec/models/event_shard_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require "rails_helper"

describe "Event number_of_shards" do
it "defaults to 5 on Event settings" do
expect(ENV.fetch("NUMBER_OF_SHARDS_EVENT")).to eq("5")
expect(Event.settings.to_hash.dig(:index, :number_of_shards)).to eq(5)
end

it "does not apply the Event shard setting to shared Doi settings" do
expect(Doi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
expect(Event.settings).not_to equal(Activity.settings)
expect(Event.settings).not_to equal(Doi.settings)
expect(Event.mappings.to_hash[:properties]).to be_present
end

it "uses Event.settings when building the Event template" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(Event.index_name)
expect(args[:body][:index_patterns]).to eq(["#{Event.index_name}*"])
expect(args[:body][:settings]).to eq(Event.settings.to_hash)
expect(args[:body][:settings][:index][:number_of_shards]).to eq(5)
expect(args[:body][:mappings]).to eq(Event.mappings.to_hash)
{ "acknowledged" => true }
end

Event.create_template
end
end
49 changes: 49 additions & 0 deletions spec/models/other_doi_shard_settings_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

require "rails_helper"

describe "Other DOI number_of_shards" do
it "defaults to 5 on OtherDoi settings" do
expect(ENV.fetch("NUMBER_OF_SHARDS_OTHER_DOI")).to eq("5")
expect(OtherDoi.settings.to_hash.dig(:index, :number_of_shards)).to eq(5)
end

it "does not apply the OtherDoi shard setting to shared Doi settings" do
expect(Doi.settings.to_hash.dig(:index, :number_of_shards)).to be_nil
expect(OtherDoi.settings).not_to equal(Doi.settings)
expect(OtherDoi.settings).not_to equal(DataciteDoi.settings)
end

it "uses OtherDoi.settings when building the OtherDoi template" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(OtherDoi.index_name)
expect(args[:body][:index_patterns]).to eq(["#{OtherDoi.index_name}*"])
expect(args[:body][:settings]).to eq(OtherDoi.settings.to_hash)
expect(args[:body][:settings][:index][:number_of_shards]).to eq(5)
expect(args[:body][:mappings]).to eq(Doi.mappings.to_hash)
{ "acknowledged" => true }
end

OtherDoi.create_template
end

it "keeps DataciteDoi templates on DataciteDoi settings" do
indices = Elasticsearch::Model.client.indices
allow(indices).to receive(:exists_template?).and_return(false)
expect(indices).to receive(:put_template) do |args|
expect(args[:name]).to eq(DataciteDoi.index_name)
expect(args[:body][:index_patterns]).to eq(
[DataciteDoi.index_name, "#{DataciteDoi.index_name}_v1", "#{DataciteDoi.index_name}_v2"],
)
expect(args[:body][:settings]).to eq(DataciteDoi.settings.to_hash)
expect(args[:body][:settings][:index][:number_of_shards]).to eq(
ENV.fetch("NUMBER_OF_SHARDS_DATACITE_DOI").to_i,
)
{ "acknowledged" => true }
end

DataciteDoi.create_template
end
end
Loading