/
interface_with_prometheus.go
executable file
·96 lines (83 loc) · 3.08 KB
/
interface_with_prometheus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Code generated by gowrap. DO NOT EDIT.
// template: ../templates/prometheus
// gowrap: http://github.com/hexdigest/gowrap
package templatestests
//go:generate gowrap gen -p github.com/hexdigest/gowrap/templates_tests -i TestInterface -t ../templates/prometheus -o interface_with_prometheus.go -l ""
import (
"context"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// TestInterfaceWithPrometheus implements TestInterface interface with all methods wrapped
// with Prometheus metrics
type TestInterfaceWithPrometheus struct {
base TestInterface
instanceName string
}
var testinterfaceDurationSummaryVec = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Name: "testinterface_duration_seconds",
Help: "testinterface runtime duration and result",
MaxAge: time.Minute,
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
},
[]string{"instance_name", "method", "result"})
// NewTestInterfaceWithPrometheus returns an instance of the TestInterface decorated with prometheus summary metric
func NewTestInterfaceWithPrometheus(base TestInterface, instanceName string) TestInterfaceWithPrometheus {
return TestInterfaceWithPrometheus{
base: base,
instanceName: instanceName,
}
}
// Channels implements TestInterface
func (_d TestInterfaceWithPrometheus) Channels(chA chan bool, chB chan<- bool, chanC <-chan bool) {
_since := time.Now()
defer func() {
result := "ok"
testinterfaceDurationSummaryVec.WithLabelValues(_d.instanceName, "Channels", result).Observe(time.Since(_since).Seconds())
}()
_d.base.Channels(chA, chB, chanC)
return
}
// ContextNoError implements TestInterface
func (_d TestInterfaceWithPrometheus) ContextNoError(ctx context.Context, a1 string, a2 string) {
_since := time.Now()
defer func() {
result := "ok"
testinterfaceDurationSummaryVec.WithLabelValues(_d.instanceName, "ContextNoError", result).Observe(time.Since(_since).Seconds())
}()
_d.base.ContextNoError(ctx, a1, a2)
return
}
// F implements TestInterface
func (_d TestInterfaceWithPrometheus) F(ctx context.Context, a1 string, a2 ...string) (result1 string, result2 string, err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
testinterfaceDurationSummaryVec.WithLabelValues(_d.instanceName, "F", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.F(ctx, a1, a2...)
}
// NoError implements TestInterface
func (_d TestInterfaceWithPrometheus) NoError(s1 string) (s2 string) {
_since := time.Now()
defer func() {
result := "ok"
testinterfaceDurationSummaryVec.WithLabelValues(_d.instanceName, "NoError", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.NoError(s1)
}
// NoParamsOrResults implements TestInterface
func (_d TestInterfaceWithPrometheus) NoParamsOrResults() {
_since := time.Now()
defer func() {
result := "ok"
testinterfaceDurationSummaryVec.WithLabelValues(_d.instanceName, "NoParamsOrResults", result).Observe(time.Since(_since).Seconds())
}()
_d.base.NoParamsOrResults()
return
}