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

Vmselect slow query https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5134 #6167

Open
wants to merge 2 commits into
base: cluster
Choose a base branch
from

Conversation

AVESH-RAI
Copy link

…s/issues/5134

Describe Your Changes

Please provide a brief description of the changes you made. Be as specific as possible to help others understand the purpose and impact of your modifications.

Checklist

The following checks are mandatory:

Signed-off-by: root <root@C-5CG324677Z>
@AVESH-RAI AVESH-RAI marked this pull request as ready for review April 22, 2024 11:42
@AVESH-RAI AVESH-RAI marked this pull request as draft April 22, 2024 11:43
@AVESH-RAI AVESH-RAI marked this pull request as ready for review April 23, 2024 11:30
@@ -902,6 +956,32 @@ var (
httpRequestsDuration = tenantmetrics.NewCounterMap(`vm_tenant_select_requests_duration_ms_total`)
)

var (
slowQueries = metrics.NewCounter(`vm_slow_queries_total{path="*"}`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This metric can be removed, since it's the same as sum(vm_slow_queries_total{path!=""}).

@@ -182,6 +180,61 @@ var (
})
)

func updateSlowQueryPathCounter(p *httpserver.Path, path string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need a duplicated function to identify the query path, we can increase counters in the original handler.
The code can be like this

	var slowQueries *metrics.Counter
	if *logSlowQueryDuration > 0 {
		actualStartTime := time.Now()
		defer func() {
			d := time.Since(actualStartTime)
			if d >= *logSlowQueryDuration {
...
				slowQueries.Inc()
			}
		}()
	}
...
	if path == "/admin/tenants" {
		tenantsRequests.Inc()
		slowQueries = pathSlowTenantsRequests
...

// selectHandler()
	switch p.Suffix {
	case "prometheus/api/v1/query":
		queryRequests.Inc()
		slowQueries = pathSlowQuery
		httpserver.EnableCORS(w, r)
		if err := prometheus.QueryHandler(qt, startTime, at, w, r); err != nil {
			queryErrors.Inc()
			sendPrometheusError(w, r, err)
			return true
		}
		return true
	case "prometheus/api/v1/query_range":
		queryRangeRequests.Inc()
		slowQueries = pathSlowQueryRange

@@ -234,6 +287,11 @@ func requestHandler(w http.ResponseWriter, r *http.Request) bool {
return true
}
}
p, err := httpserver.ParsePath(path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This check can't be moved before handlers /internal/resetRollupResultCache and /admin/tenants, it requires path to have /{prefix}/{tenantID}/{suffix} form.

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

2 participants