Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replication observability metrics #142

Merged
merged 11 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ type Client interface {
PerformanceMetricsByAppliance(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByApplianceResponse, error)
PerformanceMetricsByNode(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByNodeResponse, error)
PerformanceMetricsByVolume(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByVolumeResponse, error)
VolumeMirrorTransferRate(ctx context.Context, entityID string) ([]VolumeMirrorTransferRateResponse, error)
PerformanceMetricsByCluster(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByClusterResponse, error)
PerformanceMetricsByVM(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByVMResponse, error)
PerformanceMetricsByVg(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByVgResponse, error)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/dell/gopowerstore

go 1.23

toolchain go1.23.1
require (
github.com/go-openapi/strfmt v0.23.0
github.com/jarcoal/httpmock v1.2.0
Expand Down
13 changes: 13 additions & 0 deletions inttests/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ func Test_PerformanceMetricsByVolume(t *testing.T) {
assert.Equal(t, "performance_metrics_by_volume", resp[0].Entity)
}

func Test_VolumeMirrorTransferRate(t *testing.T) {
volumesResp, err := C.GetVolumes(context.Background())
checkAPIErr(t, err)
if len(volumesResp) == 0 {
t.Skip("no volumes are available to check for metrics")
return
}
resp, err := C.VolumeMirrorTransferRate(context.Background(), volumesResp[0].ID)
checkAPIErr(t, err)
assert.NotEmpty(t, resp)
assert.Equal(t, "volume_mirror_transfer_rate", resp[0].ID)
}

func Test_PerformanceMetricsByCluster(t *testing.T) {
resp, err := C.PerformanceMetricsByCluster(context.Background(), "0", gopowerstore.FiveMins)
checkAPIErr(t, err)
Expand Down
46 changes: 44 additions & 2 deletions metrics.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright © 2020-2022 Dell Inc. or its subsidiaries. All Rights Reserved.
* Copyright © 2020-2024 Dell Inc. or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,9 +21,15 @@ package gopowerstore
import (
"context"
"errors"
"fmt"
"net/http"
)

const metricsURL = "metrics"
const (
metricsURL = "metrics"
mirrorURL = "volume_mirror_transfer_rate_cma_view"
limit = 2000
)

func (c *ClientIMPL) metricsRequest(ctx context.Context, response interface{}, entity string, entityID string, interval MetricsIntervalEnum) error {
_, err := c.APIClient().Query(
Expand All @@ -45,6 +51,35 @@ func (c *ClientIMPL) metricsRequest(ctx context.Context, response interface{}, e
return err
}

// mirrorTransferRate - Volume Mirror Transfer Rate
func (c *ClientIMPL) mirrorTransferRate(ctx context.Context, response interface{}, entityID string, limit int) error {
qp := getFSDefaultQueryParams(c)
qp.RawArg("id", fmt.Sprintf("eq.%s", entityID))
qp.Limit(limit)
qp.RawArg("select", "id,timestamp,synchronization_bandwidth,mirror_bandwidth,data_remaining")

customHeader := http.Header{}
customHeader.Add("DELL-VISIBILITY", "Internal")
apiClient := c.APIClient()
apiClient.SetCustomHTTPHeaders(customHeader)
AkshaySainiDell marked this conversation as resolved.
Show resolved Hide resolved

_, err := c.APIClient().Query(
ctx,
RequestConfig{
Method: "GET",
Endpoint: mirrorURL,
QueryParams: qp,
},
response)
if err != nil {
err = WrapErr(err)
}
customHeader.Del("DELL-VISIBILITY")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
customHeader.Del("DELL-VISIBILITY")
customHeader.Del("DELL-VISIBILITY")
apiClient.SetCustomHTTPHeaders(customHeader)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

apiClient.SetCustomHTTPHeaders(customHeader)

return err
}

// PerformanceMetricsByAppliance - Appliance performance metrics
func (c *ClientIMPL) PerformanceMetricsByAppliance(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByApplianceResponse, error) {
var resp []PerformanceMetricsByApplianceResponse
Expand All @@ -66,6 +101,13 @@ func (c *ClientIMPL) PerformanceMetricsByVolume(ctx context.Context, entityID st
return resp, err
}

// VolumeMirrorTransferRate - Volume Mirror Transfer Rate
func (c *ClientIMPL) VolumeMirrorTransferRate(ctx context.Context, entityID string) ([]VolumeMirrorTransferRateResponse, error) {
var resp []VolumeMirrorTransferRateResponse
err := c.mirrorTransferRate(ctx, &resp, entityID, limit)
return resp, err
}

// PerformanceMetricsByCluster - Cluster performance metrics
func (c *ClientIMPL) PerformanceMetricsByCluster(ctx context.Context, entityID string, interval MetricsIntervalEnum) ([]PerformanceMetricsByClusterResponse, error) {
var resp []PerformanceMetricsByClusterResponse
Expand Down
22 changes: 20 additions & 2 deletions metrics_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright © 2020-2022 Dell Inc. or its subsidiaries. All Rights Reserved.
* Copyright © 2020-2024 Dell Inc. or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,11 @@ import (
"github.com/stretchr/testify/assert"
)

const metricsMockURL = APIMockURL + metricsURL
const (
metricsMockURL = APIMockURL + metricsURL
metricsMockVolMirrURL = APIMockURL + mirrorURL
volumeID = "4ffcd8e8-2a93-49ed-b9b3-2e68c8ddc5e4"
)

func TestClientIMPL_GetCapacity(t *testing.T) {
totalSpace0 := 12077448036352
Expand Down Expand Up @@ -136,6 +140,20 @@ func TestClientIMPL_PerformanceMetricsByVolume(t *testing.T) {
assert.Equal(t, float64(1000), resp[0].TotalIops)
}

func TestClientIMPL_VolumeMirrorTransferRate(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
setResponder := func(respData string) {
httpmock.RegisterResponder("GET", metricsMockVolMirrURL,
httpmock.NewStringResponder(200, respData))
}
respData := fmt.Sprintf(`[{"id": "%s"}]`, volumeID)
setResponder(respData)
volMirr, err := C.VolumeMirrorTransferRate(context.Background(), volumeID)
assert.Nil(t, err)
assert.Equal(t, volumeID, volMirr[0].ID)
}

func TestClientIMPL_PerformanceMetricsByCluster(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
Expand Down
20 changes: 19 additions & 1 deletion metrics_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright © 2020-2022 Dell Inc. or its subsidiaries. All Rights Reserved.
* Copyright © 2020-2024 Dell Inc. or its subsidiaries. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1194,6 +1194,24 @@ type PerformanceMetricsByVolumeResponse struct {
CommonMaxAvgIopsBandwidthFields
}

// VolumeMirrorTransferRateResponse is returned by volume_mirror_transfer_rate
type VolumeMirrorTransferRateResponse struct {
// Unique identifier representing a specific volume.
ID string `json:"id,omitempty"`

// The timestamp of the last read or write operation.
Timestamp strfmt.DateTime `json:"timestamp,omitempty"`

// The read or write bandwidth in bytes per second.
SynchronizationBandwidth float32 `json:"synchronization_bandwidth,omitempty"`

// The read or write bandwidth in bytes per second.
MirrorBandwidth float32 `json:"mirror_bandwidth,omitempty"`

// The amount of data remaining in the bandwidth
DataRemaining float32 `json:"data_remaining,omitempty"`
}

type CommonAvgFields struct {
// Average size of read and write operations in bytes.
AvgIoSize float32 `json:"avg_io_size,omitempty"`
Expand Down
30 changes: 29 additions & 1 deletion mocks/Client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.