Commit 07a79959 authored by Patrick Bajao's avatar Patrick Bajao

Merge branch 'remove-marginalia-feature-flag' into 'master'

Remove Marginalia feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!54349
parents d5341588 fc3707d5
---
name: marginalia
introduced_by_url:
rollout_issue_url:
milestone:
type: ops
group:
default_enabled: false
...@@ -4,11 +4,6 @@ require 'marginalia' ...@@ -4,11 +4,6 @@ require 'marginalia'
::Marginalia::Comment.extend(::Gitlab::Marginalia::Comment) ::Marginalia::Comment.extend(::Gitlab::Marginalia::Comment)
# Patch to modify 'Marginalia::ActiveRecordInstrumentation.annotate_sql' method with feature check.
# Orignal Marginalia::ActiveRecordInstrumentation is included to ActiveRecord::ConnectionAdapters::PostgreSQLAdapter in the Marginalia Railtie.
# Refer: https://github.com/basecamp/marginalia/blob/v1.8.0/lib/marginalia/railtie.rb#L67
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(Gitlab::Marginalia::ActiveRecordInstrumentation)
# By default, PostgreSQL only tracks the first 1024 bytes of a SQL # By default, PostgreSQL only tracks the first 1024 bytes of a SQL
# query. Prepending the comment allows us to trace the source of the # query. Prepending the comment allows us to trace the source of the
# query without having to increase the `track_activity_query_size` # query without having to increase the `track_activity_query_size`
...@@ -25,5 +20,3 @@ Marginalia::Comment.components << :line if Rails.env.development? ...@@ -25,5 +20,3 @@ Marginalia::Comment.components << :line if Rails.env.development?
Gitlab::Marginalia.set_application_name Gitlab::Marginalia.set_application_name
Gitlab::Marginalia.enable_sidekiq_instrumentation Gitlab::Marginalia.enable_sidekiq_instrumentation
Gitlab::Marginalia.set_enabled_from_feature_flag
...@@ -47,16 +47,3 @@ Examples of queries with comments as observed in `development.log`: ...@@ -47,16 +47,3 @@ Examples of queries with comments as observed in `development.log`:
```sql ```sql
/*application:sidekiq,jid:e7d6668a39a991e323009833,job_class:ExpireJobCacheWorker,correlation_id:rYF4mey9CH3,line:/app/workers/expire_job_cache_worker.rb:14:in `perform'*/ SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."id" = $1 LIMIT $2 [["id", 64], ["LIMIT", 1]] /*application:sidekiq,jid:e7d6668a39a991e323009833,job_class:ExpireJobCacheWorker,correlation_id:rYF4mey9CH3,line:/app/workers/expire_job_cache_worker.rb:14:in `perform'*/ SELECT "ci_pipelines".* FROM "ci_pipelines" WHERE "ci_pipelines"."id" = $1 LIMIT $2 [["id", 64], ["LIMIT", 1]]
``` ```
## Enable/Disable the feature
Enabling or disabling the feature requires a **restart/SIGHUP** of the Web and
Sidekiq workers, as the feature flag's state is memoized upon starting up.
The `feature_flag` for this feature is **disabled** by default. You can enable
or disable it with:
```ruby
Feature.enable(:marginalia)
Feature.disable(:marginalia)
```
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
module Gitlab module Gitlab
module Marginalia module Marginalia
cattr_accessor :enabled, default: false
def self.set_application_name def self.set_application_name
::Marginalia.application_name = Gitlab.process_name ::Marginalia.application_name = Gitlab.process_name
end end
...@@ -13,12 +11,5 @@ module Gitlab ...@@ -13,12 +11,5 @@ module Gitlab
::Marginalia::SidekiqInstrumentation.enable! ::Marginalia::SidekiqInstrumentation.enable!
end end
end end
def self.set_enabled_from_feature_flag
# During db:create and db:bootstrap skip feature query as DB is not available yet.
return false unless Gitlab::Database.cached_table_exists?('features')
self.enabled = Feature.enabled?(:marginalia, type: :ops)
end
end end
end end
# frozen_string_literal: true
# Patch to annotate sql only when the feature is enabled.
module Gitlab
module Marginalia
module ActiveRecordInstrumentation
def annotate_sql(sql)
Gitlab::Marginalia.enabled ? super(sql) : sql
end
end
end
end
...@@ -37,11 +37,6 @@ RSpec.describe 'Marginalia spec' do ...@@ -37,11 +37,6 @@ RSpec.describe 'Marginalia spec' do
} }
end end
context 'when the feature is enabled' do
before do
stub_feature(true)
end
it 'generates a query that includes the component and value' do it 'generates a query that includes the component and value' do
component_map.each do |component, value| component_map.each do |component, value|
expect(recorded.log.last).to include("#{component}:#{value}") expect(recorded.log.last).to include("#{component}:#{value}")
...@@ -49,18 +44,6 @@ RSpec.describe 'Marginalia spec' do ...@@ -49,18 +44,6 @@ RSpec.describe 'Marginalia spec' do
end end
end end
context 'when the feature is disabled' do
before do
stub_feature(false)
end
it 'excludes annotations in generated queries' do
expect(recorded.log.last).not_to include("/*")
expect(recorded.log.last).not_to include("*/")
end
end
end
describe 'for Sidekiq worker jobs' do describe 'for Sidekiq worker jobs' do
around do |example| around do |example|
with_sidekiq_server_middleware do |chain| with_sidekiq_server_middleware do |chain|
...@@ -90,11 +73,6 @@ RSpec.describe 'Marginalia spec' do ...@@ -90,11 +73,6 @@ RSpec.describe 'Marginalia spec' do
} }
end end
context 'when the feature is enabled' do
before do
stub_feature(true)
end
it 'generates a query that includes the component and value' do it 'generates a query that includes the component and value' do
component_map.each do |component, value| component_map.each do |component, value|
expect(recorded.log.last).to include("#{component}:#{value}") expect(recorded.log.last).to include("#{component}:#{value}")
...@@ -126,23 +104,6 @@ RSpec.describe 'Marginalia spec' do ...@@ -126,23 +104,6 @@ RSpec.describe 'Marginalia spec' do
end end
end end
context 'when the feature is disabled' do
before do
stub_feature(false)
end
it 'excludes annotations in generated queries' do
expect(recorded.log.last).not_to include("/*")
expect(recorded.log.last).not_to include("*/")
end
end
end
def stub_feature(value)
stub_feature_flags(marginalia: value)
Gitlab::Marginalia.set_enabled_from_feature_flag
end
def make_request(correlation_id) def make_request(correlation_id)
request_env = Rack::MockRequest.env_for('/') request_env = Rack::MockRequest.env_for('/')
......
...@@ -249,9 +249,6 @@ RSpec.configure do |config| ...@@ -249,9 +249,6 @@ RSpec.configure do |config|
unstub_all_feature_flags unstub_all_feature_flags
end end
# Enable Marginalia feature for all specs in the test suite.
Gitlab::Marginalia.enabled = true
# Stub these calls due to being expensive operations # Stub these calls due to being expensive operations
# It can be reenabled for specific tests via: # It can be reenabled for specific tests via:
# #
......
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