File tree Expand file tree Collapse file tree 3 files changed +48
-60
lines changed
Expand file tree Collapse file tree 3 files changed +48
-60
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- package promauto
1+ package promauto_adapter
22
33import (
44 "github.com/prometheus/client_golang/prometheus"
55 "github.com/prometheus/client_golang/prometheus/promauto"
66 "github.com/prometheus/client_golang/prometheus/promsafe"
77)
88
9- // NewCounterVec behaves as promauto.NewCounterVec but with type-safe labels
9+ // NewCounterVec behaves as adapter- promauto.NewCounterVec but with type-safe labels
1010func NewCounterVec [T promsafe.LabelsProviderMarker ](opts prometheus.CounterOpts ) * promsafe.CounterVec [T ] {
1111 //_ = promauto.NewCounterVec // keeping for reference
1212
@@ -22,12 +22,12 @@ type Factory[T promsafe.LabelsProviderMarker] struct {
2222 r prometheus.Registerer
2323}
2424
25- // With behaves same as promauto.With but with type-safe labels
25+ // With behaves same as adapter- promauto.With but with type-safe labels
2626func With [T promsafe.LabelsProviderMarker ](r prometheus.Registerer ) Factory [T ] {
2727 return Factory [T ]{r : r }
2828}
2929
30- // NewCounterVec behaves like promauto.NewCounterVec but with type-safe labels
30+ // NewCounterVec behaves like adapter- promauto.NewCounterVec but with type-safe labels
3131func (f Factory [T ]) NewCounterVec (opts prometheus.CounterOpts ) * promsafe.CounterVec [T ] {
3232 c := NewCounterVec [T ](opts )
3333 if f .r != nil {
Original file line number Diff line number Diff line change 1+ package promauto_adapter_test
2+
3+ import (
4+ "github.com/prometheus/client_golang/prometheus"
5+ "github.com/prometheus/client_golang/prometheus/promsafe"
6+ promauto "github.com/prometheus/client_golang/prometheus/promsafe/promauto_adapter"
7+ )
8+
9+ func ExampleNewCounterVec_promauto_adapted () {
10+ // Examples on how to migrate from promauto to promsafe gently
11+ //
12+ // Before:
13+ // import "github.com/prometheus/client_golang/prometheus/promauto"
14+ // func main() {
15+ // myReg := prometheus.NewRegistry()
16+ // counterOpts := prometheus.CounterOpts{Name:"..."}
17+ // promauto.With(myReg).NewCounterVec(counterOpts, []string{"event_type", "source"})
18+ // }
19+ //
20+ // After:
21+ //
22+ // import (
23+ // promauto "github.com/prometheus/client_golang/prometheus/promsafe/promauto_adapter"
24+ // )
25+ // ...
26+
27+ myReg := prometheus .NewRegistry ()
28+ counterOpts := prometheus.CounterOpts {
29+ Name : "items_counted_detailed_auto" ,
30+ }
31+
32+ type MyLabels struct {
33+ promsafe.StructLabelProvider
34+ EventType string
35+ Source string
36+ }
37+ c := promauto.With [MyLabels ](myReg ).NewCounterVec (counterOpts )
38+
39+ c .With (MyLabels {
40+ EventType : "reservation" , Source : "source1" ,
41+ }).Inc ()
42+
43+ // Output:
44+ }
You can’t perform that action at this time.
0 commit comments