Skip to content

Commit 7a7db5b

Browse files
authored
[chore][exporter/googlecloudpubsub] update to cloud.google.com/go/pubsub/v2 (#44465)
#### Description Update to cloud.google.com/go/pubsub/v2 package to keep Renovate bot happy. This PR is scoped to the `exporter/googlepubsubexporter` #### Link to tracking issue This PR fixes renovate trying to upgrade but can't because it requires code changes: #42871 And remove the Pubsub part in the combined deprecation fix PR: #41646 #### Testing Changed existing test to match the new API. #### Documentation No documentation change required.
1 parent 026002a commit 7a7db5b

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

exporter/googlecloudpubsubexporter/exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"fmt"
1111
"time"
1212

13-
"cloud.google.com/go/pubsub/apiv1/pubsubpb"
13+
"cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
1414
"github.com/google/uuid"
1515
"go.opentelemetry.io/collector/component"
1616
"go.opentelemetry.io/collector/pdata/plog"

exporter/googlecloudpubsubexporter/exporter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12-
pb "cloud.google.com/go/pubsub/apiv1/pubsubpb"
12+
pb "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
1313
"github.com/google/uuid"
1414
"github.com/googleapis/gax-go/v2"
1515
"github.com/stretchr/testify/assert"

exporter/googlecloudpubsubexporter/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/google
33
go 1.24.0
44

55
require (
6-
cloud.google.com/go/pubsub v1.49.0
6+
cloud.google.com/go/pubsub/v2 v2.3.0
77
github.com/google/uuid v1.6.0
88
github.com/googleapis/gax-go/v2 v2.15.0
99
github.com/stretchr/testify v1.11.1

exporter/googlecloudpubsubexporter/go.sum

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/googlecloudpubsubexporter/publisher_client.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"context"
88
"fmt"
99

10-
pubsub "cloud.google.com/go/pubsub/apiv1"
11-
"cloud.google.com/go/pubsub/apiv1/pubsubpb"
10+
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
11+
"cloud.google.com/go/pubsub/v2/apiv1/pubsubpb"
1212
"github.com/googleapis/gax-go/v2"
1313
"google.golang.org/api/option"
1414
"google.golang.org/grpc"
@@ -18,7 +18,7 @@ import (
1818
// publisherClient subset of `pubsub.PublisherClient`
1919
type publisherClient interface {
2020
Close() error
21-
Publish(ctx context.Context, req *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error)
21+
Publish(ctx context.Context, in *pubsubpb.PublishRequest, opts ...gax.CallOption) (*pubsubpb.PublishResponse, error)
2222
}
2323

2424
// wrappedPublisherClient allows to override the close function
@@ -40,7 +40,8 @@ func newPublisherClient(ctx context.Context, config *Config, userAgent string) (
4040
return nil, fmt.Errorf("failed preparing the gRPC client options to PubSub: %w", err)
4141
}
4242

43-
client, err := pubsub.NewPublisherClient(ctx, clientOptions...)
43+
// In new v2 client the Publish is moved to the TopicAdmin client
44+
client, err := pubsub.NewTopicAdminClient(ctx, clientOptions...)
4445
if err != nil {
4546
return nil, fmt.Errorf("failed creating the gRPC client to PubSub: %w", err)
4647
}

exporter/googlecloudpubsubexporter/publisher_client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package googlecloudpubsubexporter
66
import (
77
"testing"
88

9-
pubsub "cloud.google.com/go/pubsub/apiv1"
9+
pubsub "cloud.google.com/go/pubsub/v2/apiv1"
1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
1212
"google.golang.org/api/option"
@@ -88,7 +88,7 @@ func TestNewPublisherClient(t *testing.T) {
8888
client, err := newPublisherClient(ctx, cfg, "test-user-agent 6789")
8989
assert.NoError(t, err)
9090
require.NotEmpty(t, client)
91-
assert.IsType(t, &pubsub.PublisherClient{}, client)
91+
assert.IsType(t, &pubsub.TopicAdminClient{}, client)
9292
assert.NoError(t, client.Close())
9393
})
9494

@@ -103,7 +103,7 @@ func TestNewPublisherClient(t *testing.T) {
103103
client, err := newPublisherClient(ctx, cfg, "test-user-agent 6789")
104104
assert.NoError(t, err)
105105
require.NotEmpty(t, client)
106-
assert.IsType(t, &pubsub.PublisherClient{}, client)
106+
assert.IsType(t, &pubsub.TopicAdminClient{}, client)
107107
assert.NoError(t, client.Close())
108108
})
109109

0 commit comments

Comments
 (0)