sampler_options.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright (c) 2017 Uber Technologies, Inc.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. // THE SOFTWARE.
  20. package jaeger
  21. import (
  22. "time"
  23. )
  24. // SamplerOption is a function that sets some option on the sampler
  25. type SamplerOption func(options *samplerOptions)
  26. // SamplerOptions is a factory for all available SamplerOption's
  27. var SamplerOptions samplerOptions
  28. type samplerOptions struct {
  29. metrics *Metrics
  30. maxOperations int
  31. sampler Sampler
  32. logger Logger
  33. samplingServerURL string
  34. samplingRefreshInterval time.Duration
  35. }
  36. // Metrics creates a SamplerOption that initializes Metrics on the sampler,
  37. // which is used to emit statistics.
  38. func (samplerOptions) Metrics(m *Metrics) SamplerOption {
  39. return func(o *samplerOptions) {
  40. o.metrics = m
  41. }
  42. }
  43. // MaxOperations creates a SamplerOption that sets the maximum number of
  44. // operations the sampler will keep track of.
  45. func (samplerOptions) MaxOperations(maxOperations int) SamplerOption {
  46. return func(o *samplerOptions) {
  47. o.maxOperations = maxOperations
  48. }
  49. }
  50. // InitialSampler creates a SamplerOption that sets the initial sampler
  51. // to use before a remote sampler is created and used.
  52. func (samplerOptions) InitialSampler(sampler Sampler) SamplerOption {
  53. return func(o *samplerOptions) {
  54. o.sampler = sampler
  55. }
  56. }
  57. // Logger creates a SamplerOption that sets the logger used by the sampler.
  58. func (samplerOptions) Logger(logger Logger) SamplerOption {
  59. return func(o *samplerOptions) {
  60. o.logger = logger
  61. }
  62. }
  63. // SamplingServerURL creates a SamplerOption that sets the sampling server url
  64. // of the local agent that contains the sampling strategies.
  65. func (samplerOptions) SamplingServerURL(samplingServerURL string) SamplerOption {
  66. return func(o *samplerOptions) {
  67. o.samplingServerURL = samplingServerURL
  68. }
  69. }
  70. // SamplingRefreshInterval creates a SamplerOption that sets how often the
  71. // sampler will poll local agent for the appropriate sampling strategy.
  72. func (samplerOptions) SamplingRefreshInterval(samplingRefreshInterval time.Duration) SamplerOption {
  73. return func(o *samplerOptions) {
  74. o.samplingRefreshInterval = samplingRefreshInterval
  75. }
  76. }