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

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

Open
viralpraxis opened this issue Jul 26, 2024 · 4 comments

Comments

@viralpraxis
Copy link

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.

@SamSaffron
Copy link
Member

SamSaffron commented Jul 28, 2024

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

@viralpraxis
Copy link
Author

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.

@SamSaffron
Copy link
Member

you can send a PR I guess.

@viralpraxis
Copy link
Author

Could someone take a look, please?

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

No branches or pull requests

2 participants