Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global instrumenter configuration #636

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

bkeepers
Copy link
Collaborator

@bkeepers bkeepers commented Jun 8, 2022

While working on some changes for a different PR, I was running into some friction with having to pass the instrumenter option around everywhere. This doesn't seem like something that needs configured per object. This PR adds a global Flipper.instrumenter config and a Flipper.instrument method.

# config/initializers/flipper.rb
  Flipper.configure do |config|
    config.adapter do
-     Flipper::Adapters::Instrumented.new(my_adapter, instrumenter: MyInstrumenter)
+     Flipper::Adapters::Instrumented.new(my_adapter)
    end
+   config.instrumenter MyInstrumenter
  end

@bkeepers bkeepers requested a review from jnunemaker June 8, 2022 18:52
Flipper.instrumenter.subscribe(
Flipper::Feature::InstrumentationName,
Flipper::Instrumentation::CloudSubscriber.new(brow)
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up that I rewrote this to use a subscriber instead of wrapping the instrumenter. I think it's fair to say that anyone that wants to use this should be using AS::Notifications (default in Rails) or some other instrumentation framework.

Doesn't seem like there were any tests for this, and I have not tested it manually yet.

Copy link
Collaborator

@jnunemaker jnunemaker Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new telemetry stuff needs to work as a wrapper so that and this will conflict.

The main reason is that AS notifications are super slow. I don't want people (including me) to have to use those in order to get analytics.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason is that AS notifications are super slow. I don't want people (including me) to have to use those in order to get analytics.

FWIW, the engine configures AS Notifications by default in all Rails apps, so every app you manage right now is probably already using it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K. I thought we turned that off for some reason but I can see it is not. I'm sure my apps aren't sensitive to it but I've helped a handful of people debug perf issues and AS::Notification was the easiest win each time.

@@ -1,8 +1,9 @@
module Flipper
class Configuration
def initialize(options = {})
@default = -> { Flipper.new(adapter) }
@adapter = -> { Flipper::Adapters::Memory.new }
adapter { Flipper::Adapters::Memory.new }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow! That looks nice. I know its a little thing, but sweet.

@@ -84,21 +84,19 @@
context 'when primary is instrumented and fails' do
before do
allow(memory_adapter).to receive(:get).and_raise(Net::ReadTimeout)
Flipper.instrumenter = instrumenter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok because it's actually updating config and config is reset for every spec, right? Just did a double take because global changes without resetting always make me shiver. :)

@@ -6,16 +6,16 @@
let(:statsd_client) { Statsd.new }
let(:socket) { FakeUDPSocket.new }
let(:adapter) do
memory = Flipper::Adapters::Memory.new
Flipper::Adapters::Instrumented.new(memory, instrumenter: ActiveSupport::Notifications)
Flipper::Adapters::Instrumented.new(Flipper::Adapters::Memory.new)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now stuff like this can use use right?

Copy link
Collaborator

@jnunemaker jnunemaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this. It does simplify things and no one in their right mind would use different instrumenters for different parts of flipper. Left one note about the cloud instrumenter. Feel free to hit me up about that when looking to merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants