Skip to content

Commit

Permalink
Revert "Update elastic-agent-client and rename control proto package …
Browse files Browse the repository at this point in the history
…to cprot…" (#39772)

This reverts commit b40ddd8.
  • Loading branch information
ycombinator authored May 30, 2024
1 parent 0162f45 commit 51edb8f
Show file tree
Hide file tree
Showing 11 changed files with 316 additions and 571 deletions.
309 changes: 30 additions & 279 deletions NOTICE.txt

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ require (
github.com/docker/go-connections v0.4.0
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-plugins-helpers v0.0.0-20181025120712-1e6269c305b8
github.com/docker/go-units v0.5.0
github.com/docker/go-units v0.4.0
github.com/dolmen-go/contextio v0.0.0-20200217195037-68fc5150bcd5
github.com/dop251/goja v0.0.0-20200831102558-9af81ddcf0e1
github.com/dop251/goja_nodejs v0.0.0-20171011081505-adff31b136e6
github.com/dustin/go-humanize v1.0.1
github.com/eapache/go-resiliency v1.2.0
github.com/eclipse/paho.mqtt.golang v1.2.1-0.20200121105743-0d940dd29fd2
github.com/elastic/ecs v1.12.0
github.com/elastic/elastic-agent-client/v7 v7.8.1
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6
github.com/elastic/go-concert v0.2.0
github.com/elastic/go-libaudit/v2 v2.3.1
github.com/elastic/go-licenser v0.4.0
Expand Down Expand Up @@ -115,7 +115,7 @@ require (
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kardianos/service v1.2.1-0.20210728001519-a323c3813bc7
github.com/lib/pq v1.1.2-0.20190507191818-2ff3cb3adc01
github.com/magefile/mage v1.15.0
github.com/magefile/mage v1.14.0
github.com/mailru/easyjson v0.7.1 // indirect
github.com/mattn/go-colorable v0.1.12
github.com/mattn/go-ieproxy v0.0.0-20191113090002-7c0f6868bffe // indirect
Expand Down Expand Up @@ -164,20 +164,20 @@ require (
go.uber.org/atomic v1.9.0
go.uber.org/multierr v1.8.0
go.uber.org/zap v1.21.0
golang.org/x/crypto v0.16.0
golang.org/x/crypto v0.14.0
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.17.0
golang.org/x/oauth2 v0.10.0
golang.org/x/sync v0.5.0
golang.org/x/sys v0.15.0
golang.org/x/text v0.14.0
golang.org/x/sync v0.3.0
golang.org/x/sys v0.13.0
golang.org/x/text v0.13.0
golang.org/x/time v0.3.0
golang.org/x/tools v0.16.0
golang.org/x/tools v0.9.1
google.golang.org/api v0.126.0
google.golang.org/genproto v0.0.0-20230711160842-782d3b101e98
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.31.0
gopkg.in/inf.v0 v0.9.1
gopkg.in/jcmturner/aescts.v1 v1.0.1 // indirect
gopkg.in/jcmturner/dnsutils.v1 v1.0.1 // indirect
Expand All @@ -196,10 +196,9 @@ require (
)

require (
github.com/elastic/elastic-agent-libs v0.7.2
github.com/elastic/elastic-agent-libs v0.6.2
github.com/elastic/elastic-agent-system-metrics v0.4.4
github.com/golang/protobuf v1.5.4
golang.org/x/tools/go/vcs v0.1.0-deprecated
github.com/golang/protobuf v1.5.3
google.golang.org/genproto/googleapis/api v0.0.0-20230711160842-782d3b101e98
)

Expand Down Expand Up @@ -293,8 +292,7 @@ require (
github.com/zeebo/xxh3 v1.0.2 // indirect
go.elastic.co/fastjson v1.1.0 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
Expand Down
66 changes: 32 additions & 34 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions x-pack/elastic-agent/control.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

syntax = "proto3";

package cproto;
package proto;

option cc_enable_arenas = true;
option go_package = "pkg/agent/control/cproto;cproto";
option go_package = "pkg/agent/control/proto;proto";

// Status codes for the current state.
enum Status {
Expand Down Expand Up @@ -66,7 +66,7 @@ message UpgradeRequest {
// If provided the upgrade process will use the provided sourceURI instead of the configured
// sourceURI in the configuration.
string sourceURI = 2;

// (Optional) Overrides predefined behavior for agent package verification.
//
// If provided Elastic Agent package is not checked for signature during upgrade.
Expand Down
11 changes: 8 additions & 3 deletions x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,17 @@ func Config() {
mg.Deps(configYML)
}

// ControlProto generates pkg/agent/control/cproto module.
// ControlProto generates pkg/agent/control/proto module.
func ControlProto() error {
err := sh.RunV("protoc", "--go_out=plugins=grpc:.", "control.proto")
if err == nil {
return nil
}

return sh.RunV(
"protoc",
"--go_out=pkg/agent/control/cproto/", "--go_opt=paths=source_relative",
"--go-grpc_out=pkg/agent/control/cproto/", "--go-grpc_opt=paths=source_relative",
"--go_out=pkg/agent/control/proto/", "--go_opt=paths=source_relative",
"--go-grpc_out=pkg/agent/control/proto/", "--go-grpc_opt=paths=source_relative",
"control.proto")
}

Expand Down
18 changes: 9 additions & 9 deletions x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package cmd
import (
"bytes"
"context"
stderror "errors"
"fmt"
"io"
"io/ioutil"
"math/rand"
"os"
"os/exec"
Expand All @@ -27,7 +27,7 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/client"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/cproto"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/proto"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/install"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/storage"
Expand Down Expand Up @@ -269,7 +269,7 @@ func (c *enrollCmd) writeDelayEnroll(streams *cli.IOStreams) error {
errors.TypeConfig,
errors.M("path", enrollPath))
}
err = os.WriteFile(enrollPath, data, 0600)
err = ioutil.WriteFile(enrollPath, data, 0600)
if err != nil {
return errors.New(
err,
Expand Down Expand Up @@ -602,7 +602,7 @@ func (c *enrollCmd) startAgent(ctx context.Context) (<-chan *os.ProcessState, er

func (c *enrollCmd) stopAgent() {
if c.agentProc != nil {
c.agentProc.StopWait() //nolint:errcheck // no error check here
c.agentProc.StopWait()
c.agentProc = nil
}
}
Expand Down Expand Up @@ -664,7 +664,7 @@ func waitForAgent(ctx context.Context, timeout time.Duration) error {
for {
backOff.Wait()
_, err := getDaemonStatus(innerCtx)
if stderror.Is(err, context.Canceled) {
if err == context.Canceled {
resChan <- waitResult{err: err}
return
}
Expand Down Expand Up @@ -714,7 +714,7 @@ func waitForFleetServer(ctx context.Context, agentSubproc <-chan *os.ProcessStat
for {
backExp.Wait()
status, err := getDaemonStatus(innerCtx)
if stderror.Is(err, context.Canceled) {
if err == context.Canceled {
resChan <- waitResult{err: err}
return
}
Expand Down Expand Up @@ -751,7 +751,7 @@ func waitForFleetServer(ctx context.Context, agentSubproc <-chan *os.ProcessStat
continue
}
log.Debugf("%s: %s - %s", waitingForFleetServer, app.Status, app.Message)
if app.Status == cproto.Status_DEGRADED || app.Status == cproto.Status_HEALTHY {
if app.Status == proto.Status_DEGRADED || app.Status == proto.Status_HEALTHY {
// app has started and is running
if app.Message != "" {
log.Infof("Fleet Server - %s", app.Message)
Expand Down Expand Up @@ -827,7 +827,7 @@ func safelyStoreAgentInfo(s saver, reader io.Reader) error {
for i := 0; i <= maxRetriesstoreAgentInfo; i++ {
backExp.Wait()
err = storeAgentInfo(s, reader)
if stderror.Is(err, filelock.ErrAppAlreadyRunning) {
if err != filelock.ErrAppAlreadyRunning {
break
}
}
Expand All @@ -841,7 +841,7 @@ func storeAgentInfo(s saver, reader io.Reader) error {
if err := fileLock.TryLock(); err != nil {
return err
}
defer fileLock.Unlock() //nolint:errcheck // defered call
defer fileLock.Unlock()

if err := s.Save(reader); err != nil {
return errors.New(err, "could not save enrollment information", errors.TypeFilesystem)
Expand Down
36 changes: 18 additions & 18 deletions x-pack/elastic-agent/pkg/agent/control/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ import (
"time"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/cproto"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/proto"
)

// Status is the status of the Elastic Agent
type Status = cproto.Status
type Status = proto.Status

const (
// Starting is when the it is still starting.
Starting Status = cproto.Status_STARTING
Starting Status = proto.Status_STARTING
// Configuring is when it is configuring.
Configuring Status = cproto.Status_CONFIGURING
Configuring Status = proto.Status_CONFIGURING
// Healthy is when it is healthy.
Healthy Status = cproto.Status_HEALTHY
Healthy Status = proto.Status_HEALTHY
// Degraded is when it is degraded.
Degraded Status = cproto.Status_DEGRADED
Degraded Status = proto.Status_DEGRADED
// Failed is when it is failed.
Failed Status = cproto.Status_FAILED
Failed Status = proto.Status_FAILED
// Stopping is when it is stopping.
Stopping Status = cproto.Status_STOPPING
Stopping Status = proto.Status_STOPPING
// Upgrading is when it is upgrading.
Upgrading Status = cproto.Status_UPGRADING
Upgrading Status = proto.Status_UPGRADING
)

// Version is the current running version of the daemon.
Expand Down Expand Up @@ -102,7 +102,7 @@ type client struct {
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
client cproto.ElasticAgentControlClient
client proto.ElasticAgentControlClient
}

// New creates a client connection to Elastic Agent.
Expand All @@ -117,7 +117,7 @@ func (c *client) Connect(ctx context.Context) error {
if err != nil {
return err
}
c.client = cproto.NewElasticAgentControlClient(conn)
c.client = proto.NewElasticAgentControlClient(conn)
return nil
}

Expand All @@ -133,7 +133,7 @@ func (c *client) Disconnect() {

// Version returns the current version of the running agent.
func (c *client) Version(ctx context.Context) (Version, error) {
res, err := c.client.Version(ctx, &cproto.Empty{})
res, err := c.client.Version(ctx, &proto.Empty{})
if err != nil {
return Version{}, err
}
Expand All @@ -151,7 +151,7 @@ func (c *client) Version(ctx context.Context) (Version, error) {

// Status returns the current status of the running agent.
func (c *client) Status(ctx context.Context) (*AgentStatus, error) {
res, err := c.client.Status(ctx, &cproto.Empty{})
res, err := c.client.Status(ctx, &proto.Empty{})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -181,19 +181,19 @@ func (c *client) Status(ctx context.Context) (*AgentStatus, error) {

// Restart triggers restarting the current running daemon.
func (c *client) Restart(ctx context.Context) error {
res, err := c.client.Restart(ctx, &cproto.Empty{})
res, err := c.client.Restart(ctx, &proto.Empty{})
if err != nil {
return err
}
if res.Status == cproto.ActionStatus_FAILURE {
if res.Status == proto.ActionStatus_FAILURE {
return fmt.Errorf(res.Error)
}
return nil
}

// Upgrade triggers upgrade of the current running daemon.
func (c *client) Upgrade(ctx context.Context, version string, sourceURI string, skipVerify bool, pgpBytes ...string) (string, error) {
res, err := c.client.Upgrade(ctx, &cproto.UpgradeRequest{
res, err := c.client.Upgrade(ctx, &proto.UpgradeRequest{
Version: version,
SourceURI: sourceURI,
SkipVerify: skipVerify,
Expand All @@ -202,15 +202,15 @@ func (c *client) Upgrade(ctx context.Context, version string, sourceURI string,
if err != nil {
return "", err
}
if res.Status == cproto.ActionStatus_FAILURE {
if res.Status == proto.ActionStatus_FAILURE {
return "", fmt.Errorf(res.Error)
}
return res.Version, nil
}

// ProcMeta gathers running beat metadata.
func (c *client) ProcMeta(ctx context.Context) ([]ProcMeta, error) {
resp, err := c.client.ProcMeta(ctx, &cproto.Empty{})
resp, err := c.client.ProcMeta(ctx, &proto.Empty{})
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 51edb8f

Please sign in to comment.