gitlab.com/gitlab-org/labkit@v1.21.0/metrics/http_round_tripper/factory_options.go (about) 1 package http_round_tripper 2 3 type config struct { 4 labelValues map[string]string 5 } 6 7 type factoryConfig struct { 8 namespace string 9 subsystem string 10 requestDurationBuckets []float64 11 labels []string 12 } 13 14 // FactoryOption is used to pass options in NewFactory. 15 type FactoryOption func(*factoryConfig) 16 17 func applyFactoryOptions(opts []FactoryOption) factoryConfig { 18 config := factoryConfig{ 19 subsystem: "http", 20 requestDurationBuckets: []float64{ 21 0.005, /* 5ms */ 22 0.025, /* 25ms */ 23 0.1, /* 100ms */ 24 0.5, /* 500ms */ 25 1.0, /* 1s */ 26 10.0, /* 10s */ 27 30.0, /* 30s */ 28 60.0, /* 1m */ 29 300.0, /* 5m */ 30 }, 31 labels: []string{"code", "method"}, 32 } 33 for _, v := range opts { 34 v(&config) 35 } 36 37 return config 38 } 39 40 // WithNamespace will configure the namespace to apply to the metrics. 41 func WithNamespace(namespace string) FactoryOption { 42 return func(config *factoryConfig) { 43 config.namespace = namespace 44 } 45 } 46 47 // WithLabels will configure additional labels to apply to the metrics. 48 func WithLabels(labels ...string) FactoryOption { 49 return func(config *factoryConfig) { 50 config.labels = append(config.labels, labels...) 51 } 52 } 53 54 // WithRequestDurationBuckets will configure the duration buckets used for 55 // incoming request histogram buckets. 56 func WithRequestDurationBuckets(buckets []float64) FactoryOption { 57 return func(config *factoryConfig) { 58 config.requestDurationBuckets = buckets 59 } 60 }