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

vmalert: fix vmalert_remotewrite_send_duration_seconds_total metric… #4801

Merged
merged 1 commit into from Aug 10, 2023

Conversation

Abirdcfly
Copy link
Contributor

… value

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

For a simulation, see: https://go.dev/play/p/XTxYljyk1VZ

package main

import (
	"fmt"
	"time"
)

func main() {
	B()
	A()
}
func A() {
	timeStart := time.Now()
	defer Add(time.Since(timeStart).Seconds())  // 0
	time.Sleep(time.Second)
}

func B() {
	timeStart := time.Now()
	defer func() {
		Add(time.Since(timeStart).Seconds())  // 1
	}()
	time.Sleep(time.Second)
}

func Add(d float64) {
	fmt.Println(d)
}

… value

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
Copy link
Collaborator

@Haleygo Haleygo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks for the fix!

@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.02% ⚠️

Comparison is base (527cfa2) 61.10% compared to head (4c815ed) 61.08%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4801      +/-   ##
==========================================
- Coverage   61.10%   61.08%   -0.02%     
==========================================
  Files         381      381              
  Lines       71586    71587       +1     
==========================================
- Hits        43740    43730      -10     
- Misses      25458    25466       +8     
- Partials     2388     2391       +3     
Files Changed Coverage Δ
app/vmalert/main.go 39.23% <100.00%> (+0.15%) ⬆️
app/vmalert/remotewrite/remotewrite.go 67.72% <100.00%> (+0.34%) ⬆️
app/vmalert/web.qtpl 71.32% <100.00%> (ø)

... and 9 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Haleygo Haleygo merged commit 835c03f into VictoriaMetrics:master Aug 10, 2023
9 of 10 checks passed
f41gh7 pushed a commit that referenced this pull request Aug 10, 2023
… value (#4801)

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
valyala pushed a commit that referenced this pull request Aug 11, 2023
… value (#4801)

The deferred call's arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

Signed-off-by: Abirdcfly <fp544037857@gmail.com>
@valyala
Copy link
Collaborator

valyala commented Aug 12, 2023

FYI, this pull request has been included in v1.93.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants