1// Copyright 2017 The Prometheus Authors 2// Licensed under the Apache License, Version 2.0 (the "License"); 3// you may not use this file except in compliance with the License. 4// You may obtain a copy of the License at 5// 6// http://www.apache.org/licenses/LICENSE-2.0 7// 8// Unless required by applicable law or agreed to in writing, software 9// distributed under the License is distributed on an "AS IS" BASIS, 10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11// See the License for the specific language governing permissions and 12// limitations under the License. 13 14package prometheus 15 16// Observer is the interface that wraps the Observe method, which is used by 17// Histogram and Summary to add observations. 18type Observer interface { 19 Observe(float64) 20} 21 22// The ObserverFunc type is an adapter to allow the use of ordinary 23// functions as Observers. If f is a function with the appropriate 24// signature, ObserverFunc(f) is an Observer that calls f. 25// 26// This adapter is usually used in connection with the Timer type, and there are 27// two general use cases: 28// 29// The most common one is to use a Gauge as the Observer for a Timer. 30// See the "Gauge" Timer example. 31// 32// The more advanced use case is to create a function that dynamically decides 33// which Observer to use for observing the duration. See the "Complex" Timer 34// example. 35type ObserverFunc func(float64) 36 37// Observe calls f(value). It implements Observer. 38func (f ObserverFunc) Observe(value float64) { 39 f(value) 40} 41 42// ObserverVec is an interface implemented by `HistogramVec` and `SummaryVec`. 43type ObserverVec interface { 44 GetMetricWith(Labels) (Observer, error) 45 GetMetricWithLabelValues(lvs ...string) (Observer, error) 46 With(Labels) Observer 47 WithLabelValues(...string) Observer 48 CurryWith(Labels) (ObserverVec, error) 49 MustCurryWith(Labels) ObserverVec 50 51 Collector 52} 53 54// ExemplarObserver is implemented by Observers that offer the option of 55// observing a value together with an exemplar. Its ObserveWithExemplar method 56// works like the Observe method of an Observer but also replaces the currently 57// saved exemplar (if any) with a new one, created from the provided value, the 58// current time as timestamp, and the provided Labels. Empty Labels will lead to 59// a valid (label-less) exemplar. But if Labels is nil, the current exemplar is 60// left in place. ObserveWithExemplar panics if any of the provided labels are 61// invalid or if the provided labels contain more than 64 runes in total. 62type ExemplarObserver interface { 63 ObserveWithExemplar(value float64, exemplar Labels) 64} 65