Skip to content
Closed
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
9 changes: 7 additions & 2 deletions metrics/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import (
"time"
)

// Shared JSON serialization for registry types to avoid duplication.
func marshalRegistryJSON(r Registry) ([]byte, error) {
return json.Marshal(r.GetAll())
}

// MarshalJSON returns a byte slice containing a JSON representation of all
// the metrics in the Registry.
func (r *StandardRegistry) MarshalJSON() ([]byte, error) {
return json.Marshal(r.GetAll())
return marshalRegistryJSON(r)
}

// WriteJSON writes metrics from the given registry periodically to the
Expand All @@ -27,5 +32,5 @@ func WriteJSONOnce(r Registry, w io.Writer) {
}

func (r *PrefixedRegistry) MarshalJSON() ([]byte, error) {
return json.Marshal(r.GetAll())
return marshalRegistryJSON(r)
}