Skip to content

Commit

Permalink
performance fix
Browse files Browse the repository at this point in the history
Signed-off-by: nitesh3108 <[email protected]>
  • Loading branch information
nitesh3108 committed Jan 10, 2025
1 parent 2643725 commit 4dc00ff
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 5 deletions.
67 changes: 62 additions & 5 deletions internal/service/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ func (mw *MetricsWrapper) Record(_ context.Context, meta interface{},

metrics := metricsMapValue.(*Metrics)

_, _ = mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
done := make(chan struct{})
reg, err := mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
obs.ObserveFloat64(metrics.ReadBW, float64(readBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.WriteBW, float64(writeBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.ReadIOPS, float64(readIOPS), metric.ObserveOption(metric.WithAttributes(labels...)))
Expand All @@ -197,6 +198,9 @@ func (mw *MetricsWrapper) Record(_ context.Context, meta interface{},
obs.ObserveFloat64(metrics.MirrorBW, float64(mirrorBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.DataRemaining, float64(dataRemaining), metric.ObserveOption(metric.WithAttributes(labels...)))

go func() {
done <- struct{}{}
}()
return nil
},
metrics.ReadBW,
Expand All @@ -210,6 +214,13 @@ func (mw *MetricsWrapper) Record(_ context.Context, meta interface{},
metrics.DataRemaining,
)

Check failure on line 216 in internal/service/metrics.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
if err != nil {
return err
}

<-done
_ = reg.Unregister()

return nil
}

Expand Down Expand Up @@ -307,15 +318,27 @@ func (mw *MetricsWrapper) RecordSpaceMetrics(_ context.Context, meta interface{}

metrics := metricsMapValue.(*SpaceMetrics)

_, _ = mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
done := make(chan struct{})
reg, err := mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
obs.ObserveFloat64(metrics.LogicalProvisioned, float64(logicalProvisioned), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.LogicalUsed, float64(logicalUsed), metric.ObserveOption(metric.WithAttributes(labels...)))

go func() {
done <- struct{}{}
}()
return nil
},
metrics.LogicalProvisioned,
metrics.LogicalUsed,
)

Check failure on line 334 in internal/service/metrics.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
if err != nil {
return err
}

<-done
_ = reg.Unregister()

return nil
}

Expand Down Expand Up @@ -385,15 +408,27 @@ func (mw *MetricsWrapper) RecordArraySpaceMetrics(_ context.Context, arrayID, dr
}

metrics := metricsMapValue.(*ArraySpaceMetrics)
_, _ = mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {

done := make(chan struct{})
reg, err := mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
obs.ObserveFloat64(metrics.LogicalProvisioned, float64(logicalProvisioned), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.LogicalUsed, float64(logicalUsed), metric.ObserveOption(metric.WithAttributes(labels...)))
go func() {
done <- struct{}{}
}()
return nil
},
metrics.LogicalProvisioned,
metrics.LogicalUsed,
)

Check failure on line 424 in internal/service/metrics.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
if err != nil {
return err
}

<-done
_ = reg.Unregister()

return nil
}

Expand Down Expand Up @@ -447,15 +482,26 @@ func (mw *MetricsWrapper) RecordStorageClassSpaceMetrics(_ context.Context, stor
}

metrics := metricsMapValue.(*ArraySpaceMetrics)
_, _ = mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {

done := make(chan struct{})
reg, err := mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
obs.ObserveFloat64(metrics.LogicalProvisioned, float64(logicalProvisioned), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.LogicalUsed, float64(logicalUsed), metric.ObserveOption(metric.WithAttributes(labels...)))
go func() {
done <- struct{}{}
}()
return nil
},
metrics.LogicalProvisioned,
metrics.LogicalUsed,
)

Check failure on line 498 in internal/service/metrics.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
if err != nil {
return err
}

<-done
_ = reg.Unregister()
return nil
}

