Skip to content
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.

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

[trivial] using buf, remove protoc gen #190

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,3 @@ jobs:
make examples
make test
make build

- name: Codecov
uses: codecov/codecov-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./acc.out
flags: unittests # optional
name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false)
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ GITHASH := `git rev-parse HEAD`
GITTAG := `git describe --tags --always`
LDFLAGS="-X github.com/gobench-io/gobench/master.gitCommit=$(GITHASH) -X github.com/gobench-io/gobench/master.gitTag=$(GITTAG)"

.PHONY: lint build examples ent pb

pb:
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false \
pb/agent.proto
protoc --go_out=. --go_opt=paths=source_relative \
--go-grpc_out=. --go-grpc_opt=paths=source_relative,require_unimplemented_servers=false \
pb/executor.proto
.PHONY: lint build examples ent

.PHONY: gen
gen:
Expand Down
21 changes: 10 additions & 11 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

api "github.com/gobench-io/gobench/v2/gen/go/pb"
"github.com/gobench-io/gobench/v2/logger"
"github.com/gobench-io/gobench/v2/pb"
"google.golang.org/grpc"
)

Expand All @@ -31,7 +30,7 @@ type Agent struct {
route string
clusterPort int

ml pb.AgentServer
ml api.AgentServer
logger logger.Logger
executorLogger io.WriteCloser // when running the executor, save log here
socket string // unix socket that the agent rpc server will listen at
Expand All @@ -42,7 +41,7 @@ type Agent struct {
heartbeatInterval time.Duration
}

func NewLocalAgent(ml pb.AgentServer, logger logger.Logger) (*Agent, error) {
func NewLocalAgent(ml api.AgentServer, logger logger.Logger) (*Agent, error) {
a := &Agent{
ml: ml,
logger: logger,
Expand All @@ -53,7 +52,7 @@ func NewLocalAgent(ml pb.AgentServer, logger logger.Logger) (*Agent, error) {
// NewAgent create a new agent instance.
// Deprecated, use NewAgentV2 instead
// todo: remove this in gobench@v2
func NewAgent(opts *Options, ml pb.AgentServer, logger logger.Logger) (*Agent, error) {
func NewAgent(opts *Options, ml api.AgentServer, logger logger.Logger) (*Agent, error) {
a := &Agent{
route: opts.Route,
clusterPort: opts.ClusterPort,
Expand All @@ -64,7 +63,7 @@ func NewAgent(opts *Options, ml pb.AgentServer, logger logger.Logger) (*Agent, e
return a, nil
}

func NewAgentV2(opts *Options, logger logger.Logger, ml pb.AgentServer, jdsClient api.JobDistributionServiceClient) (*Agent, error) {
func NewAgentV2(opts *Options, logger logger.Logger, ml api.AgentServer, jdsClient api.JobDistributionServiceClient) (*Agent, error) {
a := &Agent{
route: opts.Route,
clusterPort: opts.ClusterPort,
Expand Down Expand Up @@ -127,7 +126,7 @@ func (a *Agent) sendHeartbeat(ctx context.Context) error {
}

// SetMetricLogger sets metric logger property
func (a *Agent) SetMetricLogger(ml pb.AgentServer) {
func (a *Agent) SetMetricLogger(ml api.AgentServer) {
a.mu.Lock()
a.ml = ml
a.mu.Unlock()
Expand Down Expand Up @@ -160,7 +159,7 @@ func (a *Agent) StartSocketServer() error {
return err
}
s := grpc.NewServer()
pb.RegisterAgentServer(s, a.ml)
api.RegisterAgentServer(s, a.ml)

go s.Serve(l)

Expand Down Expand Up @@ -219,15 +218,15 @@ func (a *Agent) RunJob(ctx context.Context, executorPath string, appID int) (err
a.logger.Infow("local executor to run driver")

// todo: handle the response
if _, err = client.Start(ctx, &pb.StartRequest{}); err != nil {
if _, err = client.Start(ctx, &api.StartRequest{}); err != nil {
err = fmt.Errorf("rpc start: %v", err)
return
}

a.logger.Infow("local executor is shutting down")

// ignore error, since when the executor is terminated, this rpc will fail
_, _ = client.Terminate(ctx, &pb.TermRequest{})
_, _ = client.Terminate(ctx, &api.TermRequest{})

if err = cmd.Wait(); err != nil {
a.logger.Errorw("executor wait", "err", err)
Expand All @@ -238,7 +237,7 @@ func (a *Agent) RunJob(ctx context.Context, executorPath string, appID int) (err
}

func waitForReady(ctx context.Context, executorSock string, expiredIn time.Duration) (
pb.ExecutorClient, error,
api.ExecutorClient, error,
) {
timeout := time.After(expiredIn)
sleep := 10 * time.Millisecond
Expand All @@ -256,7 +255,7 @@ func waitForReady(ctx context.Context, executorSock string, expiredIn time.Durat
if err != nil {
continue
}
client := pb.NewExecutorClient(conn)
client := api.NewExecutorClient(conn)
return client, nil
}
}
Expand Down
14 changes: 7 additions & 7 deletions agent/metriclog.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ package agent
import (
"context"

"github.com/gobench-io/gobench/v2/pb"
api "github.com/gobench-io/gobench/v2/gen/go/pb"
)

// nop metric logger
type nopLog struct{}

func (n *nopLog) FindCreateGroup(context.Context, *pb.FCGroupReq) (*pb.FCGroupRes, error) {
func (n *nopLog) FindCreateGroup(context.Context, *api.FCGroupReq) (*api.FCGroupRes, error) {
return nil, nil
}

func (n *nopLog) FindCreateGraph(context.Context, *pb.FCGraphReq) (*pb.FCGraphRes, error) {
func (n *nopLog) FindCreateGraph(context.Context, *api.FCGraphReq) (*api.FCGraphRes, error) {
return nil, nil
}

func (n *nopLog) FindCreateMetric(context.Context, *pb.FCMetricReq) (*pb.FCMetricRes, error) {
func (n *nopLog) FindCreateMetric(context.Context, *api.FCMetricReq) (*api.FCMetricRes, error) {
return nil, nil
}

func (n *nopLog) Histogram(context.Context, *pb.HistogramReq) (*pb.HistogramRes, error) {
func (n *nopLog) Histogram(context.Context, *api.HistogramReq) (*api.HistogramRes, error) {
return nil, nil
}

func (n *nopLog) Counter(context.Context, *pb.CounterReq) (*pb.CounterRes, error) {
func (n *nopLog) Counter(context.Context, *api.CounterReq) (*api.CounterRes, error) {
return nil, nil
}

func (n *nopLog) Gauge(context.Context, *pb.GaugeReq) (*pb.GaugeRes, error) {
func (n *nopLog) Gauge(context.Context, *api.GaugeReq) (*api.GaugeRes, error) {
return nil, nil
}

Expand Down
24 changes: 12 additions & 12 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/gobench-io/gobench/v2/dis"
"github.com/gobench-io/gobench/v2/executor/metrics"
"github.com/gobench-io/gobench/v2/executor/scenario"
api "github.com/gobench-io/gobench/v2/gen/go/pb"
"github.com/gobench-io/gobench/v2/logger"
"github.com/gobench-io/gobench/v2/pb"
"google.golang.org/grpc"

gometrics "github.com/rcrowley/go-metrics"
Expand Down Expand Up @@ -67,7 +67,7 @@ type Executor struct {
vus scenario.Vus
units map[string]unit //title - gometrics

rc pb.AgentClient
rc api.AgentClient
}

// the singleton instance of executor
Expand Down Expand Up @@ -113,7 +113,7 @@ func (e *Executor) Serve() (err error) {
if err != nil {
return
}
e.rc = pb.NewAgentClient(conn)
e.rc = api.NewAgentClient(conn)

// executor register a rpc server at executor socket
l, err := net.Listen("unix", e.executorSock)
Expand All @@ -122,7 +122,7 @@ func (e *Executor) Serve() (err error) {
}

s := grpc.NewServer()
pb.RegisterExecutorServer(s, e)
api.RegisterExecutorServer(s, e)

err = s.Serve(l)
if err != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ func (e *Executor) logScaledOnCue(ctx context.Context, ch chan interface{}) erro
e.mu.Unlock()

for _, u := range units {
base := &pb.BasedReqMetric{
base := &api.BasedReqMetric{
AppID: int64(e.appID),
EID: e.id,
MID: int64(u.metricID),
Expand All @@ -228,14 +228,14 @@ func (e *Executor) logScaledOnCue(ctx context.Context, ch chan interface{}) erro

switch u.Type {
case metrics.Counter:
_, err = e.rc.Counter(ctx, &pb.CounterReq{
_, err = e.rc.Counter(ctx, &api.CounterReq{
Base: base,
Count: u.c.Count(),
})
case metrics.Histogram:
h := u.h.Snapshot()
ps := h.Percentiles([]float64{0.5, 0.75, 0.95, 0.99, 0.999})
hv := &pb.HistogramValues{
hv := &api.HistogramValues{
Count: h.Count(),
Min: h.Min(),
Max: h.Max(),
Expand All @@ -247,12 +247,12 @@ func (e *Executor) logScaledOnCue(ctx context.Context, ch chan interface{}) erro
P99: ps[3],
P999: ps[4],
}
_, err = e.rc.Histogram(ctx, &pb.HistogramReq{
_, err = e.rc.Histogram(ctx, &api.HistogramReq{
Base: base,
Histogram: hv,
})
case metrics.Gauge:
_, err = e.rc.Gauge(ctx, &pb.GaugeReq{
_, err = e.rc.Gauge(ctx, &api.GaugeReq{
Base: base,
Gauge: u.g.Value(),
})
Expand Down Expand Up @@ -284,7 +284,7 @@ func (e *Executor) Setup(groups []metrics.Group) error {

for _, group := range groups {
// create a new group if not existed
egroup, err := e.rc.FindCreateGroup(ctx, &pb.FCGroupReq{
egroup, err := e.rc.FindCreateGroup(ctx, &api.FCGroupReq{
AppID: int64(e.appID),
Name: group.Name,
})
Expand All @@ -294,7 +294,7 @@ func (e *Executor) Setup(groups []metrics.Group) error {

for _, graph := range group.Graphs {
// create new graph if not existed
egraph, err := e.rc.FindCreateGraph(ctx, &pb.FCGraphReq{
egraph, err := e.rc.FindCreateGraph(ctx, &api.FCGraphReq{
AppID: int64(e.appID),
Title: graph.Title,
Unit: graph.Unit,
Expand All @@ -306,7 +306,7 @@ func (e *Executor) Setup(groups []metrics.Group) error {

for _, m := range graph.Metrics {
// create new metric if not existed
emetric, err := e.rc.FindCreateMetric(ctx, &pb.FCMetricReq{
emetric, err := e.rc.FindCreateMetric(ctx, &api.FCMetricReq{
AppID: int64(e.appID),
Title: m.Title,
Type: string(m.Type),
Expand Down
6 changes: 3 additions & 3 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"time"

"github.com/gobench-io/gobench/v2/executor/scenario"
api "github.com/gobench-io/gobench/v2/gen/go/pb"
"github.com/gobench-io/gobench/v2/logger"
"github.com/gobench-io/gobench/v2/pb"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -127,7 +127,7 @@ func TestStart(t *testing.T) {

ctx := context.TODO()

_, err = e.Start(ctx, &pb.StartRequest{
_, err = e.Start(ctx, &api.StartRequest{
AppID: int64(opts.AppID),
})

Expand Down Expand Up @@ -163,7 +163,7 @@ func TestCancel(t *testing.T) {
done := make(chan struct{}, 1)

go func() {
_, err = e.Start(ctx, &pb.StartRequest{
_, err = e.Start(ctx, &api.StartRequest{
AppID: int64(opts.AppID),
})
assert.EqualError(t, err, ErrAppCancel.Error())
Expand Down
20 changes: 10 additions & 10 deletions executor/nop_metriclog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ package executor
import (
"context"

"github.com/gobench-io/gobench/v2/pb"
api "github.com/gobench-io/gobench/v2/gen/go/pb"
"google.golang.org/grpc"
)

// nop metric logger, used for testing
type nopLog struct{}

func (n *nopLog) Counter(ctx context.Context, req *pb.CounterReq, opts ...grpc.CallOption) (*pb.CounterRes, error) {
func (n *nopLog) Counter(ctx context.Context, req *api.CounterReq, opts ...grpc.CallOption) (*api.CounterRes, error) {
return nil, nil
}

func (n *nopLog) Histogram(ctx context.Context, req *pb.HistogramReq, opts ...grpc.CallOption) (*pb.HistogramRes, error) {
func (n *nopLog) Histogram(ctx context.Context, req *api.HistogramReq, opts ...grpc.CallOption) (*api.HistogramRes, error) {
return nil, nil
}

func (n *nopLog) Gauge(ctx context.Context, req *pb.GaugeReq, opts ...grpc.CallOption) (*pb.GaugeRes, error) {
func (n *nopLog) Gauge(ctx context.Context, req *api.GaugeReq, opts ...grpc.CallOption) (*api.GaugeRes, error) {
return nil, nil
}

func (n *nopLog) FindCreateGroup(ctx context.Context, req *pb.FCGroupReq, opts ...grpc.CallOption) (*pb.FCGroupRes, error) {
return new(pb.FCGroupRes), nil
func (n *nopLog) FindCreateGroup(ctx context.Context, req *api.FCGroupReq, opts ...grpc.CallOption) (*api.FCGroupRes, error) {
return new(api.FCGroupRes), nil
}

func (n *nopLog) FindCreateGraph(ctx context.Context, req *pb.FCGraphReq, opts ...grpc.CallOption) (*pb.FCGraphRes, error) {
return new(pb.FCGraphRes), nil
func (n *nopLog) FindCreateGraph(ctx context.Context, req *api.FCGraphReq, opts ...grpc.CallOption) (*api.FCGraphRes, error) {
return new(api.FCGraphRes), nil
}

func (n *nopLog) FindCreateMetric(ctx context.Context, req *pb.FCMetricReq, opts ...grpc.CallOption) (*pb.FCMetricRes, error) {
return new(pb.FCMetricRes), nil
func (n *nopLog) FindCreateMetric(ctx context.Context, req *api.FCMetricReq, opts ...grpc.CallOption) (*api.FCMetricRes, error) {
return new(api.FCMetricRes), nil
}

// NewNopMetricLog returns a no-op metric logger
Expand Down
20 changes: 10 additions & 10 deletions executor/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@ import (
"context"
"os"

"github.com/gobench-io/gobench/v2/pb"
api "github.com/gobench-io/gobench/v2/gen/go/pb"
)

// Start begins to run the program
func (m *Executor) Start(ctx context.Context, req *pb.StartRequest) (*pb.StartResult, error) {
m.logger.Infow("executor rpc starting")
func (e *Executor) Start(ctx context.Context, req *api.StartRequest) (*api.StartResult, error) {
e.logger.Infow("executor rpc starting")

err := m.run(ctx)
err := e.run(ctx)

m.logger.Infow("executor rpc finished")
e.logger.Infow("executor rpc finished")

if err != nil {
return nil, err
}

res := new(pb.StartResult)
res.AppID = int64(m.appID)
res := new(api.StartResult)
res.AppID = int64(e.appID)
res.Success = true

return res, nil
}

// Terminate shutdown this executor process
func (m *Executor) Terminate(ctx context.Context, req *pb.TermRequest) (*pb.TermResult, error) {
func (e *Executor) Terminate(ctx context.Context, req *api.TermRequest) (*api.TermResult, error) {
os.Exit(int(req.Code))

res := new(pb.TermResult)
res.AppID = int64(m.appID)
res := new(api.TermResult)
res.AppID = int64(e.appID)
res.Success = true

return res, nil
Expand Down
Loading
Loading