Class: GraphQL::Hive::Sampler
- Inherits:
-
Object
- Object
- GraphQL::Hive::Sampler
- Defined in:
- lib/graphql-hive/sampler.rb
Overview
Sampler instance for usage reporter
Instance Method Summary collapse
-
#initialize(sampling_options, logger = nil) ⇒ Sampler
constructor
A new instance of Sampler.
- #sample?(operation) ⇒ Boolean
Constructor Details
#initialize(sampling_options, logger = nil) ⇒ Sampler
Returns a new instance of Sampler.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graphql-hive/sampler.rb', line 7 def initialize(, logger = nil) # backwards compatibility with old `collect_usage_sampling` field if .is_a?(Numeric) logger&.warn( "`collect_usage_sampling` is deprecated for fixed sampling rates, " \ "use `collect_usage_sampling: { sample_rate: XX }` instead" ) passed_sampling_rate = = {sample_rate: passed_sampling_rate} end ||= {} @sampler = if [:sampler] Sampling::DynamicSampler.new( [:sampler], [:at_least_once], [:key_generator] ) else Sampling::BasicSampler.new( [:sample_rate], [:at_least_once], [:key_generator] ) end end |
Instance Method Details
#sample?(operation) ⇒ Boolean
35 36 37 |
# File 'lib/graphql-hive/sampler.rb', line 35 def sample?(operation) @sampler.sample?(operation) end |