factory.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 metrics
  15. import (
  16. "time"
  17. )
  18. // NSOptions defines the name and tags map associated with a factory namespace
  19. type NSOptions struct {
  20. Name string
  21. Tags map[string]string
  22. }
  23. // Options defines the information associated with a metric
  24. type Options struct {
  25. Name string
  26. Tags map[string]string
  27. Help string
  28. }
  29. // TimerOptions defines the information associated with a metric
  30. type TimerOptions struct {
  31. Name string
  32. Tags map[string]string
  33. Help string
  34. Buckets []time.Duration
  35. }
  36. // HistogramOptions defines the information associated with a metric
  37. type HistogramOptions struct {
  38. Name string
  39. Tags map[string]string
  40. Help string
  41. Buckets []float64
  42. }
  43. // Factory creates new metrics
  44. type Factory interface {
  45. Counter(metric Options) Counter
  46. Timer(metric TimerOptions) Timer
  47. Gauge(metric Options) Gauge
  48. Histogram(metric HistogramOptions) Histogram
  49. // Namespace returns a nested metrics factory.
  50. Namespace(scope NSOptions) Factory
  51. }
  52. // NullFactory is a metrics factory that returns NullCounter, NullTimer, and NullGauge.
  53. var NullFactory Factory = nullFactory{}
  54. type nullFactory struct{}
  55. func (nullFactory) Counter(options Options) Counter {
  56. return NullCounter
  57. }
  58. func (nullFactory) Timer(options TimerOptions) Timer {
  59. return NullTimer
  60. }
  61. func (nullFactory) Gauge(options Options) Gauge {
  62. return NullGauge
  63. }
  64. func (nullFactory) Histogram(options HistogramOptions) Histogram {
  65. return NullHistogram
  66. }
  67. func (nullFactory) Namespace(scope NSOptions) Factory { return NullFactory }