sampler_options.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2017 Uber Technologies, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package jaeger
  15. import (
  16. "time"
  17. )
  18. // SamplerOption is a function that sets some option on the sampler
  19. type SamplerOption func(options *samplerOptions)
  20. // SamplerOptions is a factory for all available SamplerOption's
  21. var SamplerOptions samplerOptions
  22. type samplerOptions struct {
  23. metrics *Metrics
  24. maxOperations int
  25. sampler Sampler
  26. logger Logger
  27. samplingServerURL string
  28. samplingRefreshInterval time.Duration
  29. }
  30. // Metrics creates a SamplerOption that initializes Metrics on the sampler,
  31. // which is used to emit statistics.
  32. func (samplerOptions) Metrics(m *Metrics) SamplerOption {
  33. return func(o *samplerOptions) {
  34. o.metrics = m
  35. }
  36. }
  37. // MaxOperations creates a SamplerOption that sets the maximum number of
  38. // operations the sampler will keep track of.
  39. func (samplerOptions) MaxOperations(maxOperations int) SamplerOption {
  40. return func(o *samplerOptions) {
  41. o.maxOperations = maxOperations
  42. }
  43. }
  44. // InitialSampler creates a SamplerOption that sets the initial sampler
  45. // to use before a remote sampler is created and used.
  46. func (samplerOptions) InitialSampler(sampler Sampler) SamplerOption {
  47. return func(o *samplerOptions) {
  48. o.sampler = sampler
  49. }
  50. }
  51. // Logger creates a SamplerOption that sets the logger used by the sampler.
  52. func (samplerOptions) Logger(logger Logger) SamplerOption {
  53. return func(o *samplerOptions) {
  54. o.logger = logger
  55. }
  56. }
  57. // SamplingServerURL creates a SamplerOption that sets the sampling server url
  58. // of the local agent that contains the sampling strategies.
  59. func (samplerOptions) SamplingServerURL(samplingServerURL string) SamplerOption {
  60. return func(o *samplerOptions) {
  61. o.samplingServerURL = samplingServerURL
  62. }
  63. }
  64. // SamplingRefreshInterval creates a SamplerOption that sets how often the
  65. // sampler will poll local agent for the appropriate sampling strategy.
  66. func (samplerOptions) SamplingRefreshInterval(samplingRefreshInterval time.Duration) SamplerOption {
  67. return func(o *samplerOptions) {
  68. o.samplingRefreshInterval = samplingRefreshInterval
  69. }
  70. }