Esempio n. 1
0
// Instrumentation returns a Decorator which instruments an Exchanger with the given
// counter.
func Instrumentation(c logging.Counter) Decorator {
	return func(ex Exchanger) Exchanger {
		return Func(func(m *dns.Msg, a string) (*dns.Msg, time.Duration, error) {
			defer c.Inc()
			return ex.Exchange(m, a)
		})
	}
}
Esempio n. 2
0
// Instrumentation returns a Decorator which instruments an Exchanger with the given
// counters.
func Instrumentation(total, success, failure logging.Counter) Decorator {
	return func(ex Exchanger) Exchanger {
		return Func(func(m *dns.Msg, a string) (r *dns.Msg, rtt time.Duration, err error) {
			defer func() {
				if total.Inc(); err != nil {
					failure.Inc()
				} else {
					success.Inc()
				}
			}()
			return ex.Exchange(m, a)
		})
	}
}