Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time.Since() in defer. Wrap in anonymous function #113325

Merged
merged 1 commit into from Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/credentialprovider/plugin/plugin.go
Expand Up @@ -435,7 +435,9 @@ func (e *execPlugin) ExecPlugin(ctx context.Context, image string) (*credentialp

func (e *execPlugin) runPlugin(ctx context.Context, cmd *exec.Cmd, image string) error {
startTime := time.Now()
defer kubeletCredentialProviderPluginDuration.WithLabelValues(e.name).Observe(time.Since(startTime).Seconds())
defer func() {
kubeletCredentialProviderPluginDuration.WithLabelValues(e.name).Observe(time.Since(startTime).Seconds())
}()

err := cmd.Run()
if ctx.Err() != nil {
Expand Down
Expand Up @@ -101,7 +101,10 @@ func getBaseEnv() (*cel.Env, error) {
// perCallLimit was added for testing purpose only. Callers should always use const PerCallLimit as input.
func Compile(s *schema.Structural, declType *apiservercel.DeclType, perCallLimit uint64) ([]CompilationResult, error) {
t := time.Now()
defer metrics.Metrics.ObserveCompilation(time.Since(t))
defer func() {
metrics.Metrics.ObserveCompilation(time.Since(t))
}()

if len(s.Extensions.XValidations) == 0 {
return nil, nil
}
Expand Down
Expand Up @@ -139,7 +139,9 @@ func validator(s *schema.Structural, isResourceRoot bool, declType *cel.DeclType
// context is passed for supporting context cancellation during cel validation
func (s *Validator) Validate(ctx context.Context, fldPath *field.Path, sts *schema.Structural, obj, oldObj interface{}, costBudget int64) (errs field.ErrorList, remainingBudget int64) {
t := time.Now()
defer metrics.Metrics.ObserveEvaluation(time.Since(t))
defer func() {
metrics.Metrics.ObserveEvaluation(time.Since(t))
}()
remainingBudget = costBudget
if s == nil || obj == nil {
return nil, remainingBudget
Expand Down