Commit b1f75a22 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Merge branch 'default-oj' into 'master'

Remove :oj_json feature flag

See merge request gitlab-org/gitlab!46012
parents cb4ec474 7d57c135
---
name: oj_json
introduced_by_url:
rollout_issue_url:
group:
type: development
default_enabled: true
...@@ -67,15 +67,6 @@ module Gitlab ...@@ -67,15 +67,6 @@ module Gitlab
::JSON.pretty_generate(object, opts) ::JSON.pretty_generate(object, opts)
end end
# Feature detection for using Oj instead of the `json` gem.
#
# @return [Boolean]
def enable_oj?
return false unless feature_table_exists?
Feature.enabled?(:oj_json, default_enabled: true)
end
private private
# Convert JSON string into Ruby through toggleable adapters. # Convert JSON string into Ruby through toggleable adapters.
...@@ -91,11 +82,7 @@ module Gitlab ...@@ -91,11 +82,7 @@ module Gitlab
def adapter_load(string, *args, **opts) def adapter_load(string, *args, **opts)
opts = standardize_opts(opts) opts = standardize_opts(opts)
if enable_oj?
Oj.load(string, opts) Oj.load(string, opts)
else
::JSON.parse(string, opts)
end
rescue Oj::ParseError, Encoding::UndefinedConversionError => ex rescue Oj::ParseError, Encoding::UndefinedConversionError => ex
raise parser_error.new(ex) raise parser_error.new(ex)
end end
...@@ -120,11 +107,7 @@ module Gitlab ...@@ -120,11 +107,7 @@ module Gitlab
# #
# @return [String] # @return [String]
def adapter_dump(object, *args, **opts) def adapter_dump(object, *args, **opts)
if enable_oj?
Oj.dump(object, opts) Oj.dump(object, opts)
else
::JSON.dump(object, *args)
end
end end
# Generates JSON for an object but with fewer options, using toggleable adapters. # Generates JSON for an object but with fewer options, using toggleable adapters.
...@@ -135,11 +118,7 @@ module Gitlab ...@@ -135,11 +118,7 @@ module Gitlab
def adapter_generate(object, opts = {}) def adapter_generate(object, opts = {})
opts = standardize_opts(opts) opts = standardize_opts(opts)
if enable_oj?
Oj.generate(object, opts) Oj.generate(object, opts)
else
::JSON.generate(object, opts)
end
end end
# Take a JSON standard options hash and standardize it to work across adapters # Take a JSON standard options hash and standardize it to work across adapters
...@@ -149,11 +128,8 @@ module Gitlab ...@@ -149,11 +128,8 @@ module Gitlab
# @return [Hash] # @return [Hash]
def standardize_opts(opts) def standardize_opts(opts)
opts ||= {} opts ||= {}
if enable_oj?
opts[:mode] = :rails opts[:mode] = :rails
opts[:symbol_keys] = opts[:symbolize_keys] || opts[:symbolize_names] opts[:symbol_keys] = opts[:symbolize_keys] || opts[:symbolize_names]
end
opts opts
end end
...@@ -213,7 +189,7 @@ module Gitlab ...@@ -213,7 +189,7 @@ module Gitlab
# @param object [Object] # @param object [Object]
# @return [String] # @return [String]
def self.call(object, env = nil) def self.call(object, env = nil)
if Gitlab::Json.enable_oj? && Feature.enabled?(:grape_gitlab_json, default_enabled: true) if Feature.enabled?(:grape_gitlab_json, default_enabled: true)
Gitlab::Json.dump(object) Gitlab::Json.dump(object)
else else
Grape::Formatter::Json.call(object, env) Grape::Formatter::Json.call(object, env)
......
...@@ -7,7 +7,6 @@ RSpec.describe Gitlab::Json do ...@@ -7,7 +7,6 @@ RSpec.describe Gitlab::Json do
stub_feature_flags(json_wrapper_legacy_mode: true) stub_feature_flags(json_wrapper_legacy_mode: true)
end end
shared_examples "json" do
describe ".parse" do describe ".parse" do
context "legacy_mode is disabled by default" do context "legacy_mode is disabled by default" do
it "parses an object" do it "parses an object" do
...@@ -295,12 +294,6 @@ RSpec.describe Gitlab::Json do ...@@ -295,12 +294,6 @@ RSpec.describe Gitlab::Json do
subject.send(:handle_legacy_mode!, {}) subject.send(:handle_legacy_mode!, {})
end end
it "skips oj feature detection" do
expect(Feature).not_to receive(:enabled?).with(:oj_json, default_enabled: true)
subject.send(:enable_oj?)
end
end end
context "the database is missing" do context "the database is missing" do
...@@ -316,35 +309,6 @@ RSpec.describe Gitlab::Json do ...@@ -316,35 +309,6 @@ RSpec.describe Gitlab::Json do
expect(subject.dump({})).to eq("{}") expect(subject.dump({})).to eq("{}")
end end
end end
end
context "oj gem" do
before do
stub_feature_flags(oj_json: true)
end
it_behaves_like "json"
describe "#enable_oj?" do
it "returns true" do
expect(subject.enable_oj?).to be(true)
end
end
end
context "json gem" do
before do
stub_feature_flags(oj_json: false)
end
it_behaves_like "json"
describe "#enable_oj?" do
it "returns false" do
expect(subject.enable_oj?).to be(false)
end
end
end
describe Gitlab::Json::GrapeFormatter do describe Gitlab::Json::GrapeFormatter do
subject { described_class.call(obj, env) } subject { described_class.call(obj, env) }
...@@ -353,11 +317,6 @@ RSpec.describe Gitlab::Json do ...@@ -353,11 +317,6 @@ RSpec.describe Gitlab::Json do
let(:env) { {} } let(:env) { {} }
let(:result) { "{\"test\":true}" } let(:result) { "{\"test\":true}" }
context "oj is enabled" do
before do
stub_feature_flags(oj_json: true)
end
context "grape_gitlab_json flag is enabled" do context "grape_gitlab_json flag is enabled" do
before do before do
stub_feature_flags(grape_gitlab_json: true) stub_feature_flags(grape_gitlab_json: true)
...@@ -391,23 +350,6 @@ RSpec.describe Gitlab::Json do ...@@ -391,23 +350,6 @@ RSpec.describe Gitlab::Json do
end end
end end
context "oj is disabled" do
before do
stub_feature_flags(oj_json: false)
end
it "generates JSON" do
expect(subject).to eq(result)
end
it "uses Grape::Formatter::Json" do
expect(Grape::Formatter::Json).to receive(:call).with(obj, env)
subject
end
end
end
describe Gitlab::Json::LimitedEncoder do describe Gitlab::Json::LimitedEncoder do
subject { described_class.encode(obj, limit: 8.kilobytes) } subject { described_class.encode(obj, limit: 8.kilobytes) }
......
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