@@ -3,16 +3,31 @@ package proxy
3
3
import (
4
4
"github.com/sirupsen/logrus"
5
5
"golang.org/x/net/context"
6
+ grpccodes "google.golang.org/grpc/codes"
7
+ grpcstatus "google.golang.org/grpc/status"
6
8
7
9
eclient "github.com/longhorn/longhorn-engine/pkg/controller/client"
8
10
"github.com/longhorn/types/pkg/generated/enginerpc"
9
11
rpc "github.com/longhorn/types/pkg/generated/imrpc"
10
12
)
11
13
12
14
func (p * Proxy ) MetricsGet (ctx context.Context , req * rpc.ProxyEngineRequest ) (resp * rpc.EngineMetricsGetProxyResponse , err error ) {
13
- log := logrus .WithFields (logrus.Fields {"serviceURL" : req .Address })
15
+ log := logrus .WithFields (logrus.Fields {
16
+ "serviceURL" : req .Address ,
17
+ "volume" : req .VolumeName ,
18
+ "instance" : req .EngineName ,
19
+ "dataEngine" : req .DataEngine ,
20
+ })
14
21
log .Trace ("Getting metrics" )
15
22
23
+ ops , ok := p .ops [req .DataEngine ]
24
+ if ! ok {
25
+ return nil , grpcstatus .Errorf (grpccodes .Unimplemented , "unsupported data engine %v" , req .DataEngine )
26
+ }
27
+ return ops .MetricsGet (ctx , req )
28
+ }
29
+
30
+ func (ops V1DataEngineProxyOps ) MetricsGet (ctx context.Context , req * rpc.ProxyEngineRequest ) (resp * rpc.EngineMetricsGetProxyResponse , err error ) {
16
31
c , err := eclient .NewControllerClient (req .Address , req .VolumeName , req .EngineName )
17
32
if err != nil {
18
33
return nil , err
@@ -35,3 +50,27 @@ func (p *Proxy) MetricsGet(ctx context.Context, req *rpc.ProxyEngineRequest) (re
35
50
},
36
51
}, nil
37
52
}
53
+
54
+ func (ops V2DataEngineProxyOps ) MetricsGet (ctx context.Context , req * rpc.ProxyEngineRequest ) (resp * rpc.EngineMetricsGetProxyResponse , err error ) {
55
+ c , err := getSPDKClientFromAddress (req .Address )
56
+ if err != nil {
57
+ return nil , grpcstatus .Errorf (grpccodes .Internal , "failed to get SPDK client from engine address %v: %v" , req .Address , err )
58
+ }
59
+ defer c .Close ()
60
+
61
+ metrics , err := c .MetricsGet (req .EngineName )
62
+ if err != nil {
63
+ return nil , grpcstatus .Errorf (grpccodes .Internal , "failed to get engine %v: %v" , req .EngineName , err )
64
+ }
65
+
66
+ return & rpc.EngineMetricsGetProxyResponse {
67
+ Metrics : & enginerpc.Metrics {
68
+ ReadThroughput : metrics .ReadThroughput ,
69
+ WriteThroughput : metrics .WriteThroughput ,
70
+ ReadLatency : metrics .ReadLatency ,
71
+ WriteLatency : metrics .WriteLatency ,
72
+ ReadIOPS : metrics .ReadIOPS ,
73
+ WriteIOPS : metrics .WriteIOPS ,
74
+ },
75
+ }, nil
76
+ }
0 commit comments