diff --git a/pkg/serviceaccount/externaljwt/metrics/metrics.go b/pkg/serviceaccount/externaljwt/metrics/metrics.go index d20e7893be7..56997ad99f7 100644 --- a/pkg/serviceaccount/externaljwt/metrics/metrics.go +++ b/pkg/serviceaccount/externaljwt/metrics/metrics.go @@ -116,8 +116,8 @@ func RecordTokenGenAttempt(err error) { tokenGenReqTotal.WithLabelValues(getErrorCode(err)).Inc() } -func RecordKeyDataTimeStamp(timestamp int64) { - dataTimeStamp.WithLabelValues().Set(float64(timestamp)) +func RecordKeyDataTimeStamp(timestamp float64) { + dataTimeStamp.WithLabelValues().Set(timestamp) } type gRPCError interface { diff --git a/pkg/serviceaccount/externaljwt/metrics/metrics_test.go b/pkg/serviceaccount/externaljwt/metrics/metrics_test.go index 02623750266..ef5e9348671 100644 --- a/pkg/serviceaccount/externaljwt/metrics/metrics_test.go +++ b/pkg/serviceaccount/externaljwt/metrics/metrics_test.go @@ -195,13 +195,13 @@ func TestTokenGenMetrics(t *testing.T) { func TestRecordKeyDataTimeStamp(t *testing.T) { - dataTimeStamp1 := time.Now().Unix() - dataTimeStamp2 := time.Now().Add(time.Second * 1200).Unix() + dataTimeStamp1 := float64(time.Now().Unix()) + dataTimeStamp2 := float64(time.Now().Add(time.Second * 1200).Unix()) testCases := []struct { desc string metrics []string - want int64 + want float64 emit func() }{ { diff --git a/pkg/serviceaccount/externaljwt/plugin/keycache.go b/pkg/serviceaccount/externaljwt/plugin/keycache.go index 521e0f881e7..f7ad53d0e86 100644 --- a/pkg/serviceaccount/externaljwt/plugin/keycache.go +++ b/pkg/serviceaccount/externaljwt/plugin/keycache.go @@ -156,7 +156,7 @@ func (p *keyCache) syncKeys(ctx context.Context) error { } p.verificationKeys.Store(newPublicKeys) - externaljwtmetrics.RecordKeyDataTimeStamp(newPublicKeys.DataTimestamp.Unix()) + externaljwtmetrics.RecordKeyDataTimeStamp(float64(newPublicKeys.DataTimestamp.UnixNano()) / float64(1000000000)) if keysChanged(oldPublicKeys, newPublicKeys) { p.broadcastUpdate() diff --git a/pkg/serviceaccount/externaljwt/plugin/testing/v1alpha1/externalsigner_mock.go b/pkg/serviceaccount/externaljwt/plugin/testing/v1alpha1/externalsigner_mock.go index a3f19c4fe1e..3175714c00c 100644 --- a/pkg/serviceaccount/externaljwt/plugin/testing/v1alpha1/externalsigner_mock.go +++ b/pkg/serviceaccount/externaljwt/plugin/testing/v1alpha1/externalsigner_mock.go @@ -160,9 +160,10 @@ func (m *MockSigner) FetchKeys(ctx context.Context, req *v1alpha1.FetchKeysReque m.supportedKeysFetched.Broadcast() m.supportedKeysLock.RUnlock() + now := time.Now() return &v1alpha1.FetchKeysResponse{ RefreshHintSeconds: 5, - DataTimestamp: ×tamppb.Timestamp{Seconds: time.Now().Unix()}, + DataTimestamp: ×tamppb.Timestamp{Seconds: now.Unix(), Nanos: int32(now.Nanosecond())}, Keys: keys, }, nil }