Skip to content

Commit 4cbba0f

Browse files
authored
Add support for timestamp metrics with seconds precision (#558)
* 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
1 parent fcb3850 commit 4cbba0f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

exporter/metrics.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ func asFloat64(value interface{}) (*float64, error) {
208208
f = v
209209
case primitive.DateTime:
210210
f = float64(v)
211-
case primitive.A, primitive.ObjectID, primitive.Timestamp, primitive.Binary, string, []uint8, time.Time:
211+
case primitive.Timestamp:
212+
f = float64(v.T)
213+
case primitive.A, primitive.ObjectID, primitive.Binary, string, []uint8, time.Time:
212214
return nil, nil
213215
default:
214216
return nil, errors.Wrapf(errCannotHandleType, "%T", v)

exporter/metrics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func TestMakeRawMetric(t *testing.T) {
141141
{value: float32(1.23), wantVal: pointer.ToFloat64(float64(float32(1.23)))},
142142
{value: float64(1.23), wantVal: pointer.ToFloat64(1.23)},
143143
{value: primitive.A{}, wantVal: nil},
144-
{value: primitive.Timestamp{}, wantVal: nil},
144+
{value: primitive.Timestamp{T: 123, I: 456}, wantVal: pointer.ToFloat64(123)},
145145
{value: "zapp", wantVal: nil},
146146
{value: []byte{}, wantVal: nil},
147147
{value: time.Date(2020, 6, 15, 0, 0, 0, 0, time.UTC), wantVal: nil},

0 commit comments

Comments
 (0)