Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/integration_tests/_utils/start_tidb_cluster_nextgen
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ tidb-server \
--path "${UP_PD_HOST_1}:${UP_PD_PORT_1}" \
--status "${UP_TIDB_SYSTEM_STATUS}" \
--log-file "$OUT_DIR/log/upstream/tidb-system/tidb.log" \
--log-slow-query "$OUT_DIR/log/upstream/tidb-system/tidb-slow.log" \
>"$OUT_DIR/log/upstream/tidb-system/tidb-stdout.log" \
2>"$OUT_DIR/log/upstream/tidb-system/tidb-stderr.log" &

Expand All @@ -629,6 +630,7 @@ tidb-server \
--path "${UP_PD_HOST_1}:${UP_PD_PORT_1}" \
--status "${UP_TIDB_STATUS}" \
--log-file "$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME/tidb.log" \
--log-slow-query "$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME/tidb-slow.log" \
>"$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME/tidb-stdout.log" \
2>"$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME/tidb-stderr.log" &

Expand All @@ -641,6 +643,7 @@ tidb-server \
--path "${UP_PD_HOST_1}:${UP_PD_PORT_1}" \
--status "${UP_TIDB_OTHER_STATUS}" \
--log-file "$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME-other/tidb.log" \
--log-slow-query "$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME-other/tidb-slow.log" \
>"$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME-other/tidb-stdout.log" \
2>"$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME-other/tidb-stderr.log" &

Expand All @@ -655,6 +658,7 @@ tidb-server \
--path "${DOWN_PD_HOST}:${DOWN_PD_PORT}" \
--status "${DOWN_TIDB_SYSTEM_STATUS}" \
--log-file "$OUT_DIR/log/downstream/tidb-system/tidb.log" \
--log-slow-query "$OUT_DIR/log/downstream/tidb-system/tidb-slow.log" \
>"$OUT_DIR/log/downstream/tidb-system/tidb-stdout.log" \
2>"$OUT_DIR/log/downstream/tidb-system/tidb-stderr.log" &

Expand All @@ -672,6 +676,7 @@ tidb-server \
--path "${DOWN_PD_HOST}:${DOWN_PD_PORT}" \
--status "${DOWN_TIDB_STATUS}" \
--log-file "$OUT_DIR/log/downstream/tidb-$KEYSPACE_NAME/tidb.log" \
--log-slow-query "$OUT_DIR/log/downstream/tidb-$KEYSPACE_NAME/tidb-slow.log" \
>"$OUT_DIR/log/downstream/tidb-$KEYSPACE_NAME/tidb-stdout.log" \
2>"$OUT_DIR/log/downstream/tidb-$KEYSPACE_NAME/tidb-stderr.log" &

Expand Down
69 changes: 69 additions & 0 deletions tests/integration_tests/_utils/start_tidb_cluster_nextgen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2026 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package utils_test

import (
"os"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func TestTiDBServersUseUniqueSlowQueryLogs(t *testing.T) {
_, currentFile, _, ok := runtime.Caller(0)
require.True(t, ok)

scriptPath := filepath.Join(filepath.Dir(currentFile), "start_tidb_cluster_nextgen")
content, err := os.ReadFile(scriptPath)
require.NoError(t, err)

lines := strings.Split(string(content), "\n")
commands := make([]string, 0, 5)
for i := 0; i < len(lines); i++ {
if strings.TrimSpace(lines[i]) != `tidb-server \` {
continue
}

var command strings.Builder
for ; i < len(lines); i++ {
command.WriteString(lines[i])
command.WriteByte('\n')
if strings.HasSuffix(strings.TrimSpace(lines[i]), "&") {
break
}
}
commands = append(commands, command.String())
}
require.Len(t, commands, 5)

slowQueryLogPattern := regexp.MustCompile(`--log-slow-query\s+"([^"]+)"`)
slowQueryLogs := make(map[string]struct{}, len(commands))
for _, command := range commands {
matches := slowQueryLogPattern.FindStringSubmatch(command)
require.Len(t, matches, 2, "TiDB command must configure a slow-query log:\n%s", command)
slowQueryLogs[matches[1]] = struct{}{}
Comment on lines +57 to +59

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Require exactly one slow-query-log option per command.

Line 57 only captures the first match, so a duplicate --log-slow-query option can evade this regression test. Match all occurrences and require one before recording its path.

Proposed fix
-		matches := slowQueryLogPattern.FindStringSubmatch(command)
-		require.Len(t, matches, 2, "TiDB command must configure a slow-query log:\n%s", command)
-		slowQueryLogs[matches[1]] = struct{}{}
+		matches := slowQueryLogPattern.FindAllStringSubmatch(command, -1)
+		require.Len(t, matches, 1, "TiDB command must configure exactly one slow-query log:\n%s", command)
+		slowQueryLogs[matches[0][1]] = struct{}{}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
matches := slowQueryLogPattern.FindStringSubmatch(command)
require.Len(t, matches, 2, "TiDB command must configure a slow-query log:\n%s", command)
slowQueryLogs[matches[1]] = struct{}{}
matches := slowQueryLogPattern.FindAllStringSubmatch(command, -1)
require.Len(t, matches, 1, "TiDB command must configure exactly one slow-query log:\n%s", command)
slowQueryLogs[matches[0][1]] = struct{}{}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/integration_tests/_utils/start_tidb_cluster_nextgen_test.go` around
lines 57 - 59, Update the slow-query option validation around
slowQueryLogPattern to find all matches in each command, require exactly one
occurrence, and only then record that match’s log path in slowQueryLogs.
Preserve the existing failure message context and path recording behavior for
valid commands.

}
require.Len(t, slowQueryLogs, len(commands), "each TiDB server must use a unique slow-query log")
require.Equal(t, map[string]struct{}{
"$OUT_DIR/log/upstream/tidb-system/tidb-slow.log": {},
"$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME/tidb-slow.log": {},
"$OUT_DIR/log/upstream/tidb-$KEYSPACE_NAME-other/tidb-slow.log": {},
"$OUT_DIR/log/downstream/tidb-system/tidb-slow.log": {},
"$OUT_DIR/log/downstream/tidb-$KEYSPACE_NAME/tidb-slow.log": {},
}, slowQueryLogs)
}
Loading