GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(pubsub): add publish start time to client telemetry header by tonyyyycui · Pull Request #14496 · googleapis/google-cloud-java

feat(pubsub): add publish start time to client telemetry header #14496

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.

Sign up for GitHub

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

Merged
tonyyyycui merged 2 commits into googleapis:main from tonyyyycui:publish-telemetry-start-time
Sep 25, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(pubsub): add publish start time to client telemetry header #14496

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
815e8e7
feat(pubsub): add publish start time to client telemetry header
Sep 23, 2026
6880afd
chore: trigger kokoro presubmit
Sep 24, 2026
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 4 additions & 0 deletions 4 java-pubsub/google-cloud-pubsub/pom.xml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-common-protos</artifactId>
Expand Down
9 changes: 7 additions & 2 deletions 9 java-pubsub/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.protobuf.CodedOutputStream;
import com.google.protobuf.util.Timestamps;
import com.google.pubsub.v1.PublishRequest;
import com.google.pubsub.v1.PublishResponse;
import com.google.pubsub.v1.PubsubClientTelemetry;
Expand Down Expand Up @@ -546,12 +547,14 @@ private void publishAllWithoutInflightForKey(final String orderingKey) {
}
}

private Map<String, List<String>> createTelemetryHeader(int attemptNumber) {
private Map<String, List<String>> createTelemetryHeader(
long publishBatchStartTime, int attemptNumber) {
PubsubClientTelemetry telemetry =
PubsubClientTelemetry.newBuilder()
.setPublishOperation(
PubsubClientTelemetry.PublishOperation.newBuilder()
.setHedgedAttemptCount(attemptNumber)
.setPublishStartTime(Timestamps.fromMillis(publishBatchStartTime))
.build())
.build();
String encodedHeader = Base64.getEncoder().encodeToString(telemetry.toByteArray());
Expand Down Expand Up @@ -579,7 +582,9 @@ private ApiFuture<PublishResponse> publishCall(
outstandingBatch.getMessageWrappers().get(0));
context = context.withRetryableCodes(Collections.<StatusCode.Code>emptySet());
}
context = context.withExtraHeaders(createTelemetryHeader(attemptNumber));
context =
context.withExtraHeaders(
createTelemetryHeader(outstandingBatch.creationTime, attemptNumber));
int numMessagesInBatch = outstandingBatch.size();
List<PubsubMessage> pubsubMessagesList = new ArrayList<PubsubMessage>(numMessagesInBatch);
List<PubsubMessageWrapper> messageWrappers = outstandingBatch.getMessageWrappers();
Expand Down
14 changes: 14 additions & 0 deletions 14 ...ubsub/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.cloud.pubsub.v1.Publisher.Builder;
import com.google.protobuf.ByteString;
import com.google.protobuf.Timestamp;
import com.google.protobuf.util.Timestamps;
import com.google.pubsub.v1.ProjectTopicName;
import com.google.pubsub.v1.PublishRequest;
import com.google.pubsub.v1.PublishResponse;
Expand Down Expand Up @@ -1754,12 +1756,15 @@ public void testTelemetryHeaderOnNormalPublish() throws Exception {
testPublisherServiceImpl.setAutoPublishResponse(true);
Publisher publisher =
getTestPublisherBuilder()
.setClock(fakeExecutor.getClock())
.setBatchingSettings(
Publisher.Builder.DEFAULT_BATCHING_SETTINGS.toBuilder()
.setElementCountThreshold(1L)
.build())
.build();

fakeExecutor.advanceTime(Duration.ofSeconds(60));
Timestamp expectedStartTime = Timestamps.fromMillis(fakeExecutor.getClock().millisTime());
ApiFuture<String> future = sendTestMessage(publisher, "msg-normal");
assertEquals("1", future.get(5, TimeUnit.SECONDS));

Expand All @@ -1769,6 +1774,7 @@ public void testTelemetryHeaderOnNormalPublish() throws Exception {
PubsubClientTelemetry telemetry = extractTelemetryHeader(capturedHeaders.get(0));
assertThat(telemetry.hasPublishOperation()).isTrue();
assertThat(telemetry.getPublishOperation().getHedgedAttemptCount()).isEqualTo(0);
assertThat(telemetry.getPublishOperation().getPublishStartTime()).isEqualTo(expectedStartTime);

shutdownTestPublisher(publisher);
}
Expand All @@ -1778,6 +1784,9 @@ public void testTelemetryHeaderOnHedgedPublish() throws Exception {
Publisher publisher = getPublisherWithHedge(Duration.ofMillis(100), 0.2f, 20);
fillTokenBucket(publisher, 5);

fakeExecutor.advanceTime(Duration.ofSeconds(60));
Timestamp expectedStartTime = Timestamps.fromMillis(fakeExecutor.getClock().millisTime());

// Delay response so hedge fires
testPublisherServiceImpl.setAutoPublishResponse(false);
testPublisherServiceImpl.setPublishResponseDelay(Duration.ofMillis(200));
Expand All @@ -1801,11 +1810,16 @@ public void testTelemetryHeaderOnHedgedPublish() throws Exception {
// Verify Attempt 0 (Original)
PubsubClientTelemetry initialTelemetry = extractTelemetryHeader(capturedHeaders.get(0));
assertThat(initialTelemetry.getPublishOperation().getHedgedAttemptCount()).isEqualTo(0);
assertThat(initialTelemetry.getPublishOperation().getPublishStartTime())
.isEqualTo(expectedStartTime);

// Verify Attempt 1 (Hedge)
PubsubClientTelemetry hedgedTelemetry = extractTelemetryHeader(capturedHeaders.get(1));
assertThat(hedgedTelemetry.getPublishOperation().getHedgedAttemptCount()).isEqualTo(1);

assertThat(hedgedTelemetry.getPublishOperation().getPublishStartTime())
.isEqualTo(initialTelemetry.getPublishOperation().getPublishStartTime());

shutdownTestPublisher(publisher);
}
}
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.