Skip to content

Commit dad5e5e

Browse files
hookakderekbit
authored andcommitted
feat: implement MetricsGet to support V1 and V2 data engines in ProxyOps
longhorn 10472 Signed-off-by: jinhong.kim0 <[email protected]>
1 parent 51e5b6b commit dad5e5e

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

pkg/client/proxy_metrics.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
package client
22

33
import (
4-
"github.com/pkg/errors"
5-
4+
"fmt"
65
rpc "github.com/longhorn/types/pkg/generated/imrpc"
6+
"github.com/pkg/errors"
77
)
88

9-
func (c *ProxyClient) MetricsGet(engineName, volumeName, serviceAddress string) (metrics *Metrics, err error) {
9+
func (c *ProxyClient) MetricsGet(dataEngine, engineName, volumeName, serviceAddress string) (metrics *Metrics, err error) {
1010
input := map[string]string{
1111
"engineName": engineName,
1212
"volumeName": volumeName,
1313
"serviceAddress": serviceAddress,
14+
"dataEngine": dataEngine,
1415
}
1516
if err := validateProxyMethodParameters(input); err != nil {
1617
return nil, errors.Wrap(err, "failed to get metrics for volume")
1718
}
1819

20+
driver, ok := rpc.DataEngine_value[getDataEngine(dataEngine)]
21+
if !ok {
22+
return nil, fmt.Errorf("failed to get metrics for volume: invalid data engine %v", dataEngine)
23+
}
24+
1925
defer func() {
2026
err = errors.Wrapf(err, "%v failed to get metrics for volume", c.getProxyErrorPrefix(serviceAddress))
2127
}()
@@ -24,6 +30,7 @@ func (c *ProxyClient) MetricsGet(engineName, volumeName, serviceAddress string)
2430
Address: serviceAddress,
2531
EngineName: engineName,
2632
VolumeName: volumeName,
33+
DataEngine: rpc.DataEngine(driver),
2734
}
2835
resp, err := c.service.MetricsGet(getContextWithGRPCTimeout(c.ctx), req)
2936
if err != nil {

pkg/proxy/metrics.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@ package proxy
33
import (
44
"github.com/sirupsen/logrus"
55
"golang.org/x/net/context"
6+
grpccodes "google.golang.org/grpc/codes"
7+
grpcstatus "google.golang.org/grpc/status"
68

79
eclient "github.com/longhorn/longhorn-engine/pkg/controller/client"
810
"github.com/longhorn/types/pkg/generated/enginerpc"
911
rpc "github.com/longhorn/types/pkg/generated/imrpc"
1012
)
1113

1214
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+
})
1421
log.Trace("Getting metrics")
1522

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) {
1631
c, err := eclient.NewControllerClient(req.Address, req.VolumeName, req.EngineName)
1732
if err != nil {
1833
return nil, err
@@ -35,3 +50,27 @@ func (p *Proxy) MetricsGet(ctx context.Context, req *rpc.ProxyEngineRequest) (re
3550
},
3651
}, nil
3752
}
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+
}

pkg/proxy/proxy.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type ProxyOps interface {
5252
SnapshotBackupStatus(context.Context, *rpc.EngineSnapshotBackupStatusRequest) (*rpc.EngineSnapshotBackupStatusProxyResponse, error)
5353
BackupRestore(context.Context, *rpc.EngineBackupRestoreRequest, map[string]string) error
5454
BackupRestoreStatus(context.Context, *rpc.ProxyEngineRequest) (*rpc.EngineBackupRestoreStatusProxyResponse, error)
55+
56+
MetricsGet(context.Context, *rpc.ProxyEngineRequest) (*rpc.EngineMetricsGetProxyResponse, error)
5557
}
5658

5759
type V1DataEngineProxyOps struct{}

0 commit comments

Comments
 (0)