From d63c390d9a6c111348f12866983e50837a177276 Mon Sep 17 00:00:00 2001 From: Alex Kaplun <100761913+alexkaplun-firebolt@users.noreply.github.com> Date: Mon, 9 Sep 2024 16:53:50 +0300 Subject: [PATCH] chore: change order of queries on connect to an engine (#13) When a connection to an engine is established, the `SET...` queries must be run after `USE ENGINE..` statement, otherwise they will be discarder --- .github/workflows/pr.yaml | 2 +- internal/fetcher/fetcher.go | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5a0d5db..3cc2976 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -32,6 +32,6 @@ jobs: - name: Lint uses: golangci/golangci-lint-action@v6 with: - version: v1.58 + version: v1.60 - name: Test run: go test -vet=all ./... diff --git a/internal/fetcher/fetcher.go b/internal/fetcher/fetcher.go index affdb4b..4dc9ab8 100644 --- a/internal/fetcher/fetcher.go +++ b/internal/fetcher/fetcher.go @@ -223,18 +223,18 @@ func (f *fetcher) connect(ctx context.Context, accountName string, engineName st // switch to the engine if engineName is provided if engineName != "" { - // prevent engine from auto stopping caused by exporter queries - _, err = db.ExecContext(ctx, `SET auto_start_stop_control=ignore;`) - if err != nil { - return nil, fmt.Errorf("failed to set auto_start_stop_control = ignore for engine %s: %w", engineName, err) - } - // switch to an engine _, err = db.ExecContext(ctx, fmt.Sprintf(`USE ENGINE "%s";`, engineName)) if err != nil { return nil, fmt.Errorf("failed to switch to engine %s: %w", engineName, err) } + // prevent engine from auto stopping caused by exporter queries + _, err = db.ExecContext(ctx, `SET auto_start_stop_control=ignore;`) + if err != nil { + return nil, fmt.Errorf("failed to set auto_start_stop_control = ignore for engine %s: %w", engineName, err) + } + // add a query label to appear in query history _, err = db.ExecContext(ctx, `SET query_label=otel-exporter;`) if err != nil {