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

[Elastic Agent] Add basic protocol to control Elastic Agent. #20146

Merged
merged 9 commits into from
Jul 28, 2020
Merged
Changes from 1 commit
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
Next Next commit
Add protocl to control Elastic Agent.
blakerouse committed Jul 22, 2020
commit 66f18b7cf3187866c227ee9e455bb64334f098f9
102 changes: 102 additions & 0 deletions x-pack/elastic-agent/control.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// 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";

package proto;

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

// Status codes for the current state.
enum Status {
STARTING = 0;
CONFIGURING = 1;
HEALTHY = 2;
DEGRADED = 3;
FAILED = 4;
STOPPING = 5;
UPGRADING = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to that can we introduce status for ROLLBACK? which takes place in between UPGRADING and FAILED

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes will add rollback

}

// Empty message.
message Empty {
}

// Version response message.
message VersionResponse {
// Current running version.
string version = 1;
}

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes sense but i'm worried a bit about sealed env. while it initially might all work without even using default sourceURI as everything is packed. then on upgrade request without version and sourceURI it will fail.
i would be up for these to values being required and relaxing later when we have clear use cases. relaxing is not breaking other way around is though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Being that CLI call to upgrade over the socket will return an UpgradeResponse we can place in the error message why the upgrade cannot be performed. Maybe it is we cannot discover the next version, or maybe we make the version required in some cases like when on the last minor of the current 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 {
// Status codes for upgrade response.
enum UpgradeStatus {
// Started upgrade.
SUCCESS = 0;
// Failed upgrade.
FAILURE = 1;
}

// Response status.
UpgradeStatus status = 1;

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

// 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 ElasticAgent {
// 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 (Empty);

// Upgrade starts the upgrade process of Elastic Agent.
rpc Upgrade(UpgradeRequest) returns (UpgradeResponse);
}
9 changes: 7 additions & 2 deletions x-pack/elastic-agent/magefile.go
Original file line number Diff line number Diff line change
@@ -326,9 +326,9 @@ func commitID() string {
return commitID
}

// Update is an alias for executing fields, dashboards, config, includes.
// Update is an alias for executing control protocol, configs, and specs.
func Update() {
mg.SerialDeps(Config, BuildSpec, BuildFleetCfg)
mg.SerialDeps(ControlProto, Config, BuildSpec, BuildFleetCfg)
}

// CrossBuild cross-builds the beat for all target platforms.
@@ -346,6 +346,11 @@ func Config() {
mg.Deps(configYML)
}

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

// BuildSpec make sure that all the suppported program spec are built into the binary.
func BuildSpec() error {
// go run x-pack/agent/dev-tools/cmd/buildspec/buildspec.go --in x-pack/agent/spec/*.yml --out x-pack/agent/pkg/agent/program/supported.go
913 changes: 913 additions & 0 deletions x-pack/elastic-agent/pkg/agent/control/proto/control.pb.go