prometheus_exporter icon indicating copy to clipboard operation
prometheus_exporter copied to clipboard

Feature request: no-op `PrometheusExporter::Client` Implementation for test environment

Open viralpraxis opened this issue 1 year ago • 4 comments

Hey!

I believe it would be beneficial to have a no-op implementation of PrometheusExporter::Client for use in test environments. This would allow us to avoid sending metrics during tests while maintaining the same interface.

I believe we could implement a stub client like the following:

class StubClient < Client
  def send(json); end

  # Additional stub methods can be added here if necessary
end

If this idea is deemed appropriate, I'd be happy to create a pull request with the implementation.

viralpraxis avatar Jul 26 '24 22:07 viralpraxis

not sure about this, I guess if it simplifies some of the test suite then fine

SamSaffron avatar Jul 28 '24 23:07 SamSaffron

The following client stub

# frozen_string_literal: true

require "prometheus_exporter/client"

module PrometheusExporter
  class ClientStub < PrometheusExporter::Client
    def send(_json); end
    def process_queue; end
    def stop(wait_timeout_seconds: 0); end
  end
end

seems to work fine -- in our case, in dev/test environments prometheus_exporter is loaded and PrometheusExprorter::Client.default is set to PrometheusExporter::ClientStub.new. We also don't see any significant test suite slow down. In fact, it's OK for us to have this stub in our codebase (not in the gem itself). Should I open PR with these changes? If not, feel free to close this issue. I hope if someone tries to solve the same problem this snippet will be helpful.

viralpraxis avatar Jul 30 '24 11:07 viralpraxis

you can send a PR I guess.

SamSaffron avatar Aug 02 '24 05:08 SamSaffron

Could someone take a look, please?

viralpraxis avatar Aug 09 '24 10:08 viralpraxis