github.com/uber/kraken@v0.1.4/metrics/m3.go (about) 1 // Copyright (c) 2016-2019 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 16 import ( 17 "fmt" 18 "io" 19 "time" 20 21 "github.com/uber-go/tally" 22 "github.com/uber-go/tally/m3" 23 ) 24 25 func newM3Scope(config Config, cluster string) (tally.Scope, io.Closer, error) { 26 if cluster == "" { 27 return nil, nil, fmt.Errorf("cluster required for m3") 28 } 29 30 if config.M3.Service == "" { 31 return nil, nil, fmt.Errorf("service required for m3") 32 } 33 34 // HostPort is required for m3 metrics but tally/m3 does not fail when HostPort is empty. 35 if config.M3.HostPort == "" { 36 return nil, nil, fmt.Errorf("host_port required for m3") 37 } 38 39 m3Config := m3.Configuration{ 40 HostPort: config.M3.HostPort, 41 Service: config.M3.Service, 42 Env: cluster, 43 } 44 r, err := m3Config.NewReporter() 45 if err != nil { 46 return nil, nil, err 47 } 48 s, c := tally.NewRootScope(tally.ScopeOptions{ 49 CachedReporter: r, 50 }, time.Second) 51 return s, c, nil 52 }