summaryrefslogtreecommitdiff
path: root/service/metrics/rpc.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-06-27 13:18:42 +0300
committerWolfy-J <[email protected]>2019-06-27 13:18:42 +0300
commit11870a2df3ccd8f79f131354ba106e557c248b48 (patch)
tree80ec8f7e2de0fe7508b73287affd02c769210a61 /service/metrics/rpc.go
parentc4a260cacc43bd8c5b87cce890ae582124ef3509 (diff)
rpc test
Diffstat (limited to 'service/metrics/rpc.go')
-rw-r--r--service/metrics/rpc.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/service/metrics/rpc.go b/service/metrics/rpc.go
index 30ad6c62..ca99d4ac 100644
--- a/service/metrics/rpc.go
+++ b/service/metrics/rpc.go
@@ -15,12 +15,18 @@ type Metric struct {
// Collector value.
Value float64
- // Labels associated with metric. Only for vector metrics.
+ // Labels associated with metric. Only for vector metrics. Must be provided in a form of label values.
Labels []string
}
// Add new metric to the designated collector.
-func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
+func (rpc *rpcServer) Add(m *Metric, ok *bool) (err error) {
+ defer func() {
+ if r, fail := recover().(error); fail {
+ err = r
+ }
+ }()
+
c := rpc.svc.Collector(m.Name)
if c == nil {
return fmt.Errorf("undefined collector `%s`", m.Name)
@@ -73,7 +79,13 @@ func (rpc *rpcServer) Add(m *Metric, ok *bool) error {
}
// Sub subtract the value from the specific metric (gauge only).
-func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
+func (rpc *rpcServer) Sub(m *Metric, ok *bool) (err error) {
+ defer func() {
+ if r, fail := recover().(error); fail {
+ err = r
+ }
+ }()
+
c := rpc.svc.Collector(m.Name)
if c == nil {
return fmt.Errorf("undefined collector `%s`", m.Name)
@@ -98,7 +110,13 @@ func (rpc *rpcServer) Sub(m *Metric, ok *bool) error {
}
// Observe the value (histogram and summary only).
-func (rpc *rpcServer) Observe(m *Metric, ok *bool) error {
+func (rpc *rpcServer) Observe(m *Metric, ok *bool) (err error) {
+ defer func() {
+ if r, fail := recover().(error); fail {
+ err = r
+ }
+ }()
+
c := rpc.svc.Collector(m.Name)
if c == nil {
return fmt.Errorf("undefined collector `%s`", m.Name)
@@ -130,7 +148,13 @@ func (rpc *rpcServer) Observe(m *Metric, ok *bool) error {
}
// Set the metric value (only for gaude).
-func (rpc *rpcServer) Set(m *Metric, ok *bool) error {
+func (rpc *rpcServer) Set(m *Metric, ok *bool) (err error) {
+ defer func() {
+ if r, fail := recover().(error); fail {
+ err = r
+ }
+ }()
+
c := rpc.svc.Collector(m.Name)
if c == nil {
return fmt.Errorf("undefined collector `%s`", m.Name)