Skip to content

Commit

Permalink
Do not panic when writing via nil metric
Browse files Browse the repository at this point in the history
trace instead
  • Loading branch information
alpinskiy committed Dec 12, 2024
1 parent d61f293 commit 5aa995c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions statshouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,10 @@ func (m *MetricRef) IsNil() bool {
return m.bucket == nil
}

func (m *MetricRef) Equal(other MetricRef) bool {
return m.bucket == other.bucket
}

// Count records the number of events or observations.
func (m *MetricRef) Count(n float64) {
m.CountHistoric(n, 0)
Expand Down Expand Up @@ -1200,6 +1204,10 @@ func (c *Client) NamedStringsTopHistoric(name string, tags NamedTags, values []s
}

func (m *MetricRef) write(tsUnixSec uint32, fn func(*bucket)) {
if m.bucket == nil {
log.Println("[statshouse] data loss: nil metric write")
return
}
m.mu.Lock()
tsZeroOrEqual := tsUnixSec == 0 || m.tsUnixSec <= tsUnixSec
if m.attached && tsZeroOrEqual {
Expand Down

0 comments on commit 5aa995c

Please sign in to comment.