github.com/m3db/m3@v1.5.0/src/x/instrument/types.go (about) 1 // Copyright (c) 2016 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 instrument implements functions to make instrumenting code, 22 // including metrics and logging, easier. 23 package instrument 24 25 import ( 26 "time" 27 28 "github.com/opentracing/opentracing-go" 29 "github.com/uber-go/tally" 30 "go.uber.org/zap" 31 ) 32 33 // Reporter reports metrics about a component. 34 type Reporter interface { 35 // Start starts the reporter. 36 Start() error 37 // Stop stops the reporter. 38 Stop() error 39 } 40 41 // Profiler represents profiler for profiling long-running tasks. 42 type Profiler interface { 43 // StartCPUProfile starts the named cpu profile. 44 StartCPUProfile(name string) error 45 46 // StopCPUProfile stops started cpu profile. 47 StopCPUProfile() error 48 49 // WriteHeapProfile writes heap profile. 50 WriteHeapProfile(name string) error 51 } 52 53 // Options represents the options for instrumentation. 54 type Options interface { 55 // SetLogger sets the zap logger 56 SetLogger(value *zap.Logger) Options 57 58 // Logger returns the zap logger 59 Logger() *zap.Logger 60 61 // SetMetricsScope sets the metrics scope. 62 SetMetricsScope(value tally.Scope) Options 63 64 // MetricsScope returns the metrics scope. 65 MetricsScope() tally.Scope 66 67 // Tracer returns the tracer. 68 Tracer() opentracing.Tracer 69 70 // SetTracer sets the tracer. 71 SetTracer(tracer opentracing.Tracer) Options 72 73 // SetTimerOptions sets the metrics timer options to used 74 // when building timers from timer options. 75 SetTimerOptions(value TimerOptions) Options 76 77 // TimerOptions returns the metrics timer options to used 78 // when building timers from timer options. 79 TimerOptions() TimerOptions 80 81 // SetReportInterval sets the time between reporting metrics within the system. 82 SetReportInterval(time.Duration) Options 83 84 // ReportInterval returns the time between reporting metrics within the system. 85 ReportInterval() time.Duration 86 87 // SetCustomBuildTags sets custom tags to be added to build report metrics in 88 // addition to the defaults. 89 SetCustomBuildTags(tags map[string]string) Options 90 91 // CustomBuildTags returns the custom build tags. 92 CustomBuildTags() map[string]string 93 94 // SetProfiler sets the profiler. 95 SetProfiler(value Profiler) Options 96 97 // Profiler returns the Profiler. 98 Profiler() Profiler 99 }