Skip to content

Commit

Permalink
Introducing V1 grpc control protocol for backward compatibility with …
Browse files Browse the repository at this point in the history
…older agents (#1974)

Introducing V1 grpc control protocol for backward compatibility with older agents (#1974)
  • Loading branch information
michalpristas authored Dec 21, 2022
1 parent a0e6108 commit 9ee5d99
Show file tree
Hide file tree
Showing 31 changed files with 1,900 additions and 333 deletions.
123 changes: 123 additions & 0 deletions control_v1.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

syntax = "proto3";

// proto namespace/package name is shared with elastic-agent-client
// we need to be careful with modifications to avoid name collisions
// proto is here to maintain backward compatibility and cannot be changed.
// elastic-agent-client namespace is likely change after 8.6
package proto;

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

// Status codes for the current state.
enum Status {
V1_STARTING = 0;
V1_CONFIGURING = 1;
V1_HEALTHY = 2;
V1_DEGRADED = 3;
V1_FAILED = 4;
V1_STOPPING = 5;
V1_UPGRADING = 6;
V1_SROLLBACK = 7;
}

// Action status codes for restart and upgrade response.
enum ActionStatus {
// Action was successful.
V1_SUCCESS = 0;
// Action failed.
V1_FAILURE = 1;
}

// Empty message.
message Empty {
}

// Version response message.
message VersionResponse {
// Current running version.
string version = 1;
// Current running commit.
string commit = 2;
// Current running build time.
string buildTime = 3;
// Current running version is a snapshot.
bool snapshot = 4;
}

message RestartResponse {
// Response status.
ActionStatus status = 1;
// Error message when it fails to trigger restart.
string error = 2;
}

// Upgrade request message.
message UpgradeRequest {
// (Optional) Version to upgrade to.
//
// If not provided Elastic Agent will auto discover the latest version in the same major
// to upgrade to. If wanting to upgrade to a new major that major must be present in the
// this version field.
string version = 1;

// (Optional) Use a different source URI then configured.
//
// If provided the upgrade process will use the provided sourceURI instead of the configured
// sourceURI in the configuration.
string sourceURI = 2;
}

// A upgrade response message.
message UpgradeResponse {
// Response status.
ActionStatus status = 1;

// Version that is being upgraded to.
string version = 2;

// Error message when it fails to trigger upgrade.
string error = 3;
}

// Current status of the application in Elastic Agent.
message ApplicationStatus {
// Unique application ID.
string id = 1;
// Application name.
string name = 2;
// Current status.
Status status = 3;
// Current status message.
string message = 4;
// Current status payload.
string payload = 5;
}

// Status is the current status of Elastic Agent.
message StatusResponse {
// Overall status of Elastic Agent.
Status status = 1;
// Overall status message of Elastic Agent.
string message = 2;
// Status of each application in Elastic Agent.
repeated ApplicationStatus applications = 3;
}

service ElasticAgentControl {
// Fetches the currently running version of the Elastic Agent.
rpc Version(Empty) returns (VersionResponse);

// Fetches the currently status of the Elastic Agent.
rpc Status(Empty) returns (StatusResponse);

// Restart restarts the current running Elastic Agent.
rpc Restart(Empty) returns (RestartResponse);

// Upgrade starts the upgrade process of Elastic Agent.
rpc Upgrade(UpgradeRequest) returns (UpgradeResponse);
}
6 changes: 3 additions & 3 deletions control.proto → control_v2.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ syntax = "proto3";
package cproto;

option cc_enable_arenas = true;
option go_package = "internal/pkg/agent/control/cproto";
option go_package = "internal/pkg/agent/control/v2/cproto";
import "google/protobuf/timestamp.proto";

// State codes for the current state.
Expand Down Expand Up @@ -159,9 +159,9 @@ message StateResponse {
StateAgentInfo info = 1;
// Overall state of Elastic Agent.
State state = 2;
// Overall status message of Elastic Agent.
// Overall state message of Elastic Agent.
string message = 3;
// Status of each component in Elastic Agent.
// State of each component in Elastic Agent.
repeated ComponentState components = 4;
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/coordinator/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/elastic/elastic-agent-client/v7/pkg/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/reexec"
agentclient "github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
agentclient "github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/transpiler"
"github.com/elastic/elastic-agent/internal/pkg/capabilities"
"github.com/elastic/elastic-agent/internal/pkg/config"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/coordinator/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"time"

"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
)

// LivenessResponse is the response body for the liveness endpoint.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/application/coordinator"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/gateway"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
agentclient "github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
agentclient "github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/core/backoff"
"github.com/elastic/elastic-agent/internal/pkg/fleetapi"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/application/upgrade/error_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/go-multierror"

"github.com/elastic/elastic-agent/internal/pkg/agent/control"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/pkg/core/logger"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/application/upgrade/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/control"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/install"
"github.com/elastic/elastic-agent/internal/pkg/core/backoff"
Expand Down Expand Up @@ -114,7 +114,7 @@ func InvokeWatcher(log *logger.Logger) error {
defer func() {
if cmd.Process != nil {
log.Debugf("releasing watcher %v", cmd.Process.Pid)
cmd.Process.Release()
_ = cmd.Process.Release()
}
}()

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"

"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/cli"
"github.com/elastic/elastic-agent/pkg/component"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/install"
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/application/secret"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/upgrade"
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/server"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/server"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/agent/storage"
"github.com/elastic/elastic-agent/internal/pkg/cli"
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/spf13/cobra"

"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/cli"
)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (

"github.com/spf13/cobra"

"github.com/elastic/elastic-agent/internal/pkg/agent/control"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/client"
control "github.com/elastic/elastic-agent/internal/pkg/agent/control"
"github.com/elastic/elastic-agent/internal/pkg/agent/control/v2/client"
"github.com/elastic/elastic-agent/internal/pkg/agent/errors"
"github.com/elastic/elastic-agent/internal/pkg/cli"
)
Expand Down
Loading

0 comments on commit 9ee5d99

Please sign in to comment.