github.com/uber-go/tally/v4@v4.1.17/m3/config.go (about) 1 // Copyright (c) 2021 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 21 package m3 22 23 // Configuration is a configuration for a M3 reporter. 24 type Configuration struct { 25 // HostPort is the host and port of the M3 server. 26 HostPort string `yaml:"hostPort" validate:"nonzero"` 27 28 // HostPorts are the host and port of the M3 server. 29 HostPorts []string `yaml:"hostPorts"` 30 31 // Service is the service tag to that this client emits. 32 Service string `yaml:"service" validate:"nonzero"` 33 34 // Env is the env tag to use that this client emits. 35 Env string `yaml:"env" validate:"nonzero"` 36 37 // CommonTags are tags that are common for all metrics this client emits. 38 CommonTags map[string]string `yaml:"tags" ` 39 40 // Queue is the maximum metric queue size of client. 41 Queue int `yaml:"queue"` 42 43 // PacketSize is the maximum packet size for a batch of metrics. 44 PacketSize int32 `yaml:"packetSize"` 45 46 // IncludeHost is whether or not to include host tag. 47 IncludeHost bool `yaml:"includeHost"` 48 49 // HistogramBucketTagPrecision is precision to use when formatting the metric tag 50 // with the histogram bucket bound values. 51 HistogramBucketTagPrecision uint `yaml:"histogramBucketTagPrecision"` 52 53 // InternalTags are tags that should be added to all internal metrics 54 // emitted by the reporter. 55 InternalTags map[string]string `yaml:"internalTags"` 56 } 57 58 // NewReporter creates a new M3 reporter from this configuration. 59 func (c Configuration) NewReporter() (Reporter, error) { 60 hostPorts := c.HostPorts 61 if len(hostPorts) == 0 { 62 hostPorts = []string{c.HostPort} 63 } 64 return NewReporter(Options{ 65 HostPorts: hostPorts, 66 Service: c.Service, 67 Env: c.Env, 68 CommonTags: c.CommonTags, 69 MaxQueueSize: c.Queue, 70 MaxPacketSizeBytes: c.PacketSize, 71 IncludeHost: c.IncludeHost, 72 HistogramBucketTagPrecision: c.HistogramBucketTagPrecision, 73 InternalTags: c.InternalTags, 74 }) 75 }