Expand Down Expand Up @@ -557,7 +603,8 @@ func (mw *MetricsWrapper) RecordFileSystemMetrics(_ context.Context, meta interf

metrics := metricsMapValue.(*Metrics)

_, _ = mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
done := make(chan struct{})
reg, err := mw.Meter.RegisterCallback(func(_ context.Context, obs metric.Observer) error {
obs.ObserveFloat64(metrics.ReadBW, float64(readBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.WriteBW, float64(writeBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.ReadIOPS, float64(readIOPS), metric.ObserveOption(metric.WithAttributes(labels...)))
Expand All @@ -567,6 +614,9 @@ func (mw *MetricsWrapper) RecordFileSystemMetrics(_ context.Context, meta interf
obs.ObserveFloat64(metrics.SyncronizationBW, float64(syncBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.MirrorBW, float64(mirrorBW), metric.ObserveOption(metric.WithAttributes(labels...)))
obs.ObserveFloat64(metrics.DataRemaining, float64(dataRemaining), metric.ObserveOption(metric.WithAttributes(labels...)))
go func() {
done <- struct{}{}
}()
return nil
},
metrics.ReadBW,
Expand All @@ -580,5 +630,12 @@ func (mw *MetricsWrapper) RecordFileSystemMetrics(_ context.Context, meta interf
metrics.DataRemaining,
)

Check failure on line 632 in internal/service/metrics.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
if err != nil {
return err
}

<-done
_ = reg.Unregister()

return nil
}
67 changes: 67 additions & 0 deletions internal/service/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package service_test

import (
"context"

Check failure on line 20 in internal/service/metrics_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)
otlexporters "github.com/dell/csm-metrics-powerstore/opentelemetry/exporters"
"testing"

Check failure on line 22 in internal/service/metrics_test.go

View workflow job for this annotation

GitHub Actions / Golang Validation / Lint golang code

File is not properly formatted (gofumpt)

"github.com/dell/csm-metrics-powerstore/internal/service"
Expand All @@ -39,6 +40,13 @@ func TestMetricsWrapper_Record(t *testing.T) {
ID: "123",
},
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

type args struct {
ctx context.Context
meta interface{}
Expand Down Expand Up @@ -108,6 +116,13 @@ func TestMetricsWrapper_Record_Label_Update(t *testing.T) {
mw := &service.MetricsWrapper{
Meter: otel.Meter("powerstore-test"),
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

metaFirst := &service.VolumeMeta{
ID: "123",
PersistentVolumeName: "pvol0",
Expand Down Expand Up @@ -215,6 +230,13 @@ func TestMetricsWrapper_RecordSpaceMetrics(t *testing.T) {
ID: "123",
},
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

type args struct {
ctx context.Context
meta interface{}
Expand Down Expand Up @@ -295,6 +317,12 @@ func TestMetricsWrapper_RecordSpaceMetrics_Label_Update(t *testing.T) {
Protocol: "scsi",
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

expectedLables := []attribute.KeyValue{
attribute.String("VolumeID", metaSecond.ID),
attribute.String("PersistentVolumeName", metaSecond.PersistentVolumeName),
Expand Down Expand Up @@ -368,6 +396,12 @@ func TestMetricsWrapper_RecordArraySpaceMetrics(t *testing.T) {
Meter: otel.Meter("powerstore-test"),
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

type args struct {
ctx context.Context
arrayID string
Expand Down Expand Up @@ -408,6 +442,12 @@ func TestMetricsWrapper_RecordArraySpaceMetrics_Label_Update(t *testing.T) {
Meter: otel.Meter("powerstore-test"),
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

array1 := "123"
array2 := "123"
array3 := "125"
Expand Down Expand Up @@ -477,6 +517,13 @@ func TestMetricsWrapper_RecordStorageClassSpaceMetrics(t *testing.T) {
mw := &service.MetricsWrapper{
Meter: otel.Meter("powerstore-test"),
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

type args struct {
ctx context.Context
storageclass string
Expand Down Expand Up @@ -517,6 +564,12 @@ func TestMetricsWrapper_RecordStorageClassSpaceMetrics_Label_Update(t *testing.T
Meter: otel.Meter("powerstore-test"),
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

array1 := "storageclass"
array2 := "storageclass"
array3 := "storageclass2"
Expand Down Expand Up @@ -598,6 +651,13 @@ func TestMetricsWrapper_RecordFileSystemMetrics(t *testing.T) {
ID: "123",
},
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

type args struct {
ctx context.Context
meta interface{}
Expand Down Expand Up @@ -667,6 +727,13 @@ func TestMetricsWrapper_RecordFileSystemMetrics_Label_Update(t *testing.T) {
mw := &service.MetricsWrapper{
Meter: otel.Meter("powerstore-test"),
}

exporter := &otlexporters.OtlCollectorExporter{}
err := exporter.InitExporter()
if err != nil {
t.Fatal(err)
}

metaFirst := &service.VolumeMeta{
ID: "123",
PersistentVolumeName: "pvol0",
Expand Down

0 comments on commit 4dc00ff

Please sign in to comment.