Skip to content

Commit

Permalink
fix dynamic config (apache#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
labuladong authored Jun 25, 2024
1 parent a1ce5e6 commit a6e28dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pulsaradmin/pkg/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 2 additions & 3 deletions pulsaradmin/pkg/admin/brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package admin

import (
"fmt"
"net/url"
"strings"

"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 18 additions & 0 deletions pulsaradmin/pkg/admin/brokers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit a6e28dc

Please sign in to comment.