Skip to content

Commit

Permalink
BES: Use WKPs for timestamp/duration values
Browse files Browse the repository at this point in the history
Closes bazelbuild#13181.

PiperOrigin-RevId: 369280119
  • Loading branch information
Yannic authored and copybara-github committed Apr 19, 2021
1 parent 5fa4719 commit e5c832a
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ java_library(
"//third_party:guava",
"//third_party:jsr305",
"@com_google_protobuf//:protobuf_java",
"@com_google_protobuf//java/util",
],
)

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/analysis/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ java_library(
"//third_party:guava",
"//third_party:jsr305",
"//third_party/protobuf:protobuf_java",
"//third_party/protobuf:protobuf_java_util",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.skyframe.SkyValue;
import com.google.protobuf.util.Durations;
import java.util.Collection;
import java.util.function.Function;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -434,6 +435,7 @@ public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext convert
builder.addAllOutputGroup(getOutputFilesByGroup(converters.artifactGroupNamer()));

if (isTest) {
builder.setTestTimeout(Durations.fromSeconds(testTimeoutSeconds));
builder.setTestTimeoutSeconds(testTimeoutSeconds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
import com.google.devtools.build.lib.view.test.TestStatus.TestResultData;
import com.google.protobuf.util.Durations;
import com.google.protobuf.util.Timestamps;
import java.util.Collection;
import java.util.List;

Expand Down Expand Up @@ -219,7 +221,9 @@ public BuildEventStreamProtos.TestResult asTestResult(BuildEventContext converte
builder.setStatusDetails(statusDetails);
builder.setExecutionInfo(executionInfo);
builder.setCachedLocally(cachedLocally);
builder.setTestAttemptStart(Timestamps.fromMillis(startTimeMillis));
builder.setTestAttemptStartMillisEpoch(startTimeMillis);
builder.setTestAttemptDuration(Durations.fromMillis(durationMillis));
builder.setTestAttemptDurationMillis(durationMillis);
builder.addAllWarning(testWarnings);
for (Pair<String, Path> file : files) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ java_library(
"//third_party:jsr305",
"//third_party:netty",
"//third_party/protobuf:protobuf_java",
"//third_party/protobuf:protobuf_java_util",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEventId;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.protobuf.util.Timestamps;
import java.util.Collection;

/**
Expand Down Expand Up @@ -80,6 +81,7 @@ public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext convert
BuildEventStreamProtos.BuildFinished.newBuilder()
.setOverallSuccess(ExitCode.SUCCESS.equals(exitCode))
.setExitCode(protoExitCode)
.setFinishTime(Timestamps.fromMillis(finishTimeMillis))
.setFinishTimeMillis(finishTimeMillis)
.setAnomalyReport(protoAnamolyReport)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ proto_library(
"//src/main/protobuf:command_line_proto",
"//src/main/protobuf:failure_details_proto",
"//src/main/protobuf:invocation_policy_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ syntax = "proto3";

package build_event_stream;

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "src/main/protobuf/command_line.proto";
import "src/main/protobuf/failure_details.proto";
import "src/main/protobuf/invocation_policy.proto";
Expand Down Expand Up @@ -321,9 +323,14 @@ message BuildStarted {
string uuid = 1;

// Start of the build in ms since the epoch.
// TODO(buchgr): Use google.protobuf.TimeStamp once bazel's protoc supports
// it.
int64 start_time_millis = 2;
//
// Deprecated, use `start_time` instead.
//
// TODO(yannic): Remove.
int64 start_time_millis = 2 [deprecated = true];

// Start of the build.
google.protobuf.Timestamp start_time = 9;

// Version of the build tool that is running.
string build_tool_version = 3;
Expand Down Expand Up @@ -575,7 +582,14 @@ message TargetComplete {
repeated string tag = 3;

// The timeout specified for test actions under this configured target.
int64 test_timeout_seconds = 7;
//
// Deprecated, use `test_timeout` instead.
//
// TODO(yannic): Remove.
int64 test_timeout_seconds = 7 [deprecated = true];

// The timeout specified for test actions under this configured target.
google.protobuf.Duration test_timeout = 10;

// Failure information about the target, only populated if success is false,
// and sometimes not even then. Equal to one of the ActionExecuted
Expand Down Expand Up @@ -612,11 +626,28 @@ message TestResult {
// Time in milliseconds since the epoch at which the test attempt was started.
// Note: for cached test results, this is time can be before the start of the
// build.
int64 test_attempt_start_millis_epoch = 6;
//
// Deprecated, use `test_attempt_start` instead.
//
// TODO(yannic): Remove.
int64 test_attempt_start_millis_epoch = 6 [deprecated = true];

// Time at which the test attempt was started.
// Note: for cached test results, this is time can be before the start of the
// build.
google.protobuf.Timestamp test_attempt_start = 10;

// Time the test took to run. For locally cached results, this is the time
// the cached invocation took when it was invoked.
//
// Deprecated, use `test_attempt_duration` instead.
//
// TODO(yannic): Remove.
int64 test_attempt_duration_millis = 3 [deprecated = true];

// Time the test took to run. For locally cached results, this is the time
// the cached invocation took when it was invoked.
int64 test_attempt_duration_millis = 3;
google.protobuf.Duration test_attempt_duration = 11;

// Files (logs, test.xml, undeclared outputs, etc) generated by that test
// action.
Expand All @@ -628,7 +659,7 @@ message TestResult {
// Message providing optional meta data on the execution of the test action,
// if available.
message ExecutionInfo {
// Deprecated, use TargetComplete.test_timeout_seconds instead.
// Deprecated, use TargetComplete.test_timeout instead.
int32 timeout_seconds = 1 [deprecated = true];

// Name of the strategy to execute this test action (e.g., "local",
Expand All @@ -647,11 +678,15 @@ message TestResult {

// Represents a hierarchical timing breakdown of an activity.
// The top level time should be the total time of the activity.
// Invariant: time_millis >= sum of time_millis of all direct children.
// Invariant: `time` >= sum of `time`s of all direct children.
message TimingBreakdown {
repeated TimingBreakdown child = 1;
string name = 2;
int64 time_millis = 3;
// Deprecated, use `time` instead.
//
// TODO(yannic): Remove.
int64 time_millis = 3 [deprecated = true];
google.protobuf.Duration time = 4;
}
TimingBreakdown timing_breakdown = 4;

Expand Down Expand Up @@ -689,13 +724,34 @@ message TestSummary {
int32 total_num_cached = 6;

// When the test first started running.
int64 first_start_time_millis = 7;
//
// Deprecated, use `first_start_time` instead.
//
// TODO(yannic): Remove.
int64 first_start_time_millis = 7 [deprecated = true];

// When the test first started running.
google.protobuf.Timestamp first_start_time = 13;

// When the last test action completed.
int64 last_stop_time_millis = 8;
//
// Deprecated, use `last_stop_time` instead.
//
// TODO(yannic): Remove.
int64 last_stop_time_millis = 8 [deprecated = true];

// When the test first started running.
google.protobuf.Timestamp last_stop_time = 14;

// The total runtime of the test.
//
// Deprecated, use `total_run` instead.
//
// TODO(yannic): Remove.
int64 total_run_duration_millis = 9 [deprecated = true];

// The total runtime of the test.
int64 total_run_duration_millis = 9;
google.protobuf.Duration total_run_duration = 12;
}

// Payload of the event summarizing a target (test or non-test).
Expand Down Expand Up @@ -739,10 +795,15 @@ message BuildFinished {
// ExitCode.code equals 0.
ExitCode exit_code = 3;

// Time in milliseconds since the epoch.
// TODO(buchgr): Use google.protobuf.Timestamp once bazel's protoc supports
// it.
int64 finish_time_millis = 2;
// End of the build in ms since the epoch.
//
// Deprecated, use `finish_time` instead.
//
// TODO(yannic): Remove.
int64 finish_time_millis = 2 [deprecated = true];

// End of the build.
google.protobuf.Timestamp finish_time = 5;

AnomalyReport anomaly_report = 4;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.devtools.build.lib.runtime.CommandEnvironment;
import com.google.devtools.build.lib.runtime.CommandLineEvent;
import com.google.devtools.build.lib.util.ProcessUtils;
import com.google.protobuf.util.Timestamps;
import java.util.Collection;

/**
Expand Down Expand Up @@ -101,6 +102,7 @@ public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext convert
BuildEventStreamProtos.BuildStarted.Builder started =
BuildEventStreamProtos.BuildStarted.newBuilder()
.setUuid(request.getId().toString())
.setStartTime(Timestamps.fromMillis(request.getStartTime()))
.setStartTimeMillis(request.getStartTime())
.setBuildToolVersion(BlazeVersionInfo.instance().getVersion())
.setOptionsDescription(request.getOptionsDescription())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus;
import com.google.devtools.build.lib.view.test.TestStatus.FailedTestCasesStatus;
import com.google.devtools.build.lib.view.test.TestStatus.TestCase;
import com.google.protobuf.util.Durations;
import com.google.protobuf.util.Timestamps;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -605,8 +607,11 @@ public BuildEventStreamProtos.BuildEvent asStreamProto(BuildEventContext convert
.setTotalRunCount(totalRuns())
.setRunCount(testParams.getRuns())
.setShardCount(testParams.getShards())
.setFirstStartTime(Timestamps.fromMillis(firstStartTimeMillis))
.setFirstStartTimeMillis(firstStartTimeMillis)
.setLastStopTime(Timestamps.fromMillis(lastStopTimeMillis))
.setLastStopTimeMillis(lastStopTimeMillis)
.setTotalRunDuration(Durations.fromMillis(totalRunDurationMillis))
.setTotalRunDurationMillis(totalRunDurationMillis);
for (Path path : getFailedLogs()) {
String uri = pathConverter.apply(path);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ java_test(
"//third_party:junit4",
"//third_party:mockito",
"//third_party:truth",
"//third_party/protobuf",
"//third_party/protobuf:protobuf_java",
"@com_google_protobuf//java/util",
"@com_google_testparameterinjector//:testparameterinjector",
],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import com.google.devtools.build.lib.view.test.TestStatus.FailedTestCasesStatus;
import com.google.devtools.build.lib.view.test.TestStatus.TestCase;
import com.google.devtools.build.lib.view.test.TestStatus.TestCase.Status;
import com.google.protobuf.util.Durations;
import com.google.protobuf.util.Timestamps;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -277,8 +279,11 @@ public void testAsStreamProto() throws Exception {
BuildEventStreamProtos.TestSummary.newBuilder()
.setOverallStatus(TestStatus.FAILED)
.setFirstStartTimeMillis(1000)
.setFirstStartTime(Timestamps.fromMillis(1000))
.setLastStopTimeMillis(1300)
.setLastStopTime(Timestamps.fromMillis(1300))
.setTotalRunDurationMillis(300)
.setTotalRunDuration(Durations.fromMillis(300))
.setRunCount(2)
.setShardCount(3)
.addPassed(BuildEventStreamProtos.File.newBuilder().setUri("/path/to/apple"))
Expand Down

0 comments on commit e5c832a

Please sign in to comment.