From 83cfaa2bd48177d58ca5b337b8d942f57da8d365 Mon Sep 17 00:00:00 2001 From: labuladong Date: Tue, 25 Jun 2024 17:19:23 +0800 Subject: [PATCH 1/2] fix dynamic config --- pulsaradmin/pkg/admin/admin.go | 5 +++++ pulsaradmin/pkg/admin/brokers.go | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pulsaradmin/pkg/admin/admin.go b/pulsaradmin/pkg/admin/admin.go index a22b22c62d..0b1b96254e 100644 --- a/pulsaradmin/pkg/admin/admin.go +++ b/pulsaradmin/pkg/admin/admin.go @@ -112,3 +112,8 @@ func (c *pulsarClient) endpoint(componentPath string, parts ...string) string { path.Join(escapedParts...), ) } + +// this function won't do any escaping +func (c *pulsarClient) endpointWithFullPath(componentPath string, fullPath string) string { + return path.Join(utils.MakeHTTPPath(c.APIVersion.String(), componentPath), fullPath) +} diff --git a/pulsaradmin/pkg/admin/brokers.go b/pulsaradmin/pkg/admin/brokers.go index 7dcea800e3..8ac400fd72 100644 --- a/pulsaradmin/pkg/admin/brokers.go +++ b/pulsaradmin/pkg/admin/brokers.go @@ -19,7 +19,6 @@ package admin import ( "fmt" - "net/url" "strings" "github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils" @@ -120,8 +119,8 @@ func (b *broker) GetOwnedNamespaces(cluster, brokerURL string) (map[string]utils } func (b *broker) UpdateDynamicConfiguration(configName, configValue string) error { - value := url.QueryEscape(configValue) - endpoint := b.pulsar.endpoint(b.basePath, "/configuration/", configName, value) + value := fmt.Sprintf("/configuration/%s/%s", configName, configValue) + endpoint := b.pulsar.endpointWithFullPath(b.basePath, value) return b.pulsar.Client.Post(endpoint, nil) } From 579f9ea286691f1edda0279ac9f2cfc428c22956 Mon Sep 17 00:00:00 2001 From: labuladong Date: Tue, 25 Jun 2024 17:50:51 +0800 Subject: [PATCH 2/2] add test --- pulsaradmin/pkg/admin/brokers_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pulsaradmin/pkg/admin/brokers_test.go b/pulsaradmin/pkg/admin/brokers_test.go index 3ae9e4aec9..5be90f6c34 100644 --- a/pulsaradmin/pkg/admin/brokers_test.go +++ b/pulsaradmin/pkg/admin/brokers_test.go @@ -73,3 +73,21 @@ func TestGetAllActiveBrokers(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, brokers) } + +func TestUpdateDynamicConfiguration(t *testing.T) { + readFile, err := os.ReadFile("../../../integration-tests/tokens/admin-token") + assert.NoError(t, err) + cfg := &config.Config{ + Token: string(readFile), + } + admin, err := New(cfg) + assert.NoError(t, err) + assert.NotNil(t, admin) + + err = admin.Brokers().UpdateDynamicConfiguration("allowAutoSubscriptionCreation", "true") + assert.NoError(t, err) + + configurations, err := admin.Brokers().GetDynamicConfigurationNames() + assert.NoError(t, err) + assert.NotEmpty(t, configurations) +}