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

Add a method to clear the registry #184

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/prometheus/client/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def get(name)
def metrics
@metrics.values
end

def clear
@metrics.clear
Copy link
Collaborator

Choose a reason for hiding this comment

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

@mutex.synchronize please :). (if we're going with this code, which I'm not sure we are, so maybe ignore me for now)

And come to think of it... Can we also please synchronize the 3 methods above? I'm not entirely sure how I didn't see that! 🙈

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow-up: #201

end
end
end
end
10 changes: 10 additions & 0 deletions spec/prometheus/client/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,14 @@ def registry.exist?(*args)
expect(registry.get(:test)).to eql(nil)
end
end

describe '#clear' do
it 'clears the registry' do
registry.register(double(name: :test))

expect(registry.get(:test)).to_not be_nil
registry.clear
expect(registry.get(:test)).to be_nil
end
end
end