Skip to content

Commit

Permalink
orca: ServerMetrics() method returns a copy of current metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
danielzhaotongliu committed Nov 20, 2023
1 parent aeedecb commit ba06b28
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion orca/call_metrics.go
Expand Up @@ -91,7 +91,7 @@ func (rw *recorderWrapper) recorder() CallMetricsRecorder {
func (rw *recorderWrapper) setTrailerMetadata(ctx context.Context) {
var sm *ServerMetrics
if rw.smp != nil {
sm = copyServerMetrics(rw.smp.ServerMetrics())
sm = rw.smp.ServerMetrics()
sm.merge(rw.r.ServerMetrics())
} else {
sm = rw.r.ServerMetrics()
Expand Down
6 changes: 3 additions & 3 deletions orca/server_metrics.go
Expand Up @@ -142,7 +142,7 @@ type ServerMetricsRecorder interface {
}

type serverMetricsRecorder struct {
state atomic.Pointer[ServerMetrics] // latest snapshot of the current metrics
state atomic.Pointer[ServerMetrics] // the current metrics
}

// NewServerMetricsRecorder returns an in-memory store for ServerMetrics and
Expand All @@ -167,9 +167,9 @@ func newServerMetricsRecorder() *serverMetricsRecorder {
return s
}

// ServerMetrics returns a pointer to the latest snapshot of ServerMetrics.
// ServerMetrics returns a copy of the current ServerMetrics.
func (s *serverMetricsRecorder) ServerMetrics() *ServerMetrics {
return s.state.Load()
return copyServerMetrics(s.state.Load())
}

func copyMap(m map[string]float64) map[string]float64 {
Expand Down

0 comments on commit ba06b28

Please sign in to comment.