@@ -27,69 +27,100 @@ type (
2727
2828// counter
2929
30- func DefineCounterMetric (name string ) ( MetricCounter , error ) {
30+ func DefineCounterMetric (name string ) MetricCounter {
3131 var id uint32
3232 ptr := stringBytePtr (name )
3333 st := rawhostcall .ProxyDefineMetric (types .MetricTypeCounter , ptr , len (name ), & id )
34- return MetricCounter (id ), types .StatusToError (st )
34+ if err := types .StatusToError (st ); err != nil {
35+ LogCriticalf ("define metric of name %s: %v" , name , types .StatusToError (st ))
36+ }
37+ return MetricCounter (id )
3538}
3639
3740func (m MetricCounter ) ID () uint32 {
3841 return uint32 (m )
3942}
4043
41- func (m MetricCounter ) Get () ( uint64 , error ) {
44+ func (m MetricCounter ) Get () uint64 {
4245 var val uint64
4346 st := rawhostcall .ProxyGetMetric (m .ID (), & val )
44- return val , types .StatusToError (st )
47+ if err := types .StatusToError (st ); err != nil {
48+ LogCriticalf ("get metric of %d: %v" , m .ID (), types .StatusToError (st ))
49+ panic ("" ) // abort
50+ }
51+ return val
4552}
4653
47- func (m MetricCounter ) Increment (offset uint64 ) error {
48- return types .StatusToError (rawhostcall .ProxyIncrementMetric (m .ID (), int64 (offset )))
54+ func (m MetricCounter ) Increment (offset uint64 ) {
55+ if err := types .StatusToError (rawhostcall .ProxyIncrementMetric (m .ID (), int64 (offset ))); err != nil {
56+ LogCriticalf ("increment %d by %d: %v" , m .ID (), offset , err )
57+ panic ("" ) // abort
58+ }
4959}
5060
5161// gauge
5262
53- func DefineGaugeMetric (name string ) ( MetricGauge , error ) {
63+ func DefineGaugeMetric (name string ) MetricGauge {
5464 var id uint32
5565 ptr := stringBytePtr (name )
5666 st := rawhostcall .ProxyDefineMetric (types .MetricTypeGauge , ptr , len (name ), & id )
57- return MetricGauge (id ), types .StatusToError (st )
67+ if err := types .StatusToError (st ); err != nil {
68+ LogCriticalf ("error define metric of name %s: %v" , name , types .StatusToError (st ))
69+ panic ("" ) // abort
70+ }
71+ return MetricGauge (id )
5872}
5973
6074func (m MetricGauge ) ID () uint32 {
6175 return uint32 (m )
6276}
6377
64- func (m MetricGauge ) Get () ( int64 , error ) {
78+ func (m MetricGauge ) Get () int64 {
6579 var val uint64
66- st := rawhostcall .ProxyGetMetric (m .ID (), & val )
67- return int64 (val ), types .StatusToError (st )
80+ if err := types .StatusToError (rawhostcall .ProxyGetMetric (m .ID (), & val )); err != nil {
81+ LogCriticalf ("get metric of %d: %v" , m .ID (), err )
82+ panic ("" ) // abort
83+ }
84+ return int64 (val )
6885}
6986
70- func (m MetricGauge ) Add (offset int64 ) error {
71- return types .StatusToError (rawhostcall .ProxyIncrementMetric (m .ID (), offset ))
87+ func (m MetricGauge ) Add (offset int64 ) {
88+ if err := types .StatusToError (rawhostcall .ProxyIncrementMetric (m .ID (), offset )); err != nil {
89+ LogCriticalf ("error adding %d by %d: %v" , m .ID (), offset , err )
90+ panic ("" ) // abort
91+ }
7292}
7393
7494// histogram
7595
76- func DefineHistogramMetric (name string ) ( MetricHistogram , error ) {
96+ func DefineHistogramMetric (name string ) MetricHistogram {
7797 var id uint32
7898 ptr := stringBytePtr (name )
7999 st := rawhostcall .ProxyDefineMetric (types .MetricTypeHistogram , ptr , len (name ), & id )
80- return MetricHistogram (id ), types .StatusToError (st )
100+ if err := types .StatusToError (st ); err != nil {
101+ LogCriticalf ("error define metric of name %s: %v" , name , types .StatusToError (st ))
102+ panic ("" ) // abort
103+ }
104+ return MetricHistogram (id )
81105}
82106
83107func (m MetricHistogram ) ID () uint32 {
84108 return uint32 (m )
85109}
86110
87- func (m MetricHistogram ) Get () ( uint64 , error ) {
111+ func (m MetricHistogram ) Get () uint64 {
88112 var val uint64
89113 st := rawhostcall .ProxyGetMetric (m .ID (), & val )
90- return val , types .StatusToError (st )
114+ if err := types .StatusToError (st ); err != nil {
115+ LogCriticalf ("get metric of %d: %v" , m .ID (), types .StatusToError (st ))
116+ panic ("" ) // abort
117+ }
118+ return val
91119}
92120
93- func (m MetricHistogram ) Record (value uint64 ) error {
94- return types .StatusToError (rawhostcall .ProxyRecordMetric (m .ID (), value ))
121+ func (m MetricHistogram ) Record (value uint64 ) {
122+ if err := types .StatusToError (rawhostcall .ProxyRecordMetric (m .ID (), value )); err != nil {
123+ LogCriticalf ("error adding %d: %v" , m .ID (), err )
124+ panic ("" ) // abort
125+ }
95126}
0 commit comments