Skip to content

Commit

Permalink
Add support for timestamp metrics with seconds precision (#558)
Browse files Browse the repository at this point in the history
* Add support for timestamp metrics with seconds precision

This is useful for exporting oplog metrics in order to calculate the
oplog window as the difference between mongodb_ss_oplog_latestOptime
and mongodb_ss_oplog_earliestOptime

* Fix test expectations
  • Loading branch information
trvrnrth authored Sep 29, 2023
1 parent fcb3850 commit 4cbba0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion exporter/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ func asFloat64(value interface{}) (*float64, error) {
f = v
case primitive.DateTime:
f = float64(v)
case primitive.A, primitive.ObjectID, primitive.Timestamp, primitive.Binary, string, []uint8, time.Time:
case primitive.Timestamp:
f = float64(v.T)
case primitive.A, primitive.ObjectID, primitive.Binary, string, []uint8, time.Time:
return nil, nil
default:
return nil, errors.Wrapf(errCannotHandleType, "%T", v)
Expand Down
2 changes: 1 addition & 1 deletion exporter/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestMakeRawMetric(t *testing.T) {
{value: float32(1.23), wantVal: pointer.ToFloat64(float64(float32(1.23)))},
{value: float64(1.23), wantVal: pointer.ToFloat64(1.23)},
{value: primitive.A{}, wantVal: nil},
{value: primitive.Timestamp{}, wantVal: nil},
{value: primitive.Timestamp{T: 123, I: 456}, wantVal: pointer.ToFloat64(123)},
{value: "zapp", wantVal: nil},
{value: []byte{}, wantVal: nil},
{value: time.Date(2020, 6, 15, 0, 0, 0, 0, time.UTC), wantVal: nil},
Expand Down

0 comments on commit 4cbba0f

Please sign in to comment.