Merge pull request #128967 from liggitt/datatimestampfloat

Record dataTimestamp as float
This commit is contained in:
Kubernetes Prow Robot 2024-12-12 04:14:00 +00:00 committed by GitHub
commit 46623bcf21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 7 deletions

View File

@ -116,8 +116,8 @@ func RecordTokenGenAttempt(err error) {
tokenGenReqTotal.WithLabelValues(getErrorCode(err)).Inc() tokenGenReqTotal.WithLabelValues(getErrorCode(err)).Inc()
} }
func RecordKeyDataTimeStamp(timestamp int64) { func RecordKeyDataTimeStamp(timestamp float64) {
dataTimeStamp.WithLabelValues().Set(float64(timestamp)) dataTimeStamp.WithLabelValues().Set(timestamp)
} }
type gRPCError interface { type gRPCError interface {

View File

@ -195,13 +195,13 @@ func TestTokenGenMetrics(t *testing.T) {
func TestRecordKeyDataTimeStamp(t *testing.T) { func TestRecordKeyDataTimeStamp(t *testing.T) {
dataTimeStamp1 := time.Now().Unix() dataTimeStamp1 := float64(time.Now().Unix())
dataTimeStamp2 := time.Now().Add(time.Second * 1200).Unix() dataTimeStamp2 := float64(time.Now().Add(time.Second * 1200).Unix())
testCases := []struct { testCases := []struct {
desc string desc string
metrics []string metrics []string
want int64 want float64
emit func() emit func()
}{ }{
{ {

View File

@ -156,7 +156,7 @@ func (p *keyCache) syncKeys(ctx context.Context) error {
} }
p.verificationKeys.Store(newPublicKeys) p.verificationKeys.Store(newPublicKeys)
externaljwtmetrics.RecordKeyDataTimeStamp(newPublicKeys.DataTimestamp.Unix()) externaljwtmetrics.RecordKeyDataTimeStamp(float64(newPublicKeys.DataTimestamp.UnixNano()) / float64(1000000000))
if keysChanged(oldPublicKeys, newPublicKeys) { if keysChanged(oldPublicKeys, newPublicKeys) {
p.broadcastUpdate() p.broadcastUpdate()

View File

@ -160,9 +160,10 @@ func (m *MockSigner) FetchKeys(ctx context.Context, req *v1alpha1.FetchKeysReque
m.supportedKeysFetched.Broadcast() m.supportedKeysFetched.Broadcast()
m.supportedKeysLock.RUnlock() m.supportedKeysLock.RUnlock()
now := time.Now()
return &v1alpha1.FetchKeysResponse{ return &v1alpha1.FetchKeysResponse{
RefreshHintSeconds: 5, RefreshHintSeconds: 5,
DataTimestamp: &timestamppb.Timestamp{Seconds: time.Now().Unix()}, DataTimestamp: &timestamppb.Timestamp{Seconds: now.Unix(), Nanos: int32(now.Nanosecond())},
Keys: keys, Keys: keys,
}, nil }, nil
} }