Record dataTimestamp as float

This commit is contained in:
Jordan Liggitt 2024-11-25 12:01:28 -05:00
parent bf70d289fb
commit eb6bb5f84d
No known key found for this signature in database
4 changed files with 8 additions and 7 deletions

View File

@ -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 {

View File

@ -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()
}{
{

View File

@ -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()

View File

@ -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: &timestamppb.Timestamp{Seconds: time.Now().Unix()},
DataTimestamp: &timestamppb.Timestamp{Seconds: now.Unix(), Nanos: int32(now.Nanosecond())},
Keys: keys,
}, nil
}