Copilot commented on code in PR #1425:
URL: https://github.com/apache/pulsar-client-go/pull/1425#discussion_r2415672449
##########
pulsaradmin/pkg/admin/subscription.go:
##########
@@ -34,50 +35,93 @@ import (
// Subscriptions is admin interface for subscriptions management
type Subscriptions interface {
- // Create a new subscription on a topic
+ // Create creates a new subscription on a topic
Create(utils.TopicName, string, utils.MessageID) error
- // Delete a subscription.
- // Delete a persistent subscription from a topic. There should not be
any active consumers on the subscription
+ // CreateWithContext creates a new subscription on a topic
+ CreateWithContext(context.Context, utils.TopicName, string,
utils.MessageID) error
+
+ // Delete deletes a persistent subscription from a topic. There should
not be any active consumers on the subscription
Delete(utils.TopicName, string) error
+ // DeleteWithContext deletes a persistent subscription from a topic.
There should not be any active consumers on the subscription
+ DeleteWithContext(context.Context, utils.TopicName, string) error
+
// ForceDelete deletes a subscription forcefully
ForceDelete(utils.TopicName, string) error
+ // ForceDeleteWithContext deletes a subscription forcefully
+ ForceDeleteWithContext(context.Context, utils.TopicName, string) error
+
// List returns the list of subscriptions
List(utils.TopicName) ([]string, error)
+ // ListWithContext returns the list of subscriptions
+ ListWithContext(context.Context, utils.TopicName) ([]string, error)
+
// ResetCursorToMessageID resets cursor position on a topic subscription
// @param
// messageID reset subscription to messageId (or previous nearest
messageId if given messageId is not valid)
ResetCursorToMessageID(utils.TopicName, string, utils.MessageID) error
+ // ResetCursorToMessageIDWithContext resets cursor position on a topic
subscriptio
Review Comment:
Corrected spelling of 'subscriptio' to 'subscription'.
```suggestion
// ResetCursorToMessageIDWithContext resets cursor position on a topic
subscription
```
##########
pulsaradmin/pkg/admin/schema.go:
##########
@@ -183,20 +212,32 @@ func (s *schemas) CreateSchemaByPayload(topic string,
schemaPayload utils.PostSc
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(),
topicName.GetNamespace(),
topicName.GetLocalName(), "schema")
- return s.pulsar.Client.Post(endpoint, &schemaPayload)
+ return s.pulsar.Client.Post(ctx, endpoint, &schemaPayload)
}
func (s *schemas) CreateSchemaBySchemaInfo(topic string, schemaInfo
utils.SchemaInfo) error {
+ return s.CreateSchemaBySchemaInfoWithContext(context.Background(),
topic, schemaInfo)
+}
+
+func (s *schemas) CreateSchemaBySchemaInfoWithContext(ctx context.Context,
topic string, schemaInfo utils.SchemaInfo) error {
schemaPayload := utils.ConvertSchemaInfoToPostSchemaPayload(schemaInfo)
return s.CreateSchemaByPayload(topic, schemaPayload)
}
func (s *schemas) GetVersionBySchemaInfo(topic string, schemaInfo
utils.SchemaInfo) (int64, error) {
+ return s.GetVersionBySchemaInfoWithContext(context.Background(), topic,
schemaInfo)
+}
+
+func (s *schemas) GetVersionBySchemaInfoWithContext(ctx context.Context, topic
string, schemaInfo utils.SchemaInfo) (int64, error) {
schemaPayload := utils.ConvertSchemaInfoToPostSchemaPayload(schemaInfo)
return s.GetVersionByPayload(topic, schemaPayload)
Review Comment:
The method should call `GetVersionByPayloadWithContext` instead of
`GetVersionByPayload` to properly pass through the context parameter.
```suggestion
return s.GetVersionByPayloadWithContext(ctx, topic, schemaPayload)
```
##########
pulsaradmin/pkg/admin/cluster.go:
##########
@@ -74,69 +112,118 @@ func (c *pulsarClient) Clusters() Clusters {
}
func (c *clusters) List() ([]string, error) {
+ return c.ListWithContext(context.Background())
+}
+
+func (c *clusters) ListWithContext(ctx context.Context) ([]string, error) {
var clusters []string
- err := c.pulsar.Client.Get(c.pulsar.endpoint(c.basePath), &clusters)
+ err := c.pulsar.Client.Get(ctx, c.pulsar.endpoint(c.basePath),
&clusters)
return clusters, err
}
func (c *clusters) Get(name string) (utils.ClusterData, error) {
+ return c.GetWithContext(context.Background(), name)
+}
+
+func (c *clusters) GetWithContext(ctx context.Context, name string)
(utils.ClusterData, error) {
cdata := utils.ClusterData{}
endpoint := c.pulsar.endpoint(c.basePath, name)
- err := c.pulsar.Client.Get(endpoint, &cdata)
+ err := c.pulsar.Client.Get(ctx, endpoint, &cdata)
return cdata, err
}
func (c *clusters) Create(cdata utils.ClusterData) error {
+ return c.CreateWithContext(context.Background(), cdata)
+}
+
+func (c *clusters) CreateWithContext(ctx context.Context, cdata
utils.ClusterData) error {
endpoint := c.pulsar.endpoint(c.basePath, cdata.Name)
- return c.pulsar.Client.Put(endpoint, &cdata)
+ return c.pulsar.Client.Put(ctx, endpoint, &cdata)
}
func (c *clusters) Delete(name string) error {
+ return c.DeleteWithContext(context.Background(), name)
+}
+
+func (c *clusters) DeleteWithContext(ctx context.Context, name string) error {
endpoint := c.pulsar.endpoint(c.basePath, name)
- return c.pulsar.Client.Delete(endpoint)
+ return c.pulsar.Client.Delete(ctx, endpoint)
}
func (c *clusters) Update(cdata utils.ClusterData) error {
+ return c.UpdateWithContext(context.Background(), cdata)
+}
+
+func (c *clusters) UpdateWithContext(ctx context.Context, cdata
utils.ClusterData) error {
endpoint := c.pulsar.endpoint(c.basePath, cdata.Name)
- return c.pulsar.Client.Post(endpoint, &cdata)
+ return c.pulsar.Client.Post(ctx, endpoint, &cdata)
}
func (c *clusters) GetPeerClusters(name string) ([]string, error) {
+ return c.GetPeerClustersWithContext(context.Background(), name)
+}
+
+func (c *clusters) GetPeerClustersWithContext(ctx context.Context, name
string) ([]string, error) {
var peerClusters []string
endpoint := c.pulsar.endpoint(c.basePath, name, "peers")
- err := c.pulsar.Client.Get(endpoint, &peerClusters)
+ err := c.pulsar.Client.Get(ctx, endpoint, &peerClusters)
return peerClusters, err
}
func (c *clusters) UpdatePeerClusters(cluster string, peerClusters []string)
error {
+ return c.UpdatePeerClustersWithContext(context.Background(), cluster,
peerClusters)
+}
+
+func (c *clusters) UpdatePeerClustersWithContext(ctx context.Context, cluster
string, peerClusters []string) error {
endpoint := c.pulsar.endpoint(c.basePath, cluster, "peers")
- return c.pulsar.Client.Post(endpoint, peerClusters)
+ return c.pulsar.Client.Post(ctx, endpoint, peerClusters)
}
func (c *clusters) CreateFailureDomain(data utils.FailureDomainData) error {
+ return c.CreateFailureDomainWithContext(context.Background(), data)
+}
+
+func (c *clusters) CreateFailureDomainWithContext(ctx context.Context, data
utils.FailureDomainData) error {
endpoint := c.pulsar.endpoint(c.basePath, data.ClusterName,
"failureDomains", data.DomainName)
- return c.pulsar.Client.Post(endpoint, &data)
+ return c.pulsar.Client.Post(ctx, endpoint, &data)
}
func (c *clusters) GetFailureDomain(clusterName string, domainName string)
(utils.FailureDomainData, error) {
+ return c.GetFailureDomainWithContext(context.Background(), clusterName,
domainName)
+}
+
+func (c *clusters) GetFailureDomainWithContext(ctx context.Context,
clusterName string, domainName string) (utils.FailureDomainData, error) {
var res utils.FailureDomainData
endpoint := c.pulsar.endpoint(c.basePath, clusterName,
"failureDomains", domainName)
- err := c.pulsar.Client.Get(endpoint, &res)
+ err := c.pulsar.Client.Get(ctx, endpoint, &res)
return res, err
}
func (c *clusters) ListFailureDomains(clusterName string)
(utils.FailureDomainMap, error) {
+ return c.ListFailureDomainsWithContext(context.Background(),
clusterName)
+}
+
+func (c *clusters) ListFailureDomainsWithContext(ctx context.Context,
clusterName string) (utils.FailureDomainMap, error) {
var domainData utils.FailureDomainMap
endpoint := c.pulsar.endpoint(c.basePath, clusterName, "failureDomains")
- err := c.pulsar.Client.Get(endpoint, &domainData)
+ err := c.pulsar.Client.Get(ctx, endpoint, &domainData)
return domainData, err
}
func (c *clusters) DeleteFailureDomain(data utils.FailureDomainData) error {
+ return c.DeleteFailureDomainWithContext(context.TODO(), data)
Review Comment:
Use `context.Background()` instead of `context.TODO()` for consistency with
other methods in this PR. `context.TODO()` should only be used when it's
unclear which context to use, but here the pattern is clearly established.
```suggestion
return c.DeleteFailureDomainWithContext(context.Background(), data)
```
##########
pulsaradmin/pkg/admin/subscription.go:
##########
@@ -191,6 +279,10 @@ func (s *subscriptions) peekNthMessage(topic
utils.TopicName, sName string, pos
}
func (s *subscriptions) GetMessageByID(topic utils.TopicName, ledgerID,
entryID int64) (*utils.Message, error) {
+ return s.GetMessageByIDWithContext(context.Background(), topic,
ledgerID, entryID)
+}
+
+func (s *subscriptions) GetMessageByIDWithContext(ctx context.Context, topic
utils.TopicName, ledgerID, entryID int64) (*utils.Message, error) {
messages, err := s.GetMessagesByID(topic, ledgerID, entryID)
Review Comment:
The `GetMessageByIDWithContext` method should call
`GetMessagesByIDWithContext` instead of `GetMessagesByID` to properly pass
through the context parameter.
```suggestion
messages, err := s.GetMessagesByIDWithContext(ctx, topic, ledgerID,
entryID)
```
##########
pulsaradmin/pkg/admin/schema.go:
##########
@@ -183,20 +212,32 @@ func (s *schemas) CreateSchemaByPayload(topic string,
schemaPayload utils.PostSc
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(),
topicName.GetNamespace(),
topicName.GetLocalName(), "schema")
- return s.pulsar.Client.Post(endpoint, &schemaPayload)
+ return s.pulsar.Client.Post(ctx, endpoint, &schemaPayload)
}
func (s *schemas) CreateSchemaBySchemaInfo(topic string, schemaInfo
utils.SchemaInfo) error {
+ return s.CreateSchemaBySchemaInfoWithContext(context.Background(),
topic, schemaInfo)
+}
+
+func (s *schemas) CreateSchemaBySchemaInfoWithContext(ctx context.Context,
topic string, schemaInfo utils.SchemaInfo) error {
schemaPayload := utils.ConvertSchemaInfoToPostSchemaPayload(schemaInfo)
return s.CreateSchemaByPayload(topic, schemaPayload)
Review Comment:
The method should call `CreateSchemaByPayloadWithContext` instead of
`CreateSchemaByPayload` to properly pass through the context parameter.
```suggestion
return s.CreateSchemaByPayloadWithContext(ctx, topic, schemaPayload)
```
##########
pulsaradmin/pkg/admin/schema.go:
##########
@@ -206,17 +247,27 @@ func (s *schemas) GetVersionByPayload(topic string,
schemaPayload utils.PostSche
}{}
endpoint := s.pulsar.endpoint(s.basePath, topicName.GetTenant(),
topicName.GetNamespace(),
topicName.GetLocalName(), "version")
- err = s.pulsar.Client.PostWithObj(endpoint, &schemaPayload, &version)
+ err = s.pulsar.Client.PostWithObj(ctx, endpoint, &schemaPayload,
&version)
return version.Version, err
}
func (s *schemas) TestCompatibilityWithSchemaInfo(topic string,
+ schemaInfo utils.SchemaInfo) (*utils.IsCompatibility, error) {
+ return
s.TestCompatibilityWithSchemaInfoWithContext(context.Background(), topic,
schemaInfo)
+}
+
+func (s *schemas) TestCompatibilityWithSchemaInfoWithContext(ctx
context.Context, topic string,
schemaInfo utils.SchemaInfo) (*utils.IsCompatibility, error) {
schemaPayload := utils.ConvertSchemaInfoToPostSchemaPayload(schemaInfo)
- return s.TestCompatibilityWithPostSchemaPayload(topic, schemaPayload)
+ return s.TestCompatibilityWithPostSchemaPayloadWithContext(ctx, topic,
schemaPayload)
Review Comment:
The method should call `TestCompatibilityWithPostSchemaPayloadWithContext`
with the context parameter, but the context parameter `ctx` is passed correctly
here. However, check that this method exists and accepts the context parameter.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]