in internal/alloydb/lazy.go [66:124]
func (c *LazyRefreshCache) ConnectionInfo(
ctx context.Context,
) (ConnectionInfo, error) {
c.mu.Lock()
defer c.mu.Unlock()
// strip monotonic clock with UTC()
now := time.Now().UTC()
// Pad expiration with a buffer to give the client plenty of time to
// establish a connection to the server with the certificate.
exp := c.cached.Expiration.UTC().Add(-refreshBuffer)
if !c.needsRefresh && now.Before(exp) {
c.logger.Debugf(
ctx,
"[%v] Connection info is still valid, using cached info",
c.uri.String(),
)
return c.cached, nil
}
c.logger.Debugf(
ctx,
"[%v] Connection info refresh operation started",
c.uri.String(),
)
ci, err := c.r.connectionInfo(ctx, c.uri)
if err != nil {
c.logger.Debugf(
ctx,
"[%v] Connection info refresh operation failed, err = %v",
c.uri.String(),
err,
)
go c.metricRecorder.RecordRefreshCount(ctx, telv2.Attributes{
UserAgent: c.userAgent,
RefreshType: telv2.RefreshLazyType,
RefreshStatus: telv2.RefreshFailure,
})
return ConnectionInfo{}, err
}
go c.metricRecorder.RecordRefreshCount(ctx, telv2.Attributes{
UserAgent: c.userAgent,
RefreshType: telv2.RefreshLazyType,
RefreshStatus: telv2.RefreshSuccess,
})
c.logger.Debugf(
ctx,
"[%v] Connection info refresh operation complete",
c.uri.String(),
)
c.logger.Debugf(
ctx,
"[%v] Current certificate expiration = %v",
c.uri.String(),
ci.Expiration.UTC().Format(time.RFC3339),
)
c.cached = ci
c.needsRefresh = false
return ci, nil
}