Skip to content

Commit cde00dd

Browse files
authored
Merge pull request #145115 from jeffswenson/backport24.3.12-rc-145114
release-24.3.12-rc: release-24.3: streamclient: add internal app name prefix
2 parents 92db8fd + d620137 commit cde00dd

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

pkg/ccl/crosscluster/physical/testdata/simple

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ postgres://root@?redacted
3232

3333
# The session on the source should have an app name set.
3434
query-sql as=source-system
35-
SELECT application_name FROM [SHOW SESSIONS] WHERE application_name LIKE '%repstream%' LIMIT 1
35+
SELECT application_name FROM [SHOW ALL SESSIONS] WHERE application_name LIKE '%repstream%' LIMIT 1
3636
----
37-
repstream job id=$_producerJobID
37+
$ internal repstream job id=$_producerJobID
3838

3939

4040
query-sql as=source-system

pkg/ccl/crosscluster/streamclient/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ go_library(
2525
"//pkg/sql/catalog/descs",
2626
"//pkg/sql/isql",
2727
"//pkg/sql/pgwire/pgcode",
28+
"//pkg/sql/sem/catconstants",
2829
"//pkg/util/ctxgroup",
2930
"//pkg/util/hlc",
3031
"//pkg/util/log",

pkg/ccl/crosscluster/streamclient/client.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/cockroachdb/cockroach/pkg/roachpb"
1717
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descs"
1818
"github.com/cockroachdb/cockroach/pkg/sql/isql"
19+
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
1920
"github.com/cockroachdb/cockroach/pkg/util/hlc"
2021
"github.com/cockroachdb/cockroach/pkg/util/log"
2122
"github.com/cockroachdb/cockroach/pkg/util/span"
@@ -317,11 +318,13 @@ type options struct {
317318
}
318319

319320
func (o *options) appName() string {
320-
const appNameBase = "repstream"
321+
// NOTE: use an internal app name prefix so that the sql.*.internal metrics
322+
// are used instead of the user facing metrics. The logic responsible for
323+
// picking the metric family lives in conn_executor.go:SetupConn.
321324
if o.streamID != 0 {
322-
return fmt.Sprintf("%s job id=%d", appNameBase, o.streamID)
325+
return fmt.Sprintf("%s repstream job id=%d", catconstants.InternalAppNamePrefix, o.streamID)
323326
} else {
324-
return appNameBase
327+
return fmt.Sprintf("%s repstream", catconstants.InternalAppNamePrefix)
325328
}
326329
}
327330

pkg/ccl/crosscluster/streamclient/client_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,21 @@ func ExampleClient() {
340340
// kv: "key_1"->value_1@1
341341
// resolved 100
342342
}
343+
344+
func TestStreamClientAppName(t *testing.T) {
345+
defer leaktest.AfterTest(t)()
346+
defer log.Scope(t).Close(t)
347+
348+
expectAppName := func(t *testing.T, name string, options ...Option) {
349+
o := processOptions(options)
350+
cfg, err := setupPGXConfig(&url.URL{
351+
Scheme: "postgresql",
352+
Host: "localhost:26257",
353+
}, o)
354+
require.NoError(t, err)
355+
require.Equal(t, name, cfg.RuntimeParams["application_name"])
356+
}
357+
358+
expectAppName(t, "$ internal repstream")
359+
expectAppName(t, "$ internal repstream job id=1337", WithStreamID(1337))
360+
}

0 commit comments

Comments
 (0)