/
instrumented_client.go
executable file
·139 lines (118 loc) · 4.49 KB
/
instrumented_client.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package reputation
// Code generated by gowrap. DO NOT EDIT.
// template: ../../../.prom-gowrap.tmpl
// gowrap: http://github.com/hexdigest/gowrap
//go:generate gowrap gen -p github.com/brave-intl/bat-go/libs/clients/-i Client -t ../../../.prom-gowrap.tmpl -o instrumented_client.go -l ""
import (
"context"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
uuid "github.com/satori/go.uuid"
"github.com/shopspring/decimal"
)
// ClientWithPrometheus implements Client interface with all methods wrapped
// with Prometheus metrics
type ClientWithPrometheus struct {
base Client
instanceName string
}
var clientDurationSummaryVec = promauto.NewSummaryVec(
prometheus.SummaryOpts{
Name: "reputation_client_duration_seconds",
Help: "client 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"})
// NewClientWithPrometheus returns an instance of the Client decorated with prometheus summary metric
func NewClientWithPrometheus(base Client, instanceName string) ClientWithPrometheus {
return ClientWithPrometheus{
base: base,
instanceName: instanceName,
}
}
// IsDrainReputable implements Client
func (_d ClientWithPrometheus) IsDrainReputable(ctx context.Context, id uuid.UUID, promotionID uuid.UUID, withdrawAmount decimal.Decimal) (b1 bool, ia1 []int, err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "IsDrainReputable", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.IsDrainReputable(ctx, id, promotionID, withdrawAmount)
}
// IsLinkingReputable implements Client
func (_d ClientWithPrometheus) IsLinkingReputable(ctx context.Context, id uuid.UUID, country string) (b1 bool, ia1 []int, err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "IsLinkingReputable", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.IsLinkingReputable(ctx, id, country)
}
// IsWalletAdsReputable implements Client
func (_d ClientWithPrometheus) IsWalletAdsReputable(ctx context.Context, id uuid.UUID, platform string) (b1 bool, err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "IsWalletAdsReputable", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.IsWalletAdsReputable(ctx, id, platform)
}
// IsWalletOnPlatform implements Client
func (_d ClientWithPrometheus) IsWalletOnPlatform(ctx context.Context, id uuid.UUID, platform string) (b1 bool, err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "IsWalletOnPlatform", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.IsWalletOnPlatform(ctx, id, platform)
}
// IsWalletReputable implements Client
func (_d ClientWithPrometheus) IsWalletReputable(ctx context.Context, id uuid.UUID, platform string) (b1 bool, err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "IsWalletReputable", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.IsWalletReputable(ctx, id, platform)
}
// UpdateReputationSummary implements Client
func (_d ClientWithPrometheus) UpdateReputationSummary(ctx context.Context, paymentID string, verifiedWallet bool) (err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "UpdateReputationSummary", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.UpdateReputationSummary(ctx, paymentID, verifiedWallet)
}
// UpsertReputationSummary implements Client
func (_d ClientWithPrometheus) UpsertReputationSummary(ctx context.Context, paymentID string, geoCountry string) (err error) {
_since := time.Now()
defer func() {
result := "ok"
if err != nil {
result = "error"
}
clientDurationSummaryVec.WithLabelValues(_d.instanceName, "UpsertReputationSummary", result).Observe(time.Since(_since).Seconds())
}()
return _d.base.UpsertReputationSummary(ctx, paymentID, geoCountry)
}