Skip to content

Commit

Permalink
Move stat pb out as a separate library
Browse files Browse the repository at this point in the history
Move the stat protobuf message out of stats as a separate library to
make it easier for other proto to import stat while avoid having
circular dependency with stats.proto.

Bug: b/295363989
Test: Run post-submit Kokoro CI jobs to make sure rbe_metrics are
correctly generated.

Change-Id: I4e4c9c39819f55149c74182546eeaeb4960a4093
GitOrigin-RevId: 028ed86c273643270ca22b50ec877adcd07fe309
  • Loading branch information
ywmei-brt1 authored and copybara-github committed Sep 14, 2023
1 parent eb9508e commit 1aa72ad
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 146 deletions.
23 changes: 23 additions & 0 deletions api/stat/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
name = "stat_proto",
srcs = ["stat.proto"],
visibility = ["//visibility:public"],
)

go_proto_library(
name = "stat_go_proto",
importpath = "team/foundry-x/re-client/api/stat",
proto = ":stat_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "stat",
embed = [":stat_go_proto"],
importpath = "team/foundry-x/re-client/api/stat",
visibility = ["//visibility:public"],
)
48 changes: 48 additions & 0 deletions api/stat/stat.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 Google LLC
//
// Licensed 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.

syntax = "proto3";

package stats;

// Outlier represents a command with an unusually large value in the stat.
message Outlier {
string command_id = 1;
int64 value = 2;
}

message Stat {
// The metric/stat name.
string name = 1;

// The number of all the true values for booleans, the sum of all the
// values for ints.
int64 count = 2;

message Value {
string name = 1;
int64 count = 2;
}
// For enum stats, the count of each value.
repeated Value counts_by_value = 3;

// A list of commands that have the highest values.
repeated Outlier outliers = 4;

int64 median = 5;
int64 percentile75 = 6;
int64 percentile85 = 7;
int64 percentile95 = 8;
double average = 9;
}
10 changes: 8 additions & 2 deletions api/stats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ proto_library(
name = "stats_proto",
srcs = ["stats.proto"],
visibility = ["//visibility:public"],
deps = ["//api/log:log_proto"],
deps = [
"//api/log:log_proto",
"//api/stat:stat_proto",
],
)

go_proto_library(
name = "stats_go_proto",
importpath = "team/foundry-x/re-client/api/stats",
proto = ":stats_proto",
visibility = ["//visibility:public"],
deps = ["//api/log"],
deps = [
"//api/log",
"//api/stat",
],
)

go_library(
Expand Down
32 changes: 1 addition & 31 deletions api/stats/stats.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ syntax = "proto3";
package stats;

import "api/log/log.proto";
import "api/stat/stat.proto";

// The full aggregated build stats and properties.
message Stats {
Expand Down Expand Up @@ -56,37 +57,6 @@ message Stats {
reserved 3, 8;
}

// Outlier represents a command with an unusually large value in the stat.
message Outlier {
string command_id = 1;
int64 value = 2;
}

message Stat {
// The metric/stat name.
string name = 1;

// The number of all the true values for booleans, the sum of all the
// values for ints.
int64 count = 2;

message Value {
string name = 1;
int64 count = 2;
}
// For enum stats, the count of each value.
repeated Value counts_by_value = 3;

// A list of commands that have the highest values.
repeated Outlier outliers = 4;

int64 median = 5;
int64 percentile75 = 6;
int64 percentile85 = 7;
int64 percentile95 = 8;
double average = 9;
}

message MachineInfo {
// Number of CPU cores that the machine has.
int64 num_cpu = 1;
Expand Down
2 changes: 2 additions & 0 deletions experiments/api/experiment/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ proto_library(
visibility = ["//visibility:public"],
deps = [
"//api/log:log_proto",
"//api/stat:stat_proto",
"//api/stats:stats_proto",
],
)
Expand All @@ -19,6 +20,7 @@ go_proto_library(
visibility = ["//visibility:public"],
deps = [
"//api/log",
"//api/stat",
"//api/stats",
],
)
Expand Down
1 change: 1 addition & 0 deletions experiments/api/experiment/experiment.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ syntax = "proto3";
package experiment;

import "api/log/log.proto";
import "api/stat/stat.proto";
import "api/stats/stats.proto";

// Experiment encapsulates all configuration required for running an experiment
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/stats/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ go_library(
visibility = ["//:__subpackages__"],
deps = [
"//api/log",
"//api/stat",
"//api/stats",
"//internal/pkg/labels",
"//internal/pkg/localresources",
Expand All @@ -31,6 +32,7 @@ go_test(
embed = [":stats"],
deps = [
"//api/log",
"//api/stat",
"//api/stats",
"@com_github_bazelbuild_remote_apis_sdks//go/api/command",
"@com_github_bazelbuild_remote_apis_sdks//go/pkg/command",
Expand Down
11 changes: 6 additions & 5 deletions internal/pkg/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"google.golang.org/protobuf/proto"

lpb "team/foundry-x/re-client/api/log"
stpb "team/foundry-x/re-client/api/stat"
spb "team/foundry-x/re-client/api/stats"

cpb "github.com/bazelbuild/remote-apis-sdks/go/api/command"
Expand Down Expand Up @@ -69,7 +70,7 @@ type Stat struct {
isMillis bool

// Commands that have the highest values.
Outlier1, Outlier2 *spb.Outlier
Outlier1, Outlier2 *stpb.Outlier

Median, Percentile75, Percentile85, Percentile95 int64
Average float64
Expand Down Expand Up @@ -292,7 +293,7 @@ func (stt *statTree) addNum(val int64, name, cmdID string, isMillis bool) {
if val == 0 {
return
}
cur := &spb.Outlier{CommandId: cmdID, Value: int64(val)}
cur := &stpb.Outlier{CommandId: cmdID, Value: int64(val)}
if st.Outlier1 == nil || val > st.Outlier1.Value {
st.Outlier2 = st.Outlier1
st.Outlier1 = cur
Expand Down Expand Up @@ -453,8 +454,8 @@ func CompletionStats(s *spb.Stats) string {
return ""
}

func statToProto(name string, s *Stat) *spb.Stat {
sPb := &spb.Stat{
func statToProto(name string, s *Stat) *stpb.Stat {
sPb := &stpb.Stat{
Name: name,
Count: s.Count,
Median: s.Median,
Expand All @@ -470,7 +471,7 @@ func statToProto(name string, s *Stat) *spb.Stat {
sort.Strings(keys)
for _, n := range keys {
v := s.CountByValue[n]
sPb.CountsByValue = append(sPb.CountsByValue, &spb.Stat_Value{Name: n, Count: v})
sPb.CountsByValue = append(sPb.CountsByValue, &stpb.Stat_Value{Name: n, Count: v})
}
if s.Outlier1 != nil {
sPb.Outliers = append(sPb.Outliers, s.Outlier1)
Expand Down
Loading

0 comments on commit 1aa72ad

Please sign in to comment.