Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve] Add admin api HealthCheckWithTopicVersion #1200

Merged
merged 5 commits into from
Apr 9, 2024
Merged
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
1 change: 1 addition & 0 deletions integration-tests/tokens/admin-token
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhZG1pbiJ9.MKSR5Mb2wu_FQlMYACv2i4ubMCn4h4Dj_aIDo1dPsDk
12 changes: 10 additions & 2 deletions pulsaradmin/pkg/admin/brokers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ type Brokers interface {
// GetAllDynamicConfigurations returns values of all overridden dynamic-configs
GetAllDynamicConfigurations() (map[string]string, error)

// HealthCheck run a health check on the broker
// Deprecated: Use HealthCheckWithTopicVersion instead
HealthCheck() error

// HealthCheckWithTopicVersion run a health check on the broker
HealthCheckWithTopicVersion(utils.TopicVersion) error
}

type broker struct {
Expand Down Expand Up @@ -142,9 +145,14 @@ func (b *broker) GetAllDynamicConfigurations() (map[string]string, error) {
}

func (b *broker) HealthCheck() error {
return b.HealthCheckWithTopicVersion(utils.TopicVersionV1)
}
func (b *broker) HealthCheckWithTopicVersion(topicVersion utils.TopicVersion) error {
endpoint := b.pulsar.endpoint(b.basePath, "/health")

buf, err := b.pulsar.Client.GetWithQueryParams(endpoint, nil, nil, false)
buf, err := b.pulsar.Client.GetWithQueryParams(endpoint, nil, map[string]string{
"topicVersion": topicVersion.String(),
}, false)
if err != nil {
return err
}
Expand Down
44 changes: 44 additions & 0 deletions pulsaradmin/pkg/admin/brokers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package admin

import (
"os"
"testing"

"github.com/apache/pulsar-client-go/pulsaradmin/pkg/admin/config"
"github.com/apache/pulsar-client-go/pulsaradmin/pkg/utils"
"github.com/stretchr/testify/assert"
)

func TestBrokerHealthCheckWithTopicVersion(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().HealthCheck()
assert.NoError(t, err)
err = admin.Brokers().HealthCheckWithTopicVersion(utils.TopicVersionV1)
assert.NoError(t, err)
err = admin.Brokers().HealthCheckWithTopicVersion(utils.TopicVersionV2)
assert.NoError(t, err)
}
11 changes: 11 additions & 0 deletions pulsaradmin/pkg/utils/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,14 @@ type GetStatsOptions struct {
ExcludePublishers bool `json:"exclude_publishers"`
ExcludeConsumers bool `json:"exclude_consumers"`
}

type TopicVersion string

const (
TopicVersionV1 TopicVersion = "V1"
TopicVersionV2 TopicVersion = "V2"
)

func (t TopicVersion) String() string {
return string(t)
}
Loading